Skip to content

Commit 9c4d601

Browse files
devversionjelbourn
authored andcommitted
fix(button): ripples blocking mouse events on user content (#4526)
* fix(button): ripples blocking mouse events on user content * The ripple overlay intercepts all mouse events on the user content and therefore users are not able to have interactive elements in their buttons. Normally buttons should not contain interactive elements inside, but since the fix is very easy it wouldn't hurt fixing it. * Removing the `(touchstart)` event that should prevent initial clicks because it didn't do anything (because of pointer-events: none) and the initial click doesn't seem to happen anymore. Related to #4503 * Update comment for overlay
1 parent 84ea8b2 commit 9c4d601

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

src/lib/button/button.html

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,4 @@
33
[class.mat-button-ripple-round]="_isRoundButton || _isIconButton"
44
[mdRippleCentered]="_isIconButton"
55
[mdRippleTrigger]="_getHostElement()"></div>
6-
<!-- the touchstart handler prevents the overlay from capturing the initial tap on touch devices -->
7-
<div class="mat-button-focus-overlay" (touchstart)="$event.preventDefault()"></div>
6+
<div class="mat-button-focus-overlay"></div>

src/lib/button/button.scss

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,17 +64,19 @@
6464
left: 0;
6565
bottom: 0;
6666
right: 0;
67+
68+
// Disable pointer events for the ripple container and focus overlay because the container
69+
// will overlay the user content and we don't want to disable mouse events on the user content.
70+
// Pointer events can be safely disabled because the ripple trigger element is the host element.
71+
pointer-events: none;
6772
}
6873

69-
// Overlay to be used as a tint. Note that the same effect can be achieved by using a pseudo
70-
// element, however we use a proper DOM element in order to be able to disable the default
71-
// touch action. This makes the buttons more responsive on touch devices.
74+
// Element that overlays the button to show focus and hover effects.
7275
.mat-button-focus-overlay {
7376
// The button spec calls for focus on raised buttons (and FABs) to be indicated with a
7477
// black, 12% opacity shade over the normal color (for both light and dark themes).
7578
background-color: rgba(black, 0.12);
7679
border-radius: inherit;
77-
pointer-events: none;
7880
opacity: 0;
7981

8082
transition: $mat-button-focus-transition;

0 commit comments

Comments
 (0)