-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
[Button] Make disabled buttons more accessible #6461
Conversation
…native html disabled
size-limit report 📦
|
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.
Overall, your logic is pretty sound here. Just a couple of semantic things to take a look at.
Also, you mentioned the disabled buttons still having a focus state when a user presses a key. Ideally we would want to avoid having the button change visually at all when it is disabled, event when focused. It's an industry best practice to do so, and also could cause potential confusion for users if it is the only button on screen and they feel they are interacting with it, but don't have an active button to compare it to note this is a disabled button, rather than us just having super low contrast regular buttons, if that makes sense.
polaris-react/src/components/UnstyledButton/tests/UnstyledButton.test.tsx
Show resolved
Hide resolved
thanks for the premium feedback marc, should all be resolved :) |
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 looks good to me! We'll probably need to get somebody from @Shopify/polaris-team to take a 👀 too though before we can merge it.
@@ -224,7 +224,7 @@ | |||
} | |||
|
|||
&:hover, | |||
&:focus { | |||
&:focus:not(.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.
Nice 👍
const handleClick = useCallback( | ||
(event: React.MouseEvent<HTMLButtonElement>) => { | ||
if (disabled) { | ||
event.preventDefault(); | ||
return; | ||
} | ||
toggleDisclosureActive(); | ||
}, | ||
[disabled, toggleDisclosureActive], | ||
); | ||
const handleKeyDown = useCallback( | ||
(event: React.KeyboardEvent<HTMLButtonElement>) => { | ||
if (['Enter', ' '].includes(event.key) && disabled) { | ||
event.preventDefault(); | ||
} | ||
}, | ||
[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.
I don't know off the top of my head, but I assumed using aria-disabled
would have given us this functionality for free. This logic could probably be repeated for all Polaris elements that are disabled.
+1 |
Yeah we could benefit from the fact that it communicates with assistive technologies. Apart from the semantics, though, we don't get features like click prevention, focus prevention:
A nice table from this article reference: I'm currently exploring exporting the logic to a custom hook in order to be repeated in other Polaris elements. |
Hey @zakwarsame I don't think we should ship changes based off the css tricks article. Have we found issues using assistive technologies? Can we replicate the issue you are fixing? |
The source I quoted there is actually from MDN- I only used the table from css tricks to represent what's written in MDN visually. I can understand that we need to confirm it, so I've replicated this myself. Here is how: Issue
Solution
Why we need to additionally disable clicks with javascript on
Final proposal
|
@zakwarsame this is an excellent write up. Thank you. Honestly this is super. It's interesting to me that disabled elements can receive focus. What do you think about changing the |
Thank you! I think having them be focusable but styling to indicate that they're not clickable is the perfect compromise.
Considering that most people with visual impairments will prefer to navigate using the keyboard, wouldn't
I'm going to explore this further before merging, for best results. |
No focus when only navigating with keyboards:not-focusable.movWith a screen reader (🔊):tabIndex-soln.mov |
a3a40bb
to
0281d22
Compare
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.
Couple of little nits but nothing from my side that would block a release, nice one!
@zakwarsame I'm currently having to run Polaris Uplift on Email, and we need to overwrite some properties to make sure it matches our UI. Normally, I target From an a11y POV, I don't see how Surely I can target the |
WHY are these changes introduced?
disabled
prop is set to trueTab
orTab + Shift
keys and also makes it difficult for screen readers to locate it.aria-disabled
instead makes it easy for screen readers and keyboard users to interpret the button.Fixes #5967
WHAT is this pull request doing?
disabled
witharia-disabled
How to 🎩
Tab
key🖥 Check out this short demo video
🎩 checklist
README.md
with documentation changes