Skip to content

Commit f2a06ab

Browse files
crisbetojelbourn
authored andcommittedDec 18, 2018
fix(menu): accidentally tapping on sub-menu content that overlaps trigger on touch devices (#14538)
We depend on the `mouseenter` event to switch between sub-menus, both on touch and mouse devices. Since `mouseenter` is emulated on touch devices, it fires much earlier in the event chain which means that the sub-menu can be shown before the user has lifted their finger. This can be an issue if the sub-menu overlaps the trigger in which case a click will be triggered on the content. These changes fix the issue by re-using an earlier fix that blocks interactions with the panel while it's animating. Note: an alternate approach can be to do something something similar to what we did with the ripples where we block `mouseenter` for a period after the last `touchstart` event. The problem of doing so is that it'll block all `mouseenter` events on touch devices which we depend on to toggle the panel when switching from one sub-menu to another.
1 parent bfacbb5 commit f2a06ab

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed
 

‎src/lib/menu/menu.scss

+11-7
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,17 @@ $mat-menu-submenu-indicator-size: 10px !default;
1414
border-radius: $mat-menu-border-radius;
1515
outline: 0;
1616

17+
// Prevent users from interacting with the panel while it's animating. Note that
18+
// people won't be able to click through it, because the overlay pane will catch the click.
19+
// This fixes the following issues:
20+
// * Users accidentally opening sub-menus when the `overlapTrigger` option is enabled.
21+
// * Users accidentally tapping on content inside the sub-menu on touch devices, if the
22+
// sub-menu overlaps the trigger. The issue is due to touch devices emulating the
23+
// `mouseenter` event by dispatching it on tap.
24+
&.ng-animating {
25+
pointer-events: none;
26+
}
27+
1728
@include cdk-high-contrast {
1829
outline: solid 1px;
1930
}
@@ -70,13 +81,6 @@ $mat-menu-submenu-indicator-size: 10px !default;
7081
transform: rotateY(180deg) translateY(-50%);
7182
}
7283
}
73-
74-
// Prevent the user from interacting while the panel is still animating.
75-
// This avoids issues where the user could accidentally open a sub-menu,
76-
// because of the `overlapTrigger` option.
77-
.mat-menu-panel.ng-animating & {
78-
pointer-events: none;
79-
}
8084
}
8185

8286
button.mat-menu-item {

0 commit comments

Comments
 (0)
Please sign in to comment.