Skip to content

Commit 88170e9

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

File tree

3 files changed

+31
-3
lines changed

3 files changed

+31
-3
lines changed

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,12 +139,17 @@ 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;
142+
const userTransitionProperty = computedStyles.transitionProperty;
143+
const userTransitionDuration = computedStyles.transitionDuration;
143144

144145
// Note: We detect whether animation is forcibly disabled through CSS by the use
145146
// of `transition: none`. This is technically unexpected since animations are
146147
// controlled through the animation config, but this exists for backwards compatibility
147-
const animationForciblyDisabledThroughCss = transitionProperty === 'none';
148+
const animationForciblyDisabledThroughCss =
149+
userTransitionProperty === '' ||
150+
userTransitionDuration === '' ||
151+
userTransitionProperty === 'none' ||
152+
userTransitionDuration === '0s';
148153

149154
// Exposed reference to the ripple that will be returned.
150155
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)