perf(ripple): don't process events in high contrast mode

PiperOrigin-RevId: 591368699
This commit is contained in:
Elizabeth Mitchell 2023-12-15 15:01:08 -08:00 committed by Copybara-Service
parent cc8d02c847
commit 839667dcf6

View File

@ -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.
*/
@ -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();