Accordion Block: Add additional keypress handlers for navigation#71786
Accordion Block: Add additional keypress handlers for navigation#71786
Conversation
|
Size Change: +231 B (+0.01%) Total Size: 1.95 MB
ℹ️ View Unchanged
|
|
|
||
| if ( $p->next_tag( array( 'class_name' => 'wp-block-accordion' ) ) ) { | ||
| $p->set_attribute( 'data-wp-interactive', 'core/accordion' ); | ||
| $p->set_attribute( 'data-wp-context', '{ "autoclose": ' . $autoclose . ', "isOpen": [], "icon": "' . $icon . '", "iconPosition": "' . $icon_position . '" }' ); |
There was a problem hiding this comment.
I removed the icon and iconPosition context as there are not used anymore.
| accordionContent.isOpen = ! accordionContent.isOpen; | ||
| } | ||
| }, | ||
| handleKeyDown: withSyncEvent( ( event ) => { |
There was a problem hiding this comment.
Unfortunately, the withSyncEvent wrapper doesn't seem to work as expected. If you press arrowUp/ArrowDown/Home/End key on the toggle button, the browser console logs the following warning:
I believe this problem is the same as #69975, and should be fixed in #70325.
cc @felixarntz
|
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 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. |
joedolson
left a comment
There was a problem hiding this comment.
Tested with NVDA/Firefox, VoiceOver/Chrome and JAWS/Chrome, and with keyboard only.
With screen readers running, the home/end keys operated normally for the screen reader, navigating to the beginning and end of the current line. That's good; we don't want to override screen reader behavior with these shortcuts.
On the keyboard, focused moved as expected on arrow & home/end.
|
@joedolson Thanks for the review!
I would like to merge this PR because this issue is not new to this PR and should be fixed separately. |
…dPress#71786) Co-authored-by: t-hamano <[email protected]> Co-authored-by: joedolson <[email protected]>
Closes #71778
What?
This PR adds four keyboard navigation handlers to the Accordion Block.
Why?
See #71778 for more details.
How?
Each toggle button already has an ID like
accordion-content-{unique_id}applied to it. Furthermore, in the previous implementation, the isOpen state stored the ID of the currently open toggle like this:To implement the navigation function, I extended this state to store the IDs of all the toggles in the accordion and their respective open/closed states.
This gives us a list of the toggle buttons in the accordion, so we can calculate which toggle button should have focus depending on the key pressed.
Testing Instructions
Details
Testing Instructions for Keyboard
tabfocus move works as before.Screenshots or screencast
229858dce4017785fe5854c8ea64db54.mp4