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
feat: allow focusing disabled buttons and displaying tooltips #1082
feat: allow focusing disabled buttons and displaying tooltips #1082
Conversation
src/components/Button/Button.tsx
Outdated
|
||
return ( | ||
<Component | ||
className={classes} | ||
onClick={disabled ? onClickDisabled : onClick} | ||
{...disabledProp} | ||
aria-disabled={disabled ? disabled : undefined} |
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.
Can this not just be disabled
passed directly in? It's already a boolean/undefined value
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 to explicitly skip this prop when false. This is similar to existing behaviour where disabled={false}
results in disabled
attribute not being rendered at all. I did this to reduce the impact of this change (such as failing snapshot tests).
We had some discussions around that in the past, with no exact conclusion from UX part what's the best approach: canonical/vanilla-framework#4299 canonical/vanilla-framework#4942 But seems like having tooltips on disabled buttons is something that we want, so this may be a way for implementing this. Is there anything here that would be worth upstreaming to Vanilla? I guess there are no CSS changes needed, but I guess we could have a similar example and functionality documented there. |
@bartaz I don't think there is anything major that would need to be upstreamed to Vanilla as it already handles disabled state as expected without using :disabled through .is-disabled class. We might want to update the Vanilla guidelines and suggest not using :disabled but aria-disabled with .is-disabled instead. We could also allow applying disabled through aria-disabled selector as an alternative. None of these changes are required for this PR to land, it stands on its own as is IMO. |
863e136
to
6234c4f
Compare
- this makes disabled buttons focusable allowing for display of associated tooltips via keyboard Signed-off-by: Peter Makowski <me+git@petermakowski.io>
6234c4f
to
51533c2
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.
LGTM 👍
🎉 This PR is included in version 0.53.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Done
Rationale
Previously,
disabled
attribute was used which prevents focusing the button entirely. This meant that users navigating by keyboard could not focus the button and any associated tooltip would not be displayed.By switching to aria-disabled, the button can still be focused while conveying its disabled state to assistive technologies. Submit action is prevented by using
.preventDefault
.https://css-tricks.com/making-disabled-buttons-more-inclusive/
QA
Storybook
To see rendered examples of all react-components, run:
QA in your project
from
react-components
run:Install the resulting tarball in your project with:
QA steps
Percy steps
Fixes
Fixes: https://warthogs.atlassian.net/browse/MAASENG-2122
Screenshots
After