-
-
Notifications
You must be signed in to change notification settings - Fork 3.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: number input #4982
fix: number input #4982
Conversation
🦋 Changeset detectedLatest commit: 4a2346b The changes in this PR will be included in the next version bump. This PR includes changesets to release 5 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
This pull request is being automatically deployed with Vercel (learn more). chakra-ui – ./🔍 Inspect: https://vercel.com/chakra-ui/chakra-ui/KquT362mmaHRDvBAVKgN1yW7iCNU chakra-ui-storybook – ./🔍 Inspect: https://vercel.com/chakra-ui/chakra-ui-storybook/8FwQKmpdmPGsGWmVMdWA2bd6gCKb |
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit 4a2346b:
|
Hi, any update on this PR being merged? I'm encountering the same issue |
📦 A new release has been made for this pull requestTo play around with this release, you can install
|
I don't think this PR fixes #4474, because internally the The problem occurs when the input field blurs. With I'm using the export const NumberInput = forwardRef(function NumberInputComponent(
props: NumberInputProps & Pick<NumberInputFieldProps, 'placeholder'>,
ref: ForwardedRef<HTMLDivElement | null>,
) {
const { placeholder, ...other } = props;
const parse = (value: StringOrNumber) => String(value).replace(',', '.');
const format = (value: StringOrNumber | undefined) => (
typeof value != 'undefined'
? String(value).replace('.', ',')
: ''
);
return (
<ChakraNumberInput
ref={ref}
min={0}
precision={0}
{...other}
onChange={(valueAsString, valueAsNumber) => {
const fixed = parseFloat(valueAsString.replace(',', '.'));
other.onChange?.(valueAsString, fixed);
}}
value={format(other.value)}
pattern="[0-9]*(,[0-9]+)?"
isValidCharacter={value => /^[0-9-,]$/.test(value)}
>
<NumberInputField placeholder={placeholder}/>
<NumberInputStepper>
<NumberIncrementStepper/>
<NumberDecrementStepper/>
</NumberInputStepper>
</ChakraNumberInput>
);
}); I'm using |
@llamadeus I solved the issue adding the 'parse' argument
|
@dedekpo Oh wow, that's an awesome solution. Thank you so much! |
Closes #4474 #4776 #4646
📝 Description
This PR fixes a number of issues in the number-input component and exposes a way to
format
,parse
and validate characters typed into the number input.It also introduces a new
onInvalid
callback that is invoked when the input's value exceeds the specified range.⛳️ Current behavior (updates)
💣 Is this a breaking change (Yes/No):
No