-
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
Make text/number inputs of ColorPicker
keep draft values while focused
#41264
Make text/number inputs of ColorPicker
keep draft values while focused
#41264
Conversation
* Update `RangeControl` to play nice with revised `InputControl` * Update `UnitControl` to play nice with revised `InputControl` * Restore controlled mode to `RangeControl` * Add missing ; * Add comment after deleting `onChange` * Update test of `RangeControl` to also test controlled mode * Remove separate onChange call from reset handling in `RangeControl` * Refine RESET logic of `InputControl` reducer * Simplify refined RESET logic of `InputControl` reducer * Restore initial position of `RangeControl` when without value * Differentiate state sync effect hooks by event existence * Add and use type `SecondaryReducer` * Cleanup legacy `event.perist()` * Simplify update from props in reducer Co-authored-by: Lena Morita <[email protected]> * Ensure event is cleared after drag actions * Avoid declaration of potential unused variable * Add more reset unit tests for `RangeControl` * Run `RangeControl` unit test in both controlled/uncontrolled modes * Make “keep invaid values” test async * Prevent interference of value entry in number input * Remove unused `floatClamp` function * Fix reset to `initialPosition` * Fix a couple tests for controlled `RangeControl` * Fix `RangeControl` reset * Ensure `InputControl`’s state syncing works after focus changes * Comment * Ignore NaN values in `useUnimpededRangedNumberEntry` * Refine use of event existence in state syncing effect hooks Co-authored-by: Marco Ciampini <[email protected]> Co-authored-by: Lena Morita <[email protected]>
ColorPicker
keep draft values while focusedColorPicker
keep draft values while focused
I wanted to highlight that 96b0a2e and 301c3d4 are extraneous to this PR. I'd be glad to break them into a separate PR if the changes are deemed worthwhile. The motivation was to avoid having to write |
Hey @stokesman , thank you for working on this. I'd like to get some clarity on the status of the various PRs that involve
The reason I'm bringing this up is because in the past months we've been working on a lot of potential changes to these components, but we haven't been able to merge most of these changes to If this situation persists, I wonder if we should just consider rewriting this chain of components in a simpler way. What's your point of view, and how far from being ready is this PR in your opinion?
Would this new PR be merged into |
Some time ago I expected they'd be swapped out with near equivalents from the g2 components library. Which as I understood it had them written in simpler ways. I liked that idea. I'd also have no qualms with otherwise rewriting them but I suppose either option may precipitate other difficulties. I do feel there's opportunity to simplify and improve the comprehensibility and flexibility of their implementations without full rewrites. Something I've experimented with was improving the extensibility of I also think your idea of possibly removing
Aside from the question of the last two commits I'd say this is ready. Though now I'm curious if the approach in this PR for
I'd like to make it on trunk but after a rethink I'll say it'd be better to spare shaving that yak for now. If I do mark this PR as ready it will be after updating to make it work without the last two commits. |
I believe that was the plan, yes — that was more or less at the time I had started working on components. I believe ultimately the task was put on pause given the complexity of reconciling the way input components are structured currently vs the way g2 components are.
That's definitely something I'd like us to explore. I think that the major sources of complexity are:
Removing and/or extracting some of these functionalities may simplify While we move to a hook + component setup, I would also like to explore removing the internal reducer, which I believe just adds a further layer of abstraction which makes it quite hard to follow the "flow" of the logic in the component.
Makes sense. Let us know once this PR is ready for review, and which overall strategy you're opting for (removing the last 2 commits and merging the PR back into #40518, or generalising the |
5150ade
to
3ac6020
Compare
🎯 👍
I was able to get the |
What?
In support of the changes to
InputControl
in #40518 this ensures the text and number inputs ofColorPicker
will keep a "drafted" value while the input is focused (like they do in trunk but without relying on the currentInputControl
behavior).Why?
To avoid interference with typing a value in the input and preserve instant updates during entry.
How?
Adds logic (in a hook) to prefer a draft value over the state while focused yet restore control to props after if a change comes in that wasn't initiated from the input (e.g. global undo).
Testing Instructions
c03
.*The result of the last step can be confusing because the color picker itself will revert to its last local state and instead of the editor’s revision as can be seen in its parent dialog . This is an existing issue with the component and an edge case besides.
Screenshots or screencast
Issue with the hex input of
ColorPicker
from #40518color-picker-fail-on-40518.mp4
The hex input on this branch
color-picker-draftable-on-40518.mp4
While I recorded a different set of actions they both include typing into the hex input so this demonstrates the fix. It also demonstrates the undo works (aside from the caveat mentioned in testing instructions) even while the input is focused.
Issue with
InputWithSlider
ofColorPicker
from #40518color-picker-iput-with-slider-interference.mp4
This is the same issue with the hex input but isn't likely to be as commonly encountered. What is also seen in the screen recording is a very related but separate issue with these controls #36703.
InputWithSlider
on this branchcolor-picker-iput-with-slider-draftable.mp4