Skip to content

Commit

Permalink
perf(ripple): don't process events in high contrast mode
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 591368699
  • Loading branch information
asyncLiz authored and Copybara-Service committed Dec 15, 2023
1 parent cc8d02c commit 839667d
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions ripple/internal/ripple.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,14 @@ const EVENTS = [
*/
const TOUCH_DELAY_MS = 150;

/**
* Used to detect if HCM is active. Events do not process during HCM when the
* ripple is not displayed.
*/
const FORCED_COLORS = isServer
? null
: window.matchMedia('(forced-colors: active)');

/**
* A ripple component.
*/
Expand Down Expand Up @@ -438,6 +446,11 @@ export class Ripple extends LitElement implements Attachable {

/** @private */
async handleEvent(event: Event) {
if (FORCED_COLORS?.matches) {
// Skip event logic since the ripple is `display: none`.
return;
}

switch (event.type) {
case 'click':
this.handleClick();
Expand Down

0 comments on commit 839667d

Please sign in to comment.