Skip to content

Commit

Permalink
Stop auto adding subtract advanced value when pressing "-" key in num…
Browse files Browse the repository at this point in the history
…ber field, makes it awkward to type negative numbers (ideally we'd check the caret is not at the start of the number but DOM API doesn't allow getting caret position for input type="number"
  • Loading branch information
chrismaltby committed Apr 16, 2024
1 parent 1bb0926 commit 15a03b6
Showing 1 changed file with 1 addition and 11 deletions.
12 changes: 1 addition & 11 deletions src/components/forms/ValueSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -574,17 +574,7 @@ const ValueSelect = ({
} else if (e.key === "+") {
setValueFunction("add");
} else if (e.key === "-") {
// Need to check input isn't empty
// to still allow negative numbers in number fields
const hasSelection =
e.currentTarget instanceof HTMLInputElement &&
(window.getSelection()?.toString().length ?? 0) > 0;
if (
e.currentTarget.nodeName === "BUTTON" ||
("value" in e.currentTarget &&
e.currentTarget.value.trim().length > 0 &&
!hasSelection)
) {
if (e.currentTarget.nodeName === "BUTTON") {
setValueFunction("sub");
}
} else if (e.key === "*") {
Expand Down

0 comments on commit 15a03b6

Please sign in to comment.