-
Notifications
You must be signed in to change notification settings - Fork 1.2k
[Popover] Prevent setting a11y attributes when activator disabled #2473
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
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,15 +4,20 @@ export function setActivatorAttributes( | |
activator: HTMLElement, | ||
{ | ||
id, | ||
active, | ||
active = false, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @dpersing Adding a default value for the |
||
ariaHaspopup, | ||
activatorDisabled = false, | ||
}: { | ||
id: string; | ||
active: boolean; | ||
ariaHaspopup: AriaAttributes['aria-haspopup']; | ||
activatorDisabled: boolean; | ||
}, | ||
) { | ||
activator.tabIndex = activator.tabIndex || 0; | ||
if (!activatorDisabled) { | ||
activator.tabIndex = activator.tabIndex || 0; | ||
} | ||
|
||
activator.setAttribute('aria-controls', id); | ||
activator.setAttribute('aria-owns', id); | ||
activator.setAttribute('aria-expanded', String(active)); | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Rather than adding an
activatorDisabled
prop, what do you think about deriving the value rather than explicitly setting it?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.
The reason I ended up going the prop route is that the
Popover
can't expect/know what kind of element its activator is or whether it's even focusable. The above snippet would work, but we'd need to chain all other possibilities to that conditional (it could be a textfield, etc). Since disabling aButton
,TextField
etc is done explicitly, just telling thePopover
that the activator, whatever it may be, is disabled explicitly is a lot easier to test.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 wasn't aware that activators can be non-focusable. Maybe this is something we should try and enforce through types. Seems like a huge accessibility issue to not be able to open a popover through keyboard interactions 😬 cc/ @dpersing since your assigned as well, what do you think?
Using
HTMLButtonElement
type was just a quick example. There's other ways we can achieve the same type safety that'll work on any disablable element e.g.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.
Unfortunately adding the typing alone doesn't help. The real source of the problem is the
findFirstFocusableNode
utility because it eliminatesdisabled
elements as focusable selectors.Modifying the
FOCUSABLE_SELECTOR
s to remove the:not(disabled)
in@shopify/javascript-utilities
could cause unexpected breaking changes for other consumers of the utility, so I've updated the PR to use our own version.