-
Notifications
You must be signed in to change notification settings - Fork 4.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
NumberControl: Allow empty values #33485
Conversation
Size Change: +19 B (0%) Total Size: 1.07 MB
ℹ️ View Unchanged
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is working nicely for me @aaronrobertshaw, tests pass, and it works according to the instructions in Storybook. I like that it's using the required
param to enable the behaviour, too 👍
Fixes: #33319
Tiny nit here: this PR adds the ability to fix that one, but doesn't update the usage of the UnitControl in the BoxControl to add in required={ false }
. Did you want to update the usage here, or once this PR lands, update #33444 to use the new param?
This is working nicely for me as-is, and the logic looks straightforward, so I'll give it the ✅.
Also CC: @aristath since you've done a bit of work on this recently, too 🙂
Thanks for taking a look at this 👍
Hopefully, this approach aligns it better with the HTML number input and makes it a little more intuitive.
Nice catch. I removed the updates to those components so that this PR could focus only on how the I think we can address updating those components and any others that need it once this gets merged. How they get updated might change based our what the final decision is regarding whether the Excluding them from #33444 also then means that PR only addresses a single issue as well. |
It would make sense if |
Add new prop to determine if NumberControl should allow empty string value.
To be more in line with an HTML number input, this changes the NumberControl to check the required prop to determine whether an empty string is valid or not.
ef3d863
to
c3aab6d
Compare
Good point. I've updated the Now the
The UnitControl currently has fairly wide spread use:
All of these uses appear ok with the While testing these I did find an issue with clearing the FocalPointPicker control however it turns out it was already fixed in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Related: #33319
Description
This fixes an issue caused by the
NumberControl
effectively enforcing a numerical value only via its use ofroundClamp
.An example use case where an empty value would be valid is with the
BoxControl
used for padding and margin block support styles. There is a need to be able to clear a field to an undefined value.Proposed solution
To bring the
NumberControl
more in line with an HTML number input this PR utilises arequired
prop to determine if an empty value can be applied via its state reducer. HTML number inputs, when not required, deem an empty value as valid.As the
NumberControl
is currently experimental, the newrequired
prop will default to false. It is currently only used directly in a few places. It does form the basis for theUnitControl
however from what I can see the existing uses ofUnitControl
are ok allowing the field to be cleared.How has this been tested?
npm run test-unit:watch packages/components/src/number-control/test
Test instructions
npm run storybook:dev
NumberControl
, set a placeholder and toggle offrequired
. Or, follow this link.NumberControl
, using the keyboard delete the value, then press enter. The placeholder should remain after you click elsewhere.required
knob back on and repeat step 4. The empty value will be replaced with0
Screenshots
Types of changes
Bug fix
Checklist:
*.native.js
files for terms that need renaming or removal).