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
Collaborator

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
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 on lines +121 to +122
<>
{
Copy link
Member

Choose a reason for hiding this comment

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

We don't need "<>" "{" here

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Removed

onKeyDown={handleKeyDown}
onBlur={handleBlur}
error={!isValid}
helperText={!isValid ? "Invalid input" : helperText}
Copy link
Member

Choose a reason for hiding this comment

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

Can we have a different message when the values are outside the min / max value, it's just slighly easier for users to understand. "Outside of range" or " too high", something like that.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Helper text for invalid input due to limits is now "Outside limits"

!defaultValue ? "" : defaultValue.toString(),
);
const [isValid, setIsValid] = useState(
!defaultValue ? true : Modes[numberMode].test(defaultValue.toString()),
Copy link
Member

Choose a reason for hiding this comment

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

Do we want to check the limits here too?

Copy link
Collaborator Author

@EmsArnold EmsArnold Mar 19, 2026

Choose a reason for hiding this comment

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

Limits are now checked at all relevent levels, and corresponding test has been added

}) => {
const numberRegex = Modes[numberMode];

const helperText = `A ${numberMode} number. Limits: ${minValue} to ${maxValue}`;
Copy link
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
Collaborator 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

};

const handleInputChange = (value: string) => {
setIsValid(numberRegex.test(value) && checkLimits(value));
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could set different error message at checkLimits level.

value={numberText}
onChange={(e) => handleInputChange(e.target.value)}
onKeyDown={handleKeyDown}
onBlur={handleBlur}
Copy link
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
Collaborator 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.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add a NumberInput component

3 participants