Skip to content

Commit

Permalink
Remove/restore focus as console is hidden/shown
Browse files Browse the repository at this point in the history
  • Loading branch information
georgestagg committed Jul 24, 2024
1 parent 7e1a141 commit 4a4b3cf
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
2 changes: 1 addition & 1 deletion _extensions/drop/drop-runtime.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 18 additions & 2 deletions drop-runtime/src/drop-runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ declare global {
RevealDrop?: {
id: string;
dropElement: HTMLDivElement;
focusElement: Element | null;
init: (reveal: any) => void;
toggleDrop: () => void;
isActive: () => boolean;
Expand All @@ -33,6 +34,7 @@ type DropConfig = {

window.RevealDrop = window.RevealDrop || {
id: 'RevealDrop',
focusElement: null,
dropElement: document.createElement('div'),
init: function (reveal) {
const revealConfig = reveal.getConfig();
Expand Down Expand Up @@ -83,12 +85,26 @@ window.RevealDrop = window.RevealDrop || {
window.RevealDrop.toggleDrop();
reveal.toggleHelp(false);
reveal.toggleOverview(false);
reveal.configure({ keyboard: !window.RevealDrop.isActive() });

if (window.RevealDrop.isActive()) {
reveal.configure({ keyboard: false });
// Restore focus as console is shown
if (window.RevealDrop.focusElement instanceof HTMLElement) {
window.RevealDrop.focusElement.focus();
}
} else {
reveal.configure({ keyboard: true });
// Remove focus as console is hidden
window.RevealDrop.focusElement = document.activeElement;
if (document.activeElement instanceof HTMLElement) {
document.activeElement.blur();
}
}

event.preventDefault();
event.stopPropagation();
}
}, { capture: true });

},
toggleDrop() {
window.RevealDrop.dropElement.classList.toggle("active");
Expand Down

0 comments on commit 4a4b3cf

Please sign in to comment.