Skip to content

Commit a76f301

Browse files
authored
fix(material/menu): clicks on disabled item closing the menu (#19183)
Adds an overlay on top of the content of a disabled menu item in order to capture clicks and prevent the menu from closing when clicking on it. Fixes #19173.
1 parent b9bfaee commit a76f301

File tree

2 files changed

+26
-13
lines changed

2 files changed

+26
-13
lines changed

src/material-experimental/mdc-menu/menu.scss

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,17 +67,25 @@ mat-menu {
6767
min-height: map.get($height-config, default);
6868

6969
&[disabled] {
70-
// Usually every click inside the menu closes it, however some browsers will stop events
71-
// when the user clicks on a disabled item, **except** when the user clicks on a non-disabled
72-
// child node of the disabled button. This is inconsistent because some regions of a disabled
73-
// button will still cause the menu to close and some won't (see #16694). We make the behavior
74-
// more consistent by disabling pointer events and allowing the user to click through.
75-
pointer-events: none;
7670
cursor: default;
7771

7872
// This is the same as `mdc-list-mixins.list-disabled-opacity` which
7973
// we can't use directly, because it comes with some selectors.
8074
opacity: mdc-list-variables.$content-disabled-opacity;
75+
76+
// The browser prevents clicks on disabled buttons from propagating which prevents the menu
77+
// from closing, but clicks on child nodes still propagate which is inconsistent (see #16694).
78+
// In order to keep the behavior consistent and prevent the menu from closing, we add an overlay
79+
// on top of the content that will catch all the clicks while disabled.
80+
&::before {
81+
display: block;
82+
position: absolute;
83+
content: '';
84+
top: 0;
85+
left: 0;
86+
bottom: 0;
87+
right: 0;
88+
}
8189
}
8290

8391
.mat-icon {

src/material/menu/menu.scss

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,18 @@ mat-menu {
5353
@include menu-common.item-base();
5454
position: relative;
5555

56-
&[disabled] {
57-
// Usually every click inside the menu closes it, however some browsers will stop events
58-
// when the user clicks on a disabled item, **except** when the user clicks on a non-disabled
59-
// child node of the disabled button. This is inconsistent because some regions of a disabled
60-
// button will still cause the menu to close and some won't (see #16694). We make the behavior
61-
// more consistent by disabling pointer events and allowing the user to click through.
62-
pointer-events: none;
56+
// The browser prevents clicks on disabled buttons from propagating which prevents the menu
57+
// from closing, but clicks on child nodes still propagate which is inconsistent (see #16694).
58+
// In order to keep the behavior consistent and prevent the menu from closing, we add an overlay
59+
// on top of the content that will catch all the clicks while disabled.
60+
&[disabled]::before {
61+
display: block;
62+
position: absolute;
63+
content: '';
64+
top: 0;
65+
left: 0;
66+
bottom: 0;
67+
right: 0;
6368
}
6469

6570
@include a11y.high-contrast(active, off) {

0 commit comments

Comments
 (0)