-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
[WIP] Unit Control: Allow custom values with more specificity than step value #33156
Conversation
Size Change: +154 B (0%) Total Size: 1.05 MB
ℹ️ View Unchanged
|
@@ -50,9 +51,17 @@ function UnitControl( | |||
initial: initialUnit, | |||
} ); | |||
|
|||
const activeUnit = useMemo( | |||
() => units.find( ( option ) => option.value === unit ), |
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.
Note to self: use optional chaining here as units
might not be defined.
I'll close this one out now, as a better solution has been proposed in #34542 which will allow an explicit |
Description
Following on from comments in #32481, this PR is an attempt to allow the user to enter values into a UnitControl field with greater specificity than the step value allows.
For example, if the step value for
em
units is0.01
by default then even though dragging the values will do so in increments of0.01
, a user should be able to manually enter1.123em
without it being rounded to1.12
. Or at least, that's the premise behind this PR!At the moment, this PR doesn't quite work right — we're grabbing the real value from within the
unitControlStateReducer
and setting the step value accordingly. This seems to work okay once the UnitControl component re-renders, however because we're using a ref, updating its value doesn't trigger a re-render. And unfortunately, we can't swap this out for asetState
call instead, because this function is called within a child component, and we can't trigger a render on a parent component during the render of a child component.So, at the moment, we have a situation where this PR kind of works the second time that a user goes to commit their value, at which point the UnitControl component is re-rendered and passes down the correct
step
value.How has this been tested?
0.01em
, e.g. try1.123em
.Screenshots
Note in this screenshot that the first time we enter the more specific value it gets rounded to
2.23
(when enter is pressed), but the second time, the more specific value is preserved2.234
:Types of changes
New feature
Checklist:
*.native.js
files for terms that need renaming or removal).