-
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
InputControl: Allow onBlur for empty values to commit the change, move reset behaviour to ESCAPE key #39109
InputControl: Allow onBlur for empty values to commit the change, move reset behaviour to ESCAPE key #39109
Conversation
I thought I'd have a go at this one — it looks like it might not be as simple as it looked superficially — we also need to support being able to type in the unit, and switching this flag to |
Size Change: +13 B (0%) Total Size: 1.15 MB
ℹ️ View Unchanged
|
Thanks for working on this and all the copy+paste commands in the test description 😄 I tested the padding/margin/blockGap inputs (and linked sides where available) in both the block and site editors. ✅ Hitting |
Interesting, good catch @ramonjd! I think that might be because the component is unmounted before |
What I forgot to say is that it didn't really stand out to me as an issue. Being able to edit values using the keyboard and via mouse clearing is already a huge win. |
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.
Excellent work, @andrewserong (and thank you for the ping!) I think this change is an improvement over the previous behaviour 🚀
Before
box-control-before.mp4
After
box-control-after.mp4
Regarding the onBlur
callback not being fired when unmounting the component, I've found a potential workaround (although it's definitely something that can happen a follow-up, since it's not really related to the changes in this PR) highlighted in facebook/react#12363 (comment)
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.
Good call, sounds good to me too 👍
Just curious, any reason we're not adding a test for InputControl
itself? (<InputControl isPressEnterToChange />
)
I think the changes here look fine but I am wondering if the option to stop using |
Thanks for the reviews and feedback, folks!
Good question — I took a look at the existing tests and the tests at the
That's a great question, too. I had a go at switching it off before opening this PR, but noticed as you mention in that issue (#30222 (comment)) that it then switched off the behaviour where you can type in the unit and then press Enter to switch units. Without knowing whether or not anyone currently relies on that option, I thought I'd open this PR in the shorter-term to at least improve the UX of this mode. But I think it'd be worth exploring if folks think it's worth it to switch it off on the BoxControl! |
@@ -13,6 +13,7 @@ | |||
|
|||
- `TreeGrid`: Add tests for `onCollapseRow`, `onExpandRow`, and `onFocusRow` callback functions. ([#38942](https://github.com/WordPress/gutenberg/pull/38942)). | |||
- `TreeGrid`: Update callback tests to use `TreeGridRow` and `TreeGridCell` sub-components. ([#39002](https://github.com/WordPress/gutenberg/pull/39002)). | |||
- InputControl: Allow `onBlur` for empty values to commit the change when `isPressEnterToChange` is true, and move reset behavior to the ESCAPE key. ([#39109](https://github.com/WordPress/gutenberg/pull/39109)). |
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.
Late comment but this missed the Unreleased section (easy to do when it's empty). Maybe someone can move it in another PR before the release.
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.
Good catch!
Fix in #39169
Description
As reported in #39090, the existing default behaviour of the BoxControl (as used in Padding and Margin dimensions controls) where you need to press Enter to commit a value change such as clearing out the padding value, can be confusing for users when it comes to clearing out the value.
Prior to this PR, when you blur (e.g. tab or click) out of the UnitControl (with
isPressEnterToChange
set to true) when it contains no value, this will be treated as cancelling / resetting the current change.After this PR, we treat any change to the input field (even it's empty) as a change to commit when tabbing or clicking out of the field.
To preserve the ability to cancel the current change, the
reset()
behaviour is moved to the ESCAPE key, which has some consistency with the W3C WAI recommendations for editing within a data cell (namelyEscape
: if content was being edited, it may also undo edits) — it's not an exact match to the use case of this component, but I think there's a close enough parallel.The proposed change here is an opinionated one, but hopefully it helps alleviate some of the frustration with editing Padding and Margin values as in the initial report.
Changes included:
isPressEnterToChange
is set on the InputField, commit empty valuesisPressEnterToChange
is set on the InputField, allow theESCAPE
key to cancel the current (not-yet-committed) changeTesting Instructions
10px
or2rem
or5%
and then press enter and check that it still works correctly.Confirm existing tests pass (you can look at the CI job, but I ran the following locally to confirm the tests were passing):
Also check that the components still behave correctly in Storybook (via
npm run storybook:dev
). Test the BoxControl component in particular: http://localhost:50240/?path=/story/components-experimental-boxcontrol--defaultScreenshots
Types of changes
Checklist:
*.native.js
files for terms that need renaming or removal).