[WIP] Unit Control: Allow custom values with more specificity than step value#33156
Closed
andrewserong wants to merge 1 commit intotrunkfrom
Closed
[WIP] Unit Control: Allow custom values with more specificity than step value#33156andrewserong wants to merge 1 commit intotrunkfrom
andrewserong wants to merge 1 commit intotrunkfrom
Conversation
7 tasks
|
Size Change: +154 B (0%) Total Size: 1.05 MB
ℹ️ View Unchanged
|
andrewserong
commented
Jul 2, 2021
| } ); | ||
|
|
||
| const activeUnit = useMemo( | ||
| () => units.find( ( option ) => option.value === unit ), |
Contributor
Author
There was a problem hiding this comment.
Note to self: use optional chaining here as units might not be defined.
Contributor
Author
|
I'll close this one out now, as a better solution has been proposed in #34542 which will allow an explicit |
6 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
emunits is0.01by default then even though dragging the values will do so in increments of0.01, a user should be able to manually enter1.123emwithout 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
unitControlStateReducerand 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 asetStatecall 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
stepvalue.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.jsfiles for terms that need renaming or removal).