feat: Escape should dismiss overlay messages (#2324)
This commit is contained in:
@@ -18,11 +18,13 @@ export class AdvancedCameraCardOverlayMessage extends LitElement {
|
|||||||
super.connectedCallback();
|
super.connectedCallback();
|
||||||
window.addEventListener('click', this._handleOutsideInteraction);
|
window.addEventListener('click', this._handleOutsideInteraction);
|
||||||
window.addEventListener('focusin', this._handleOutsideInteraction);
|
window.addEventListener('focusin', this._handleOutsideInteraction);
|
||||||
|
window.addEventListener('keydown', this._handleKeyDown);
|
||||||
}
|
}
|
||||||
|
|
||||||
public disconnectedCallback(): void {
|
public disconnectedCallback(): void {
|
||||||
window.removeEventListener('click', this._handleOutsideInteraction);
|
window.removeEventListener('click', this._handleOutsideInteraction);
|
||||||
window.removeEventListener('focusin', this._handleOutsideInteraction);
|
window.removeEventListener('focusin', this._handleOutsideInteraction);
|
||||||
|
window.removeEventListener('keydown', this._handleKeyDown);
|
||||||
super.disconnectedCallback();
|
super.disconnectedCallback();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -125,6 +127,14 @@ export class AdvancedCameraCardOverlayMessage extends LitElement {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
protected _handleKeyDown = (ev: KeyboardEvent): void => {
|
||||||
|
if (ev.key === 'Escape') {
|
||||||
|
this._dismiss();
|
||||||
|
ev.stopPropagation();
|
||||||
|
ev.preventDefault();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
static get styles(): CSSResultGroup {
|
static get styles(): CSSResultGroup {
|
||||||
return unsafeCSS(overlayMessageStyle);
|
return unsafeCSS(overlayMessageStyle);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user