Split search into shared state with inline homepage input and modal

This commit is contained in:
dtonon 2026-07-16 13:23:28 +01:00
parent b18b201fbb
commit d256abb42f
6 changed files with 316 additions and 172 deletions

View file

@ -1,13 +1,26 @@
let open = $state(false);
// When a page hosts an inline search input (the homepage), it registers a
// focus function here and every search trigger routes to it instead of the
// modal, so a modal input never opens on top of an inline one.
let inlineFocus: (() => void) | null = null;
export const searchModal = {
get open() {
return open;
},
};
export function registerInlineSearch(focus: () => void): () => void {
inlineFocus = focus;
return () => {
if (inlineFocus === focus) inlineFocus = null;
};
}
export function openSearch() {
open = true;
if (inlineFocus) inlineFocus();
else open = true;
}
export function closeSearch() {