Skip to content

Add Number Input#155

Open
EmsArnold wants to merge 7 commits intomainfrom
ea/add-number-input
Open

Add Number Input#155
EmsArnold wants to merge 7 commits intomainfrom
ea/add-number-input

Conversation

@EmsArnold
Copy link
Copy Markdown

Fixes #154.

Adds a number input component, which validates various number types, high limits, and low limits.

@EmsArnold EmsArnold requested a review from akademy March 9, 2026 10:48
Copy link
Copy Markdown
Member

@akademy akademy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great. Just a few minor suggestions.

Comment thread src/components/controls/NumberInput.tsx Outdated
Comment thread src/components/controls/NumberInput.tsx Outdated
Comment thread src/components/controls/NumberInput.tsx
Comment thread src/components/controls/NumberInput.tsx Outdated
}) => {
const numberRegex = Modes[numberMode];

const helperText = `A ${numberMode} number. Limits: ${minValue} to ${maxValue}`;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you make it optional to display this helper text?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Helper text is default, but can now be turned off

Comment thread src/components/controls/NumberInput.tsx Outdated
value={numberText}
onChange={(e) => handleInputChange(e.target.value)}
onKeyDown={handleKeyDown}
onBlur={handleBlur}
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you do not set either commitOnBlur or commitOnReturn to false and hit return you get in a loop. Enter -> Blur

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This loop seems to have only been an issue due to alert stealing focus from the original element. I've now added logic to blur the element if commitOnBlur is true (thus using the onBlur action to trigger the handleCommit when the enter key is pressed), otherwise handleCommit for onKeyDown happens as normal.
I tried it out a few times without managing to trigger a loop, but let me know if this doesn't work.

? ""
: `A ${numberMode} number. Limits: ${minValue} to ${maxValue}`;

const handleInputChange = (value: string) => {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isValid and isInLimits are both derived from props and numberText so we can remove those two states and move their calculation out of handleInputChange. handleInputChange then only needs setNumberText(value)

onKeyDown={handleKeyDown}
onBlur={handleBlur}
error={!isValid || !isInLimits}
helperText={
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can calculate helperText outside of return

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add a NumberInput component

3 participants