Skip to content

Commit

Permalink
(fix) [Ripple] Reset hover state when ripple is disabled
Browse files Browse the repository at this point in the history
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
  • Loading branch information
dfreedm authored and copybara-github committed Apr 30, 2021
1 parent cc813cf commit 0875e89
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- Fix issue with diff indices of different digit length
- `ripple`
- Fix IE11 errors with `isActive()`
- Fix cases where `hover` effect is stuck when toggling `disabled`
- `select`
- menu not opening when disabled initially set
- `tab`
Expand Down
14 changes: 13 additions & 1 deletion packages/ripple/mwc-ripple-base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {BaseElement} from '@material/mwc-base/base-element';
import {RippleInterface} from '@material/mwc-base/utils';
import {MDCRippleAdapter} from '@material/ripple/adapter';
import MDCRippleFoundation from '@material/ripple/foundation';
import {html, internalProperty, property, query, TemplateResult} from 'lit-element';
import {html, internalProperty, property, PropertyValues, query, TemplateResult} from 'lit-element';
import {classMap} from 'lit-html/directives/class-map';
import {styleMap} from 'lit-html/directives/style-map';

Expand Down Expand Up @@ -184,6 +184,18 @@ export class RippleBase extends BaseElement implements RippleInterface {
}
}

protected update(changedProperties: PropertyValues<this>) {
if (changedProperties.has('disabled')) {
// stop hovering when ripple is disabled to prevent a stuck "hover" state
// When re-enabled, the outer component will get a `mouseenter` event on
// the first movement, which will call `startHover()`
if (this.disabled) {
this.endHover();
}
}
super.update(changedProperties);
}

/** @soyTemplate */
protected render(): TemplateResult {
const shouldActivateInPrimary =
Expand Down
8 changes: 8 additions & 0 deletions packages/ripple/test/mwc-ripple.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,5 +94,13 @@ suite('mwc-ripple', () => {
await element.updateComplete;
assert.equal(internals.hovering, false);
});

test('stops hovering when disabled', async () => {
element.startHover();
await element.updateComplete;
element.disabled = true;
await element.updateComplete;
assert.equal(internals.hovering, false);
});
});
});

0 comments on commit 0875e89

Please sign in to comment.