Skip to content

Commit

Permalink
Handle focus change and update shouldBeHinted for all hintables (#256)
Browse files Browse the repository at this point in the history
  • Loading branch information
david-tejada authored Dec 7, 2023
1 parent 3fab929 commit 770e581
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/content/wrappers/ElementWrapperClass.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { debounce } from "lodash";
import { ElementWrapper } from "../../typings/ElementWrapper";
import { getExtraHintsToggle } from "../actions/customHints";
import { openInNewTab } from "../actions/openInNewTab";
Expand Down Expand Up @@ -303,6 +304,19 @@ export function disconnectObservers() {
}
}

// FOCUS CHANGE
// Some elements could become visible after some other element is focused. For
// example, using `:focus-within ul { opacity: 1 }` the `ul` could become
// visible after focusing a sibling label.
// Example: https://v3.daisyui.com/components/dropdown/#method-2-using-label-and-css-focus
const debouncedHandleFocusChange = debounce(async () => {
await refresh({ shouldBeHinted: true });
}, 100);

// Using `focusin` and `focusout` here since `focus` and `blur` don't bubble.
document.addEventListener("focusin", debouncedHandleFocusChange);
document.addEventListener("focusout", debouncedHandleFocusChange);

// =============================================================================
// WRAPPER CLASS
// =============================================================================
Expand Down

0 comments on commit 770e581

Please sign in to comment.