@@ -455,6 +455,44 @@ else if (view) head = headOfView(view, areas, top?.measure); }); // Focus follows the screen on top, as a native stack's does: a screen // opened takes it at its title (its level, while it has none), and one // gone back to has it again where it was left, so it never stays in a // level covered (`inert`) or let go. Only where it was in this stack: // elsewhere (the frame's tabs, the search) it stays where it is. let stackElement: HTMLElement | undefined = $state(); /** Where focus was in each level now covered, by its id. */ const focusedIn = new Map<number, Element>(); let topId: number | undefined; /** The top level's id as it changes, and whether focus is to follow it there. */ let follow: number | null = null; $effect.pre(() => { const id = top?.id; untrack(() => { const was = topId; topId = id; if (was === undefined || id === undefined || was === id) return; for (const kept of focusedIn.keys()) if (!levels.some((l) => l.id === kept)) focusedIn.delete(kept); const focused = document.activeElement; if (!focused || !stackElement?.contains(focused)) return; if (levels.some((l) => l.id === was)) focusedIn.set(was, focused); follow = id; }); }); $effect(() => { void top?.id; untrack(() => { const id = follow; follow = null; if (id === null || id !== top?.id) return; const level = stackElement?.querySelector<HTMLElement>(':scope > section.level:not(.under)'); const back = focusedIn.get(id); focusedIn.delete(id); const to = back instanceof HTMLElement && back.isConnected ? back : (level?.querySelector<HTMLElement>(':scope > .screen-bar > h1') ?? level); to?.focus({ preventScroll: true }); }); }); // The root afresh whenever its call changes (signing in or out changes // it), but at first not where the server's page (`seed`) or `sync` has // set the stack already. @@ -641,7 +679,7 @@ {/if} {/snippet} <div class="stack" hidden={!active}> <div class="stack" hidden={!active} bind:this={stackElement}> {#if !root} <section class="level"> <header class="screen-bar"><h1 class:wordmark>{wordmark ?? title}</h1></header> @@ -653,7 +691,7 @@ {/if} {#each levels as level, i (level.id)} {@const shown = level === top} <section class="level" class:under={!shown} aria-hidden={!shown} inert={!shown} aria-busy={level.refreshing}> <section class="level" class:under={!shown} inert={!shown} aria-busy={level.refreshing} tabindex="-1"> <!-- Its screen drawn as it last was while its call is made again: a line along its top, taking no room. --> {#if level.refreshing}<span class="refreshing" aria-hidden="true"></span>{/if} <!-- While its screen loads, `reserved` where the screen's last tree had a Bar with buttons: the desktop frame keeps it, so its buttons fill in with no jump. --> @@ -663,9 +701,9 @@ <button type="button" class="back" onclick={onback} aria-label="Back"> <svg viewBox="0 0 24 24" aria-hidden="true"><path d="m15 18-6-6 6-6" /></svg> </button> {#if named}<h1 class="screen">{named}</h1>{/if} {#if named}<h1 class="screen" tabindex="-1">{named}</h1>{/if} {:else} <h1 class:wordmark>{wordmark ?? title}</h1> <h1 class:wordmark tabindex="-1">{wordmark ?? title}</h1> {/if} <span class="tools">{@render tools(level)}</span> </header>