Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set focus visible when returning to some elements, add types. #47

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions src/App.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -33,22 +33,23 @@
let items = inputData;
let itemsFiltered = inputData;
let fuse = new Fuse(items, optionsFuse);
let focusedElement;
let focusedElement: HTMLElement | null = null;
let focusedElementFocusVisible = { visible: false };

onMount(() => {
initShortCuts(hotkeysGlobal);
setMainShortCut(hotkey, async () => {
if (showModal) {
onClosed()
} else {
focusedElement = document.activeElement
focusedElement = <HTMLElement>document.activeElement
showModal = true;
selectedIndex = 0;
dispatch("opened");
}
});
setAllShortCuts(inputData, async command => {
focusedElement = document.activeElement
focusedElement = <HTMLElement>document.activeElement
showModal = true;
dispatch("opened");
await asyncTimeout(200);
Expand Down Expand Up @@ -138,7 +139,17 @@
if ( ! focusedElement ) {
console.error("focusedElement not set")
} else {
focusedElement.focus()
if ( ['A', 'SUMMARY'].includes(focusedElement.tagName)) {
/* If focusedElement is one of these, they do not get focus rings
by default like inputs, selects etc. We want user to know
where focus is when we return so try to activate :focus-visible
styling. So use this standard.
Only implemented in Firefox currently.
*/
focusedElementFocusVisible.visible = true;
}
focusedElement.focus(
{focusVisible: focusedElementFocusVisible.visible})
}
}

Expand Down