Skip to content
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

Merged

Conversation

petermakowski
Copy link
Contributor

@petermakowski petermakowski commented May 10, 2024

Done

  • feat: allow focusing disabled buttons and displaying tooltips
    • this allows to display associated tooltips via keyboard

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:

yarn start

QA in your project

from react-components run:

yarn build
npm pack

Install the resulting tarball in your project with:

yarn add <path-to-tarball>

QA steps

  • View the "Disabled with tooltip" button example in Storybook
  • Tab to the disabled button and verify the tooltip is displayed
  • Hover over the disabled button to see the tooltip appear
  • Click the disabled button and confirm the click is prevented

Percy steps

  • New "Disabled with tooltip" button example added

Fixes

Fixes: https://warthogs.atlassian.net/browse/MAASENG-2122

Screenshots

After

Google Chrome screenshot 001879@2x

@webteam-app
Copy link

@petermakowski petermakowski requested a review from ndv99 May 10, 2024 14:53
@petermakowski petermakowski changed the title feat: disabled button with tooltip feat: allow focusing disabled buttons and displaying tooltips May 10, 2024

return (
<Component
className={classes}
onClick={disabled ? onClickDisabled : onClick}
{...disabledProp}
aria-disabled={disabled ? disabled : undefined}
Copy link

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

Copy link
Contributor Author

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).

@bartaz
Copy link
Contributor

bartaz commented May 10, 2024

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.

@petermakowski
Copy link
Contributor Author

@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.

@petermakowski petermakowski force-pushed the feat-disabled-button-with-tooltip branch from 863e136 to 6234c4f Compare May 13, 2024 13:14
- this makes disabled buttons focusable allowing for display of associated tooltips via keyboard

Signed-off-by: Peter Makowski <me+git@petermakowski.io>
Copy link

@ndv99 ndv99 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

@petermakowski petermakowski merged commit 929a409 into canonical:main May 13, 2024
12 of 14 checks passed
Copy link

🎉 This PR is included in version 0.53.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants