Skip to content

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

Merged
merged 18 commits into from
Jun 2, 2025

Conversation

yogeshbhutkar
Copy link
Contributor

@yogeshbhutkar yogeshbhutkar commented May 5, 2025

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

  1. Create a post and add the following block markup.
Code
<!-- wp:paragraph -->
<p>First Paragraph Block</p>
<!-- /wp:paragraph -->

<!-- wp:details -->
<details class="wp-block-details">
<summary>Details Block Summary</summary>
<!-- wp:paragraph {"placeholder":"Type / to add a hidden block"} -->
<p>Details Block Content</p>
<!-- /wp:paragraph -->
<!-- wp:paragraph -->
<p>Details Block Content</p>
<!-- /wp:paragraph -->
</details>
<!-- /wp:details -->

<!-- wp:paragraph -->
<p>Second Paragraph Block</p>
<!-- /wp:paragraph -->
  1. Try moving through the blocks with the arrow keys.
  2. Confirm, the inner blocks within details are accessible using the keyboard.
  3. Open the list view and expand the details block.
  4. Confirm that clicking on an inner block within the list view opens and selects the inner block properly.

Screencast

pr-demo

@yogeshbhutkar yogeshbhutkar marked this pull request as ready for review May 5, 2025 11:16
Copy link

github-actions bot commented May 5, 2025

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 props-bot label.

Unlinked Accounts

The 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.

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]>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@Mamaduka Mamaduka added [Type] Bug An existing feature does not function as intended [Focus] Accessibility (a11y) Changes that impact accessibility and need corresponding review (e.g. markup changes). [Block] Details Affects the Details Block - used to display content which can be shown/hidden labels May 5, 2025
@Mamaduka
Copy link
Member

Mamaduka commented May 5, 2025

Adding handlers for arrow keys introduces a new behavior for details, which is expanded using Space or Enter keys. Are we okay with this? It would be good to get a11y feedback on this PR before it's merged. cc @joedolson

P.S. I think @t-hamano was also working on this issue.

@alexstine
Copy link
Contributor

@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.

@yogeshbhutkar
Copy link
Contributor Author

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.

bug

Observe, pressing the spacebar while typing toggles the hidden content, which could be confusing for users in the editor.

@alexstine
Copy link
Contributor

@yogeshbhutkar Yes, absolutely. If you can detect focus in the summary rich text, space keyboard event needs to be prevented for expand/collapse.

Copy link
Contributor

@t-hamano t-hamano left a 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 speak() method. In other words, the code would be like this:

<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.

@t-hamano
Copy link
Contributor

t-hamano commented May 6, 2025

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:

@alexstine
Copy link
Contributor

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.

@t-hamano
Copy link
Contributor

t-hamano commented May 6, 2025

@alexstine

Also, can we fix the list view here as well? Any time a hidden block is selected, auto-expand the summary?

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, hasSelectedInnerBlock is true and the open attribute of the details element is true:

https://github.com/WordPress/gutenberg/pull/70056/files#diff-20d83620db8197c679e5617a73e78de6306074dff49588bb00fd5ee35a17793bR105

@t-hamano t-hamano added the Backport to WP Minor Release Pull request that needs to be backported to a WordPress minor release label May 6, 2025
@t-hamano t-hamano moved this to 🔎 Needs Review in WordPress 6.8.x Editor Tasks May 6, 2025
@joedolson
Copy link
Contributor

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.

@alexstine
Copy link
Contributor

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.

@yogeshbhutkar yogeshbhutkar force-pushed the fix-70047/details-block branch from 5f6261a to fdea3e4 Compare May 7, 2025 06:41
Copy link
Contributor

@t-hamano t-hamano left a 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,
Copy link
Contributor

@t-hamano t-hamano May 8, 2025

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.

Copy link
Contributor

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.

Copy link
Contributor

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.

@megane9988
Copy link
Contributor

I tested it.

