Skip to content

bug(menu): Disabled mat-menu-item on anchor tag still clickable #27895

Open
@shammy8

Description

@shammy8

Is this a regression?

  • Yes, this behavior used to work in the previous version

The previous version in which this bug was not present was

No response

Description

A disabled mat-menu-item anchor ie<a disabled mat-menu-item (click)="stillGetsCalled()" routerLink="/stillNavigates"> Anchor</a> looks disabled but is still clickable.

However a regular href <a disabled mat-menu-item href="https://www.google.com"> Google</a> works as expected

This occurs with the cdk menu item too.

Reproduction

StackBlitz link: https://stackblitz.com/edit/32sike?file=src%2Fexample%2Fmenu-icons-example.html
Steps to reproduce:

  1. Click the 3 dot menu, click Disabled Anchor Click, 'anchor click' is logged to the console
  2. Click the 3 dot menu, click Disabled Anchor RouterLink, NewComponent is rendered in the router-outlet

Expected Behavior

<a disabled mat-menu-item (click)="stillGetsCalled()" routerLink="/stillNavigates"> should not be clickable

Actual Behavior

<a disabled mat-menu-item (click)="stillGetsCalled()" routerLink="/stillNavigates"> is clickable

Environment

  • Angular: 16
  • CDK/Material: 16
  • Browser(s): Chrome
  • Operating System (e.g. Windows, macOS, Ubuntu): Windows 11

Activity

added
P3An issue that is relevant to core functions, but does not impede progress. Important, but not urgent
and removed
needs triageThis issue needs to be triaged by the team
on Oct 12, 2023
dcchristopher

dcchristopher commented on Dec 26, 2023

@dcchristopher

Also encountered this issue when upgrading from 15 to 17. Whether it's a [routerLink] attribute or (click) event, just make sure to use a ternary: shouldBeDisabled ? undefined : normalActionOrValue. That will stop any click event in its tracks.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3An issue that is relevant to core functions, but does not impede progress. Important, but not urgentarea: material/menu

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @dcchristopher@andrewseguin@shammy8

        Issue actions

          bug(menu): Disabled mat-menu-item on anchor tag still clickable · Issue #27895 · angular/components