Skip to content

Commit 045d15d

Browse files
authored
feat: Escape should dismiss overlay messages (#2324)
1 parent c03ddd9 commit 045d15d

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/components/overlay-message.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,13 @@ export class AdvancedCameraCardOverlayMessage extends LitElement {
1818
super.connectedCallback();
1919
window.addEventListener('click', this._handleOutsideInteraction);
2020
window.addEventListener('focusin', this._handleOutsideInteraction);
21+
window.addEventListener('keydown', this._handleKeyDown);
2122
}
2223

2324
public disconnectedCallback(): void {
2425
window.removeEventListener('click', this._handleOutsideInteraction);
2526
window.removeEventListener('focusin', this._handleOutsideInteraction);
27+
window.removeEventListener('keydown', this._handleKeyDown);
2628
super.disconnectedCallback();
2729
}
2830

@@ -125,6 +127,14 @@ export class AdvancedCameraCardOverlayMessage extends LitElement {
125127
}
126128
};
127129

130+
protected _handleKeyDown = (ev: KeyboardEvent): void => {
131+
if (ev.key === 'Escape') {
132+
this._dismiss();
133+
ev.stopPropagation();
134+
ev.preventDefault();
135+
}
136+
};
137+
128138
static get styles(): CSSResultGroup {
129139
return unsafeCSS(overlayMessageStyle);
130140
}

0 commit comments

Comments
 (0)