Skip to content

Commit

Permalink
Select all ordinal field on focus
Browse files Browse the repository at this point in the history
  • Loading branch information
Luke Brody committed Sep 7, 2024
1 parent 1060b68 commit b510b19
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion react/src/components/table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -548,11 +548,21 @@ function EditableNumber(props: { number: number, onNewNumber: (number: number) =

const handleSubmit = (): void => {
const number = parseInt(contentEditable.current!.innerText)
if (!Number.isNaN(number)) {
if (!Number.isNaN(number) && number !== props.number) {
props.onNewNumber(number)
}
}

const selectAll = (): void => {
setTimeout(() => {
const range = document.createRange()
range.selectNodeContents(contentEditable.current!)
const selection = window.getSelection()
selection?.removeAllRanges()
selection?.addRange(range)
}, 0)
}

return (
<ContentEditable
className="editable_number"
Expand All @@ -569,6 +579,7 @@ function EditableNumber(props: { number: number, onNewNumber: (number: number) =
onBlur={handleSubmit}
tagName="span" // Use a custom HTML tag (uses a div by default)
inputMode="decimal"
onFocus={selectAll}
/>
)
};
Expand Down

0 comments on commit b510b19

Please sign in to comment.