OS: macOS 15.4.1(24E263)
Browser: Chrome 135.0.7049.115
IME: Google 日本語入力 ( https://www.google.co.jp/ime/ )

Test Steps

  • Adding a Details Block
  • Pressing the Enter key on the Summary text should toggle the content open and closed.
  • Pressing Enter + Shift on the Summary text should insert a line break without toggling the content.
  • Key operations while inputting Japanese (such as the Enter key and Space key) should be ignored, and the content should not toggle.
2025-05-08.13.35.24.mov

It worked well.

@megane9988
Copy link
Contributor

I tested it.

OS: macOS 15.4.1(24E263)
Browser: Safari 18.4 (20621.1.15.11.10)
IME: Google 日本語入力 ( https://www.google.co.jp/ime/ )

Test Steps

  • Adding a Details Block
  • Pressing the Enter key on the Summary text should toggle the content open and closed.
  • Pressing Enter + Shift on the Summary text should insert a line break without toggling the content.
  • Key operations while inputting Japanese (such as the Enter key and Space key) should be ignored, and the content should not toggle.
2025-05-08.14.01.21.mov

It also worked well.

@megane9988
Copy link
Contributor

I also tested using ことえり ( macOS default IME ) in both browsers (Chrome and Safari).
It also worked well.

2025-05-08.14.10.21.mov

@yogeshbhutkar yogeshbhutkar force-pushed the fix-70047/details-block branch from fdea3e4 to c1154ba Compare May 8, 2025 05:47
@yogeshbhutkar
Copy link
Contributor Author

I've incorporated all the feedback. A few follow-ups for the details block (separate from this PR):

  1. We should add e2e coverage for drag-and-drop, as it previously caused a regression and remains a risk.

  2. Keyboard navigation should also be possible when the block is collapsed. As of now, hidden blocks restrict the movement, and removing them might not be good for accessibility.

  3. When inserting inner blocks, only the first shows the correct / placeholder (Type / to add a hidden block). Subsequent ones revert to the default. We should persist the template message while adding hidden blocks to avoid confusion. Coming out of details requires double enter, but the editor screen shows no feedback. Plus, if we are adding a hidden block, the message should always state so.

I'd like to know the opinion of others on this.

@yogeshbhutkar yogeshbhutkar requested a review from t-hamano May 8, 2025 06:52
@yogeshbhutkar yogeshbhutkar force-pushed the fix-70047/details-block branch from d4d2699 to f3d5d6b Compare June 2, 2025 03:28
@yogeshbhutkar
Copy link
Contributor Author

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

@t-hamano
Copy link
Contributor

t-hamano commented Jun 2, 2025

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.

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.

@t-hamano t-hamano merged commit 0af268b into WordPress:trunk Jun 2, 2025
91 of 92 checks passed
@github-actions github-actions bot added this to the Gutenberg 21.0 milestone Jun 2, 2025
@joedolson
Copy link
Contributor

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.

@t-hamano t-hamano moved this from 🔎 Needs Review to ✅ Done in WordPress 6.8.x Editor Tasks Jun 11, 2025
@t-hamano
Copy link
Contributor

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.

@joedolson
Copy link
Contributor

Agreed!

t-hamano added a commit that referenced this pull request Jun 30, 2025
…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]>
chriszarate pushed a commit to chriszarate/gutenberg that referenced this pull request Jul 1, 2025
…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]>
Mamaduka added a commit that referenced this pull request Jul 8, 2025
…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]>
@t-hamano t-hamano removed the Backport to WP Minor Release Pull request that needs to be backported to a WordPress minor release label Jul 8, 2025
@t-hamano
Copy link
Contributor

t-hamano commented Jul 8, 2025

This PR was cherry-picked into the wp/6.8 branch for the WP 6.8.2 release: #70557

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Block] Details Affects the Details Block - used to display content which can be shown/hidden [Focus] Accessibility (a11y) Changes that impact accessibility and need corresponding review (e.g. markup changes). [Type] Bug An existing feature does not function as intended
Projects
Development

Successfully merging this pull request may close these issues.

Details Block: Inner blocks cannot be focused using only the keyboard
6 participants