Skip to content

Commit 4a4b3cf

Browse files
committed
Remove/restore focus as console is hidden/shown
1 parent 7e1a141 commit 4a4b3cf

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

_extensions/drop/drop-runtime.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

drop-runtime/src/drop-runtime.ts

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ declare global {
88
RevealDrop?: {
99
id: string;
1010
dropElement: HTMLDivElement;
11+
focusElement: Element | null;
1112
init: (reveal: any) => void;
1213
toggleDrop: () => void;
1314
isActive: () => boolean;
@@ -33,6 +34,7 @@ type DropConfig = {
3334

3435
window.RevealDrop = window.RevealDrop || {
3536
id: 'RevealDrop',
37+
focusElement: null,
3638
dropElement: document.createElement('div'),
3739
init: function (reveal) {
3840
const revealConfig = reveal.getConfig();
@@ -83,12 +85,26 @@ window.RevealDrop = window.RevealDrop || {
8385
window.RevealDrop.toggleDrop();
8486
reveal.toggleHelp(false);
8587
reveal.toggleOverview(false);
86-
reveal.configure({ keyboard: !window.RevealDrop.isActive() });
88+
89+
if (window.RevealDrop.isActive()) {
90+
reveal.configure({ keyboard: false });
91+
// Restore focus as console is shown
92+
if (window.RevealDrop.focusElement instanceof HTMLElement) {
93+
window.RevealDrop.focusElement.focus();
94+
}
95+
} else {
96+
reveal.configure({ keyboard: true });
97+
// Remove focus as console is hidden
98+
window.RevealDrop.focusElement = document.activeElement;
99+
if (document.activeElement instanceof HTMLElement) {
100+
document.activeElement.blur();
101+
}
102+
}
103+
87104
event.preventDefault();
88105
event.stopPropagation();
89106
}
90107
}, { capture: true });
91-
92108
},
93109
toggleDrop() {
94110
window.RevealDrop.dropElement.classList.toggle("active");

0 commit comments

Comments
 (0)