-
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
ToggleGroupControl: Fix arrow key navigation in RTL #65735
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 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. |
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 🚀
Tests well with both left-right and up-down arrows 👍
* ToggleGroupControl: Fix arrow key navigation in RTL * Add changelog Co-authored-by: mirka <0mirka00@git.wordpress.org> Co-authored-by: tyxla <tyxla@git.wordpress.org>
I just cherry-picked this PR to the wp/6.7 branch to get it included in the next release: aa59d85 |
Thanks for the fix! I would like to update #64963 and clarify the remaining tasks. |
It would be good to unify the way we check for RTL. I don't know if there are any hidden implications (ie., could a user ever end up where the WP language is a RTL language BUT the document's
Doesn't seem high priority, though. |
I don't currently see an issue with |
For some reason the MDN page for the
According to that the right way to do WP-agnostic DOM-only RTL check is: element.ownerDocument.documentElement.dir === 'rtl' |
* ToggleGroupControl: Fix arrow key navigation in RTL * Add changelog Co-authored-by: mirka <0mirka00@git.wordpress.org> Co-authored-by: tyxla <tyxla@git.wordpress.org>
Whether you use the CSS property or the HTML attribute, the computed result is the same. I made a demo to illustrate this: https://stackblitz.com/edit/stackblitz-starters-mc6hcb?file=script.js
That's true, though I still think it's worth removing extra dependencies when possible. Keeping a minimal dep footprint gives us more flexibility and, in this case, might allow us to tree-shake that part of the library away.
That's not necessarily a problem if we're okay with checking export default function isRTL( element = document.body ) {
return getComputedStyle( element ).direction === 'rtl';
}
isRTL(); While still allowing an element in, which is useful for us to do something like: isRTL(containerRef); Which is more specific, and in the rare case that the direction is different in the subtree that component is in, it will correctly pick its value up. So, in a way, this would potentially improve detection and prevent some edge cases. That is, in the case that the current Another point in favor of doing this is that we might want to use |
* ToggleGroupControl: Fix arrow key navigation in RTL * Add changelog Co-authored-by: mirka <0mirka00@git.wordpress.org> Co-authored-by: tyxla <tyxla@git.wordpress.org>
* ToggleGroupControl: Fix arrow key navigation in RTL * Add changelog Co-authored-by: mirka <0mirka00@git.wordpress.org> Co-authored-by: tyxla <tyxla@git.wordpress.org>
Reported in #64963 (comment)
What?
Fixes arrow key navigation when ToggleGroupControl is in RTL mode.
Testing Instructions for Keyboard
See default Storybook story for ToggleGroupControl and toggle it to RTL mode in the toolbar. Test that arrow key navigation works as expected.
CleanShot.2024-09-30.at.19.03.16.mp4