NumberField, don't allow blank #6261
Closed
vincerubinetti
started this conversation in
General
Replies: 1 comment 4 replies
-
Okay, I was able to do this with the (undocumented) render props for the component: // my wrapper component. needs to support controlled or uncontrolled.
<NumberField
minValue={min}
maxValue={max}
step={step}
defaultValue={value ?? min}
value={value}
onChange={onChange}
>
{({ state }) => (
<>
<Label>{label}</Label>
<Group>
<Button slot="decrement">-</Button>
<Input
form={form}
onBlurCapture={(event) => {
if (!event.target.value.trim())
state.setInputValue(String(min));
}}
/>
<Button slot="increment">+</Button>
</Group>
</>
)}
</NumberField> This seems to make sure the |
Beta Was this translation helpful? Give feedback.
4 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I'd like to use just the Components and not the useNumberField hook (I'm building a design system to be used by people who aren't frontend developers, and I want it to be simple as possible).
When
onChange
fires, I see that the value will be clamped between min and max. But I don't see any option that will force a blank/empty/NaN back into a valid value range, e.g. setting value back to min. I want my component to always be set to a valid number.Is there any way to accomplish this with any of the existing component props or validation behavior, and without duplicating the value state in my wrapper component.
It'd be cool if the
onChange
function could return a number as a validated/"sanitized" value to update the internal numberfield state with.Beta Was this translation helpful? Give feedback.
All reactions