-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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
base: trunk
Are you sure you want to change the base?
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. |
Based on the test results, I think it's best to at least wrap the keydown handler function. The space would always work because it technically just prevents the default behavior; therefore, no abnormalities can be seen in the editor. What do you think, @t-hamano? |
Thank you so much for testing, @megane9988!
@yogeshbhutkar Yes, based on his tests, it would be enough to apply HOF only to the keydown handler. Sorry for the frequent suggestions for changes. |
2388334
to
1db4f61
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.
LGTM! Before shipping this PR, let's get some accessibility feedback again.
1db4f61
to
09ae797
Compare
@yogeshbhutkar This is looking much better. One final thought. Since it isn't clear that the details can be expanded, maybe add
The expanded/collapsed state does enough to notify users of the exposed content, nice job on that. I also agree it would be nice to do something about the "hidden" in the new block placeholder phrasing. The block isn't technically hidden if the details element is expanded. Thanks. |
Thanks for the feedback, @alexstine. I've implemented the suggested feedback. When you have a moment, could you please re-review the changes and approve them if everything looks good? |
@yogeshbhutkar Can you add the It also seems like something has changed where the Up/Down arrow keys can now toggle the display and this can be rather disruptive as Up/Down arrow keys allow screen reader users to read by line. Thanks. |
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.
I'm not sure if RichText
can take aria-describedby
by default, hopefully so. I would also like to see if anyone else can reproduce the Up/Down arrow keys toggling the state of the hidden blocks while in the summary edit field.
const blockProps = useBlockProps(); | ||
const instanceId = useInstanceId( DetailsEdit, 'details-edit-desc' ); | ||
const blockProps = useBlockProps( { | ||
'aria-describedby': instanceId, |
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.
This cannot be defined here as pressing Enter at block wrapper level will insert a new block, not expand/collapse the summary.
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! I've moved this to RichText
and verified that the message now triggers correctly when typing in the RichText
field.
* 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
939520f
to
0aa017b
Compare
I tested this and wasn't able to toggle the hidden blocks using the arrow keys; only the cc: @alexstine Edit: I tested this in Chrome, Firefox, and Safari, but wasn't able to replicate it in any of them. Can you provide a screencast, as it might help me investigate this further? test.mov |
Adding the For example, add a Details block to the top and focus on the post title. The screen reader will read it as follows:
f0cada83bb7812ce11991158704f4d82.mp4A second focus should not be necessary. I would suggest that since the diff --git a/packages/block-library/src/details/edit.js b/packages/block-library/src/details/edit.js
index a21a00bade..c2df5721e9 100644
--- a/packages/block-library/src/details/edit.js
+++ b/packages/block-library/src/details/edit.js
@@ -130,14 +130,11 @@ function DetailsEdit( { attributes, setAttributes, clientId } ) {
onKeyDown={ withIgnoreIMEEvents( handleSummaryKeyDown ) }
onKeyUp={ handleSummaryKeyUp }
>
- <VisuallyHidden id={ instanceId }>
- { __(
- 'Press Enter to expand or collapse the details.'
- ) }
- </VisuallyHidden>
<RichText
identifier="summary"
- aria-label={ __( 'Write summary' ) }
+ aria-label={ __(
+ 'Write summary. Press Enter to expand or collapse the details.'
+ ) }
aria-describedby={ instanceId }
placeholder={ placeholder || __( 'Write summary…' ) }
withoutInteractiveFormatting So the screen reader should read something like this:
In the first state of this PR, we were using the up and down arrow keys. |
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