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

fix(material/menu): clicks on disabled item closing the menu #19183

Merged
merged 1 commit into from
Mar 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 14 additions & 6 deletions src/material-experimental/mdc-menu/menu.scss
Original file line number Diff line number Diff line change
Expand Up @@ -67,17 +67,25 @@ mat-menu {
min-height: map.get($height-config, default);

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

// This is the same as `mdc-list-mixins.list-disabled-opacity` which
// we can't use directly, because it comes with some selectors.
opacity: mdc-list-variables.$content-disabled-opacity;

// The browser prevents clicks on disabled buttons from propagating which prevents the menu
// from closing, but clicks on child nodes still propagate which is inconsistent (see #16694).
// In order to keep the behavior consistent and prevent the menu from closing, we add an overlay
// on top of the content that will catch all the clicks while disabled.
&::before {
display: block;
position: absolute;
content: '';
top: 0;
left: 0;
bottom: 0;
right: 0;
}
}

.mat-icon {
Expand Down
19 changes: 12 additions & 7 deletions src/material/menu/menu.scss
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,18 @@ mat-menu {
@include menu-common.item-base();
position: relative;

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

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