-
Notifications
You must be signed in to change notification settings - Fork 4.5k
Details Block: Fix keyboard accessibility issues and allow list view selection to show up inner blocks #70056
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
Details Block: Fix keyboard accessibility issues and allow list view selection to show up inner blocks #70056
Conversation
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the Unlinked AccountsThe following contributors have not linked their GitHub and WordPress.org accounts: @armandovias. Contributors, please read how to link your accounts to ensure your work is properly credited in WordPress releases. If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.
To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Adding handlers for arrow keys introduces a new behavior for P.S. I think @t-hamano was also working on this issue. |
@yogeshbhutkar Thanks for working on this. @Mamaduka We need a way to expand the details block because it isn't currently possible in the editor with the keyboard alone. Give it a test on current trunk, not sure how anyone allowed a regression like this to slip by without keyboard testing. Seems like only way is the mouse at this point. |
On a separate note, while spacebar toggling makes sense on the front end, it disrupts the editing experience (I understand it's the default behavior). Disabling this behavior when typing in the summary's rich text would be better. I'd appreciate any accessibility feedback on this. Observe, pressing the spacebar while typing toggles the hidden content, which could be confusing for users in the editor. |
@yogeshbhutkar Yes, absolutely. If you can detect focus in the summary rich text, space keyboard event needs to be prevented for expand/collapse. |
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.
Thanks for the PR! The approach that uses keyboard events to collapse or expand the content is an interesting approach.
The only concern is that the summary text can span multiple lines. In this case, the content is toggled every time you move from one line to another can be annoying.
Another approach I can think of may be using the Enter key. Additionally, let screenreader users know the details block was toggled by the . In other words, the code would be like this:speak()
method
<summary
onKeyDown={ ( event ) => {
if ( event.key === 'Enter' && ! event.shiftKey ) {
setIsOpen( ! isOpen );
event.preventDefault();
}
} }
>
Finally, I think we also need to add some e2e tests to avoid regressions.
Another thing to note is that in CJK languages, an IME (Input Method Editor) is used to input complex characters. There is a higher-order function to ignore keyboard events during IME composition. We will probably need to wrap keydown events in this function in your Details block as well. See the following PRs for more details: |
That looks good @t-hamano. Shift enter will insert new line while enter will expand/collapse. I'm not overly thrilled with the UX but it is 100% better than trunk today. Also, can we fix the list view here as well? Any time a hidden block is selected, auto-expand the summary? Thanks. |
I think you can confirm that this issue has already been fixed in this PR. This is because when an inner block is selected in the List View, |
This looks like it's progressing well; thanks for getting on this! I think that you all have this well in hand, but if you need a 2nd review once everything is ready, let me know. |
This is working much better indeed. For sure need to do something about the expanding content though. If I insert a new line with enter and then down arrow to it, all I hear is expanded. So I do like the idea of shift+enter to insert a new line, enter will trigger expand/collapse, and arrows should navigate the content only. |
5f6261a
to
fdea3e4
Compare
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.
Thanks for the update, @yogeshbhutkar!
I think this PR is going pretty well.
Any time a hidden block is selected, auto-expand the summary?
Can we add an e2e test for this? The steps should be like this:
- Insert a Details block
- Open the List view
- Press the right arrow key: The inner blocks of the Details block are displayed in the List View
- Press the down arrow key: The first inner block is focused in the List View
- Press the enter key: The first inner block should be focused in the editor canvas
@@ -18,5 +19,6 @@ lock( privateApis, { | |||
Theme, | |||
Menu, | |||
kebabCase, | |||
withIgnoreIMEEvents, |
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.
@WordPress/gutenberg-components
We export this HOF as a private API. We need this function in the block library to prevent the Details content from being toggled by the Enter key event fired by the IME event.
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.
Update: Let's test whether it works without this HOF.
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.
Update: If the HOF is not used, unintended events occur in the IME and it does not work properly (See #70056 (comment)). Therefore, it is necessary to use HOF as a private API.
I tested it. OS: macOS 15.4.1(24E263) Test Steps
2025-05-08.13.35.24.movIt worked well. |
I tested it. OS: macOS 15.4.1(24E263) Test Steps
2025-05-08.14.01.21.movIt also worked well. |
I also tested using ことえり ( macOS default IME ) in both browsers (Chrome and Safari). 2025-05-08.14.10.21.mov |
fdea3e4
to
c1154ba
Compare
I've incorporated all the feedback. A few follow-ups for the details block (separate from this PR):
I'd like to know the opinion of others on this. |
* Adds using inner block content wherever required * Adds an e2e test to verify list view auto expand and focus
Manual testing with IMEs showed that the HOF can safely be applied just to the key down events
d4d2699
to
f3d5d6b
Compare
This PR appears to have gone stale. Given that we've already completed the initial round of accessibility feedback and considering that this PR clearly enhances accessibility overall, I'd suggest proceeding with this PR. Any remaining or future accessibility concerns can be addressed as a follow-up. cc: @t-hamano |
I agree. This PR is much better than the trunk one, so if there are improvements to the label reading, let's address them in a follow-up. |
Thanks for moving forward with this! I definitely agree that this is much better than the trunk version, and it makes far more sense to ship the improvements and iterate, rather than continue to need to refactor the patch when it's gone out of date. |
I am checking the PRs with the "Backport to WP Minor Release" label applied to clarify which PRs should be backported to the WordPress 6.8.2 release. I believe this PR should be backported to the 6.8.2 release since it is a regression that occurred in 6.8. |
Agreed! |
…selection to show up inner blocks (#70056) * fix: use key down to open/close the details block * chore: fix import order * fix: do not conditionally render details children * feat: expose `withIgnoreIMEEvents` to private api * feat: wrap handler within `withIgnoreIMEEvents` * chore(test): add e2e test for details block * fix: prevent space in rich-text from toggling details * chore: add CHANGELOG * fix: wrap key up handler with `withIgnoreIMEEvents` * chore(e2e): updated tests * Adds using inner block content wherever required * Adds an e2e test to verify list view auto expand and focus * chore: move `CHANGELOG` to unreleased * chore: revert usage of `withIgnoreIMEEvents` * fix: apply `withIgnoreIMEEvents` to key down Manual testing with IMEs showed that the HOF can safely be applied just to the key down events * feat: add visually hidden instructions for expanding/collapsing details * fix: add `aria-describedby` and add it to RichText * fix: update aria-label for RichText * fix: remove the usage of `aria-describedby` * chore: move `CHANGELOG` to unreleased Unlinked contributors: armandovias. Co-authored-by: yogeshbhutkar <[email protected]> Co-authored-by: Mamaduka <[email protected]> Co-authored-by: t-hamano <[email protected]> Co-authored-by: alexstine <[email protected]> Co-authored-by: joedolson <[email protected]> Co-authored-by: megane9988 <[email protected]>
…selection to show up inner blocks (WordPress#70056) * fix: use key down to open/close the details block * chore: fix import order * fix: do not conditionally render details children * feat: expose `withIgnoreIMEEvents` to private api * feat: wrap handler within `withIgnoreIMEEvents` * chore(test): add e2e test for details block * fix: prevent space in rich-text from toggling details * chore: add CHANGELOG * fix: wrap key up handler with `withIgnoreIMEEvents` * chore(e2e): updated tests * Adds using inner block content wherever required * Adds an e2e test to verify list view auto expand and focus * chore: move `CHANGELOG` to unreleased * chore: revert usage of `withIgnoreIMEEvents` * fix: apply `withIgnoreIMEEvents` to key down Manual testing with IMEs showed that the HOF can safely be applied just to the key down events * feat: add visually hidden instructions for expanding/collapsing details * fix: add `aria-describedby` and add it to RichText * fix: update aria-label for RichText * fix: remove the usage of `aria-describedby` * chore: move `CHANGELOG` to unreleased Unlinked contributors: armandovias. Co-authored-by: yogeshbhutkar <[email protected]> Co-authored-by: Mamaduka <[email protected]> Co-authored-by: t-hamano <[email protected]> Co-authored-by: alexstine <[email protected]> Co-authored-by: joedolson <[email protected]> Co-authored-by: megane9988 <[email protected]>
…selection to show up inner blocks (#70056) * fix: use key down to open/close the details block * chore: fix import order * fix: do not conditionally render details children * feat: expose `withIgnoreIMEEvents` to private api * feat: wrap handler within `withIgnoreIMEEvents` * chore(test): add e2e test for details block * fix: prevent space in rich-text from toggling details * chore: add CHANGELOG * fix: wrap key up handler with `withIgnoreIMEEvents` * chore(e2e): updated tests * Adds using inner block content wherever required * Adds an e2e test to verify list view auto expand and focus * chore: move `CHANGELOG` to unreleased * chore: revert usage of `withIgnoreIMEEvents` * fix: apply `withIgnoreIMEEvents` to key down Manual testing with IMEs showed that the HOF can safely be applied just to the key down events * feat: add visually hidden instructions for expanding/collapsing details * fix: add `aria-describedby` and add it to RichText * fix: update aria-label for RichText * fix: remove the usage of `aria-describedby` * chore: move `CHANGELOG` to unreleased Unlinked contributors: armandovias. Co-authored-by: yogeshbhutkar <[email protected]> Co-authored-by: Mamaduka <[email protected]> Co-authored-by: t-hamano <[email protected]> Co-authored-by: alexstine <[email protected]> Co-authored-by: joedolson <[email protected]> Co-authored-by: megane9988 <[email protected]>
This PR was cherry-picked into the |
What, Why, and How?
Closes #70047
This PR enhances keyboard interaction with the Details block, enabling users to expand inner blocks using the keyboard. It also fixes a bug that previously prevented selecting an inner block from the List View; clicking an inner block in the List View now correctly selects it in the editor canvas.
With this PR, pressing the down arrow key expands the inner blocks within the Details block, while pressing the up arrow key collapses them.
Testing Instructions
Code
Screencast