Skip to content

Commit 0875e89

Browse files
dfreedmcopybara-github
authored andcommitted
(fix) [Ripple] Reset hover state when ripple is disabled
If a component is being hovered when disabled, ripple will miss the `mouseleave` event needed to deactivate the hover state. When the component is enabled again, the first movement inside of the component will send a `mouseenter` event and apply hover state again. PiperOrigin-RevId: 371405096
1 parent cc813cf commit 0875e89

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
5353
- Fix issue with diff indices of different digit length
5454
- `ripple`
5555
- Fix IE11 errors with `isActive()`
56+
- Fix cases where `hover` effect is stuck when toggling `disabled`
5657
- `select`
5758
- menu not opening when disabled initially set
5859
- `tab`

packages/ripple/mwc-ripple-base.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import {BaseElement} from '@material/mwc-base/base-element';
1919
import {RippleInterface} from '@material/mwc-base/utils';
2020
import {MDCRippleAdapter} from '@material/ripple/adapter';
2121
import MDCRippleFoundation from '@material/ripple/foundation';
22-
import {html, internalProperty, property, query, TemplateResult} from 'lit-element';
22+
import {html, internalProperty, property, PropertyValues, query, TemplateResult} from 'lit-element';
2323
import {classMap} from 'lit-html/directives/class-map';
2424
import {styleMap} from 'lit-html/directives/style-map';
2525

@@ -184,6 +184,18 @@ export class RippleBase extends BaseElement implements RippleInterface {
184184
}
185185
}
186186

187+
protected update(changedProperties: PropertyValues<this>) {
188+
if (changedProperties.has('disabled')) {
189+
// stop hovering when ripple is disabled to prevent a stuck "hover" state
190+
// When re-enabled, the outer component will get a `mouseenter` event on
191+
// the first movement, which will call `startHover()`
192+
if (this.disabled) {
193+
this.endHover();
194+
}
195+
}
196+
super.update(changedProperties);
197+
}
198+
187199
/** @soyTemplate */
188200
protected render(): TemplateResult {
189201
const shouldActivateInPrimary =

packages/ripple/test/mwc-ripple.test.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,5 +94,13 @@ suite('mwc-ripple', () => {
9494
await element.updateComplete;
9595
assert.equal(internals.hovering, false);
9696
});
97+
98+
test('stops hovering when disabled', async () => {
99+
element.startHover();
100+
await element.updateComplete;
101+
element.disabled = true;
102+
await element.updateComplete;
103+
assert.equal(internals.hovering, false);
104+
});
97105
});
98106
});

0 commit comments

Comments
 (0)