Skip to content

Commit cbc5f7c

Browse files
committed
fixup! fix(material/core): ripples not fading out on touch devices when scrolling
Support transition-duration
1 parent 0b3cf77 commit cbc5f7c

File tree

3 files changed

+37
-7
lines changed

3 files changed

+37
-7
lines changed

src/material/core/ripple/ripple-renderer.ts

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -139,12 +139,19 @@ export class RippleRenderer implements EventListenerObject {
139139
// We enforce a style recalculation by calling `getComputedStyle` and *accessing* a property.
140140
// See: https://gist.github.com/paulirish/5d52fb081b3570c81e3a
141141
const computedStyles = window.getComputedStyle(ripple);
142-
const transitionProperty = computedStyles.transitionProperty;
143-
144-
// Note: We detect whether animation is forcibly disabled through CSS by the use
145-
// of `transition: none`. This is technically unexpected since animations are
146-
// controlled through the animation config, but this exists for backwards compatibility
147-
const animationForciblyDisabledThroughCss = transitionProperty === 'none';
142+
const userTransitionProperty = computedStyles.transitionProperty;
143+
const userTransitionDuration = computedStyles.transitionDuration;
144+
145+
// Note: We detect whether animation is forcibly disabled through CSS by the use of
146+
// `transition: none`. This is technically unexpected since animations are controlled
147+
// through the animation config, but this exists for backwards compatibility. This logic does
148+
// not need to be super accurate since it covers some edge cases which can be easily avoided by users.
149+
const animationForciblyDisabledThroughCss =
150+
userTransitionProperty === 'none' ||
151+
// Note: The canonical unit for serialized CSS `<time>` properties is seconds. Additionally
152+
// some browsers expand the duration for every property (in our case `opacity` and `transform`).
153+
userTransitionDuration === '0s' ||
154+
userTransitionDuration === '0s, 0s';
148155

149156
// Exposed reference to the ripple that will be returned.
150157
const rippleRef = new RippleRef(this, ripple, config, animationForciblyDisabledThroughCss);

src/material/core/ripple/ripple.spec.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ describe('MatRipple', () => {
4444
RippleContainerWithoutBindings,
4545
RippleContainerWithNgIf,
4646
RippleCssTransitionNone,
47+
RippleCssTransitionDurationZero,
4748
],
4849
});
4950
});
@@ -788,6 +789,19 @@ describe('MatRipple', () => {
788789
dispatchMouseEvent(rippleTarget, 'mouseup');
789790
expect(rippleTarget.querySelectorAll('.mat-ripple-element').length).toBe(0);
790791
});
792+
793+
it('should handle forcibly disabled animations through CSS `transition-duration: 0ms`', async () => {
794+
fixture = TestBed.createComponent(RippleCssTransitionDurationZero);
795+
fixture.detectChanges();
796+
797+
rippleTarget = fixture.nativeElement.querySelector('.mat-ripple');
798+
799+
dispatchMouseEvent(rippleTarget, 'mousedown');
800+
expect(rippleTarget.querySelectorAll('.mat-ripple-element').length).toBe(1);
801+
802+
dispatchMouseEvent(rippleTarget, 'mouseup');
803+
expect(rippleTarget.querySelectorAll('.mat-ripple-element').length).toBe(0);
804+
});
791805
});
792806
});
793807

@@ -845,3 +859,10 @@ class RippleContainerWithNgIf {
845859
encapsulation: ViewEncapsulation.None,
846860
})
847861
class RippleCssTransitionNone {}
862+
863+
@Component({
864+
styles: [`* { transition-duration: 0ms !important; }`],
865+
template: `<div id="container" matRipple></div>`,
866+
encapsulation: ViewEncapsulation.None,
867+
})
868+
class RippleCssTransitionDurationZero {}

tools/public_api_guard/material/core.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -516,7 +516,9 @@ export class RippleRef {
516516
fadeOutRipple(ref: RippleRef): void;
517517
},
518518
element: HTMLElement,
519-
config: RippleConfig);
519+
config: RippleConfig, _animationForciblyDisabledThroughCss?: boolean);
520+
// (undocumented)
521+
_animationForciblyDisabledThroughCss: boolean;
520522
config: RippleConfig;
521523
element: HTMLElement;
522524
fadeOut(): void;

0 commit comments

Comments
 (0)