From 39157034546e85a89bde4d8b52fecf4cc6d3f5f5 Mon Sep 17 00:00:00 2001 From: Carl Smith <5456533+CarlosNZ@users.noreply.github.com> Date: Wed, 1 May 2024 15:22:13 +1200 Subject: [PATCH 1/2] Increment number input with arrow keys --- src/ValueNodes.tsx | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/ValueNodes.tsx b/src/ValueNodes.tsx index 57208d31..d0476ac4 100644 --- a/src/ValueNodes.tsx +++ b/src/ValueNodes.tsx @@ -65,8 +65,21 @@ export const NumberValue: React.FC = ({ }) => { const { getStyles } = useTheme() const handleKeyPress = (e: React.KeyboardEvent) => { - if (e.key === 'Enter') handleEdit() - else if (e.key === 'Escape') handleCancel() + switch (e.key) { + case 'Enter': + handleEdit() + break + case 'Escape': + handleCancel() + break + case 'ArrowUp': + e.preventDefault() + setValue((prev) => Number(prev) + 1) + break + case 'ArrowDown': + e.preventDefault() + setValue((prev) => Number(prev) - 1) + } } const validateNumber = (input: string) => { From 83d30b2d0bf2f00ac81fb8e3c46fa2b689224d73 Mon Sep 17 00:00:00 2001 From: Carl Smith <5456533+CarlosNZ@users.noreply.github.com> Date: Wed, 1 May 2024 15:23:09 +1200 Subject: [PATCH 2/2] Update README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 19b9aa54..376be1d8 100644 --- a/README.md +++ b/README.md @@ -80,6 +80,7 @@ It's pretty self explanatory (click the "edit" icon to edit, etc.), but there ar - `Escape` to cancel editing - When clicking the "clipboard" icon, holding down `Cmd/Ctrl` will copy the *path* to the selected node rather than its value - When opening/closing a node, hold down "Alt/Option" to open/close *all* child nodes at once +- For Number inputs, arrow-up and down keys will increment/decrement the value ## Props overview