Skip to content

Commit

Permalink
Poster: fix being re-focused after window regain focus
Browse files Browse the repository at this point in the history
  • Loading branch information
IRHM committed Oct 3, 2024
1 parent 48814c2 commit ed9a9aa
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
18 changes: 17 additions & 1 deletion src/lib/poster/GamePoster.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,23 @@
posterActive = false;
}
}}
on:mouseleave={() => (posterActive = false)}
on:mouseleave={() => {
posterActive = false;
const ae = document.activeElement;
if (
ae &&
ae instanceof HTMLElement &&
(ae.parentElement?.id === "ilikemoviessueme" ||
ae.parentElement?.parentElement?.id === "ilikemoviessueme")
) {
// Stops the poster being re-focused after the browser window
// loses focus, then regains it (ex: you middle click the poster,
// go to the opened tab (or lose browser window focus, then when
// you come back the poster is sent `focusin` and stuck activated
// until mouseleave again).
ae.blur();
}
}}
on:click={() => (posterActive = true)}
on:keyup={(e) => {
if (e.key === "Tab") {
Expand Down
18 changes: 17 additions & 1 deletion src/lib/poster/Poster.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,23 @@
posterActive = false;
}
}}
on:mouseleave={() => (posterActive = false)}
on:mouseleave={() => {
posterActive = false;
const ae = document.activeElement;
if (
ae &&
ae instanceof HTMLElement &&
(ae.parentElement?.id === "ilikemoviessueme" ||
ae.parentElement?.parentElement?.id === "ilikemoviessueme")
) {
// Stops the poster being re-focused after the browser window
// loses focus, then regains it (ex: you middle click the poster,
// go to the opened tab (or lose browser window focus, then when
// you come back the poster is sent `focusin` and stuck activated
// until mouseleave again).
ae.blur();
}
}}
on:click={() => (posterActive = true)}
on:keyup={(e) => {
if (e.key === "Tab") {
Expand Down

0 comments on commit ed9a9aa

Please sign in to comment.