-
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
Don't move focus within the toolbar if it is already focused #58570
Conversation
If the toolbar has focus already, we don't want to run a requestanimationFrame to then move focus to the previously unmounted index. Adding a check to see if focus is within the toolbar already, then not running the RAF fixes an issue where moving the block via the mover arrows would steal focus to the index before mount. Also added a fix for getAllFocusableToolbarItemsIn to not exclude aria-disabled buttons, as those can still receive focus.
Size Change: -832 B (0%) Total Size: 1.7 MB
ℹ️ View Unchanged
|
Flaky tests detected in dcd182b. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/7758939262
|
await expect( blockToolbarMoveUpButton ).not.toHaveAttribute( | ||
'aria-disabled', | ||
'true' | ||
); |
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.
await expect( blockToolbarMoveUpButton ).not.toHaveAttribute( | |
'aria-disabled', | |
'true' | |
); | |
await expect( blockToolbarMoveUpButton )toBeEnabled(); |
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 Core SVNIf you're a Core Committer, use this list when committing to
GitHub Merge commitsIf 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. |
await expect( blockToolbarMoveUpButton ).toHaveAttribute( | ||
'aria-disabled', | ||
'true' | ||
); |
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.
await expect( blockToolbarMoveUpButton ).toHaveAttribute( | |
'aria-disabled', | |
'true' | |
); | |
await expect( blockToolbarMoveUpButton ).toBeDisabled(); |
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.
In this case, it has aria-disabled
, but not disabled
, so it can still be focusable. It looks like toBeDisabled
only checks for disabled
property:
This custom matcher does not take into account the presence or absence of the aria-disabled attribute. For more on why this is the case, check testing-library/jest-dom#144.
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 is the Playwright assertion, which checks both - https://playwright.dev/docs/api/class-locatorassertions#locator-assertions-to-be-disabled.
Element is disabled if it has "disabled" attribute or is disabled via 'aria-disabled'.
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.
Ugh. Can't believe I missed that. Sorry! I'll add another little PR. Thanks for correcting me!
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.
Thank you, @jeryj! The fix works as expected!
Fixes #58511
What?
If the toolbar has focus already, we don't want to run a requestanimationFrame to then move focus to the previously unmounted index.
How?
Adding a check to see if focus is within the toolbar already, then not running the RAF fixes an issue where moving the block via the mover arrows would steal focus to the index before mount.
Also added a fix for getAllFocusableToolbarItemsIn to not exclude aria-disabled buttons, as those can still receive focus.
Testing Instructions