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