Skip to content

feat(material/button): add the ability to interact with disabled buttons #28242

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 1 commit into from
Dec 11, 2023

Conversation

crisbeto
Copy link
Member

@crisbeto crisbeto commented Dec 7, 2023

Native disabled buttons don't allow focus and prevent the button from dispatching events. In some cases this can be problematic, because it prevents the app from showing to the user why the button is disabled.

These changes introduce a new opt-in input that will style buttons as disabled and set aria-disabled="true", but not set the native disabled attribute, allowing them to be interactive.

Note for reviewers: there's an example of the feature in the button demo, but you have to scroll down and check the "Allow disabled button interactivity" checkbox. Afterwards you should see tooltips when hovering over the disabled buttons.

@crisbeto crisbeto added P2 The issue is important to a large percentage of users, with a workaround G This is is related to a Google internal issue target: minor This PR is targeted for the next minor release dev-app preview When applied, previews of the dev-app are deployed to Firebase labels Dec 7, 2023
@angular-robot angular-robot bot added the detected: feature PR contains a feature commit label Dec 7, 2023
Copy link

github-actions bot commented Dec 7, 2023

Deployed dev-app for 5c26124 to: https://ng-dev-previews-comp--pr-angular-components-28242-dev-1mxl5pxh.web.app

Note: As new commits are pushed to this pull request, this link is updated after the preview is rebuilt.

@crisbeto crisbeto marked this pull request as ready for review December 7, 2023 10:52
@crisbeto crisbeto requested a review from zarend December 7, 2023 10:54
@crisbeto crisbeto force-pushed the disabled-interactive-button branch 7 times, most recently from 4ebe2ce to 3a54dc4 Compare December 7, 2023 15:13
Copy link
Contributor

@zarend zarend left a comment

Choose a reason for hiding this comment

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

This looks pretty reasonable to me.

Asked a few questions.

Question about describe/it is off-topic. Wondering what you're thinking about structuring unit tests. Changing the structure isn't a blocker for me on this PR :). I wanted to start a conversation about this because I'm having a problem in another PR for Tree where there are so many unit tests that it's hard to understand what's the unit tests are actually doing and what's being covered and what isn't being covered by tests.

Smoke tested on VoiceOver.

  • macOS 14.1.1 (23B81)
  • Chrome Version 119.0.6045.199 (Official Build) (arm64)
  • Firefox 120.0 (64-bit)
  • Safari Version 17.1 (19616.2.9.11.7)

/** Object that can be used to configure the default options for the button component. */
export interface MatButtonConfig {
/** Whether disabled buttons should be interactive. */
disabledInteractive?: boolean;
Copy link
Contributor

Choose a reason for hiding this comment

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

I see that the unit tests cover disabledInteractive via InputBinding. I don't see the unit testing covering disabledInteractive via MatButtonConfig. Do you think there's value in covering the DI workflow in unit tests?


**Note:** using the `disabledInteractive` input can result in buttons that previously prevented
actions to no longer do so, for example a submit button in a form. When using this input, you should
guard against such cases in your component.
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we provide an actionable suggestion, e.g. setting tabindex=0 (not sure if thats right)?

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't think that we can provide a general advice since it depends on what the button does.

@crisbeto crisbeto force-pushed the disabled-interactive-button branch from 3a54dc4 to 7510df0 Compare December 11, 2023 12:09
Native disabled buttons don't allow focus and prevent the button from dispatching events. In some cases this can be problematic, because it prevents the app from showing to the user why the button is disabled.

These changes introduce a new opt-in input that will style buttons as disabled and set `aria-disabled="true"`, but not set the native `disabled` attribute, allowing them to be interactive.
@crisbeto crisbeto force-pushed the disabled-interactive-button branch from 7510df0 to 5c26124 Compare December 11, 2023 21:20
@crisbeto crisbeto added action: merge The PR is ready for merge by the caretaker and removed dev-app preview When applied, previews of the dev-app are deployed to Firebase labels Dec 11, 2023
@crisbeto crisbeto self-assigned this Dec 11, 2023
@crisbeto crisbeto merged commit f23d8c1 into angular:main Dec 11, 2023
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Jan 11, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
action: merge The PR is ready for merge by the caretaker detected: feature PR contains a feature commit G This is is related to a Google internal issue P2 The issue is important to a large percentage of users, with a workaround target: minor This PR is targeted for the next minor release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants