From 4d78600b11956fa3c80197337bdf2e4ab924a81a Mon Sep 17 00:00:00 2001 From: "LEWE, GEORGE" Date: Tue, 12 Sep 2023 19:56:51 +0200 Subject: [PATCH] Esc key exitst fullscreen --- src/ts/fullscreen.ts | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/ts/fullscreen.ts b/src/ts/fullscreen.ts index f953a623f..553170409 100644 --- a/src/ts/fullscreen.ts +++ b/src/ts/fullscreen.ts @@ -28,6 +28,7 @@ const SELECTOR_MINIMIZE_ICON = '[data-lte-icon="minimize"]' */ class FullScreen { _element: HTMLElement + constructor(element: HTMLElement) { this._element = element } @@ -86,6 +87,18 @@ onDOMContentLoaded(() => { } }) }) + document.addEventListener('keydown', event => { + event.preventDefault() + if (event.key === 'Escape' && document.fullscreenEnabled) { + const target = event.target as HTMLElement + const fsButton = target.closest(SELECTOR_FULLSCREEN_TOGGLE) as HTMLElement | undefined + + if (fsButton) { + const data = new FullScreen(fsButton) + data.toggleFullScreen() + } + } + }) }) export default FullScreen