Commit 80325823d for llama.cpp

commit 80325823d47ce8d02ae487de4b5563b2695684e4
Author: Aleksander Grygier <aleksander.grygier@gmail.com>
Date:   Sat Nov 21 13:21:47 2026 +0100

    ui: open the context gauge panel on click as a popover (#32685)

    * ui: open the context gauge panel on click as a popover

    Assisted-by: Claude (Opus 5.5 Medium)

    * ui: give the context gauge trigger the ghost button hover

    Assisted-by: Claude (Opus 5.5 Medium)

diff --git a/ui/apps/chat/src/lib/components/app/chat/ChatForm/ChatForm.svelte b/ui/apps/chat/src/lib/components/app/chat/ChatForm/ChatForm.svelte
index 727ceccd7..b9845cc86 100644
--- a/ui/apps/chat/src/lib/components/app/chat/ChatForm/ChatForm.svelte
+++ b/ui/apps/chat/src/lib/components/app/chat/ChatForm/ChatForm.svelte
@@ -1,5 +1,5 @@
 <script lang="ts">
-	import ContextGaugePopup from './ChatFormContextGauge/ContextGaugePopup.svelte';
+	import ContextGaugeDrawer from './ChatFormContextGauge/ContextGaugeDrawer.svelte';
 	import { microphoneUnavailableReason, warmUpVoiceCapture } from '@ggml-org/llama-voice';
 	import { VoiceRecorder } from '@ggml-org/llama-voice/svelte';
 	import { Maximize, Minimize } from '@lucide/svelte';
@@ -882,7 +882,9 @@
 		</div>
 	</div>

-	<ContextGaugePopup />
+	{#if deviceStore.isMobile}
+		<ContextGaugeDrawer />
+	{/if}

 	<!-- iOS Safari tints its bottom toolbar from a solid fixed element at the screen's bottom
 	     edge: this strip carries the sheet's fill while it rests -->
diff --git a/ui/apps/chat/src/lib/components/app/chat/ChatForm/ChatFormContextGauge/ChatFormContextGauge.svelte b/ui/apps/chat/src/lib/components/app/chat/ChatForm/ChatFormContextGauge/ChatFormContextGauge.svelte
index 221e7b511..4544d8fe4 100644
--- a/ui/apps/chat/src/lib/components/app/chat/ChatForm/ChatFormContextGauge/ChatFormContextGauge.svelte
+++ b/ui/apps/chat/src/lib/components/app/chat/ChatForm/ChatFormContextGauge/ChatFormContextGauge.svelte
@@ -1,25 +1,23 @@
 <script lang="ts">
 	import ContextGaugeDial from './ContextGaugeDial.svelte';
-	import {
-		gaugeTriggerClick,
-		gaugeTriggerEnter,
-		gaugeTriggerKeydown,
-		gaugeTriggerLeave,
-		gaugeTriggerPointerDown
-	} from './gauge-popup.svelte';
+	import ContextGaugePanel from './ContextGaugePanel.svelte';
+	import { gaugePopup, gaugePopupToggle } from './gauge-popup.svelte';
+	import { buttonVariants } from '@ggml-org/llama-ui/ui/button';
+	import * as Popover from '@ggml-org/llama-ui/ui/popover';
+	import { cn } from '@ggml-org/llama-ui/utils';
 	import GlassKey from '#lib/components/app/actions/GlassKey.svelte';
 	import { useContextGauge } from '#lib/hooks/use-context-gauge.svelte.ts';
 	import { chatStore, conversationsStore, deviceStore } from '#lib/stores/index.ts';
 	import { untrack } from 'svelte';

 	interface Props {
-		/** Sizes and places the trigger, the inline dial size by default. */
+		/** Sizes and places the trigger. */
 		class?: string;
 		/** Draws the dial as the icon of a phone's corner key, matching the menu key's glyph. */
 		corner?: boolean;
 	}

-	let { class: className = 'h-5 w-5 max-md:h-6 max-md:w-6', corner = false }: Props = $props();
+	let { class: className = '', corner = false }: Props = $props();

 	const gauge = useContextGauge();

@@ -55,34 +53,54 @@
 	<ContextGaugeDial level={gauge.colorLevel} percent={gauge.contextPercent} {size} />
 {/snippet}

-{#if corner}
-	<!-- a phone's corner key, the same glass key as the menu key across from it -->
-	<GlassKey
-		class={className}
-		data-context-gauge-trigger
-		label="Context usage"
-		onclick={gaugeTriggerClick}
-		onkeydown={gaugeTriggerKeydown}
-		onpointerdown={gaugeTriggerPointerDown}
-		onpointerenter={gaugeTriggerEnter}
-		onpointerleave={gaugeTriggerLeave}
-	>
-		{@render dial('key')}
-	</GlassKey>
+<!-- a phone's tap opens the drawer the chat form renders; elsewhere a click opens the popover -->
+{#if deviceStore.isMobile}
+	{#if corner}
+		<!-- a phone's corner key, the same glass key as the menu key across from it -->
+		<GlassKey
+			aria-expanded={gaugePopup.open}
+			aria-haspopup="dialog"
+			class={className}
+			label="Context usage"
+			onclick={gaugePopupToggle}
+		>
+			{@render dial('key')}
+		</GlassKey>
+	{:else}
+		<button
+			aria-expanded={gaugePopup.open}
+			aria-haspopup="dialog"
+			aria-label="Context usage"
+			class={['flex size-6 items-center justify-center rounded-full', className]}
+			onclick={gaugePopupToggle}
+			type="button"
+		>
+			<!-- a phone gets the larger dial: the trigger is a touch target there -->
+			{@render dial('md')}
+		</button>
+	{/if}
 {:else}
-	<div
-		aria-label="Context usage"
-		class={['flex cursor-default items-center justify-center', className]}
-		data-context-gauge-trigger
-		onclick={gaugeTriggerClick}
-		onkeydown={gaugeTriggerKeydown}
-		onpointerdown={gaugeTriggerPointerDown}
-		onpointerenter={gaugeTriggerEnter}
-		onpointerleave={gaugeTriggerLeave}
-		role="button"
-		tabindex="0"
-	>
-		<!-- a phone gets the larger dial: the trigger is a touch target there -->
-		{@render dial(deviceStore.isMobile ? 'md' : 'sm')}
-	</div>
+	<Popover.Root bind:open={gaugePopup.open}>
+		<Popover.Trigger
+			aria-label="Context usage"
+			class={cn(
+				buttonVariants({ variant: 'ghost' }),
+				'size-7 cursor-pointer rounded-full p-0',
+				className
+			)}
+		>
+			{@render dial('sm')}
+		</Popover.Trigger>
+
+		<!-- bits-ui sets aria-haspopup="dialog" on the trigger but gives the content no role -->
+		<Popover.Content
+			aria-label="Context"
+			class="w-64 rounded-xl p-1.5 text-body-sm"
+			role="dialog"
+			side="top"
+			sideOffset={8}
+		>
+			<ContextGaugePanel />
+		</Popover.Content>
+	</Popover.Root>
 {/if}
diff --git a/ui/apps/chat/src/lib/components/app/chat/ChatForm/ChatFormContextGauge/ContextGaugeDrawer.svelte b/ui/apps/chat/src/lib/components/app/chat/ChatForm/ChatFormContextGauge/ContextGaugeDrawer.svelte
new file mode 100644
index 000000000..55f76580e
--- /dev/null
+++ b/ui/apps/chat/src/lib/components/app/chat/ChatForm/ChatFormContextGauge/ContextGaugeDrawer.svelte
@@ -0,0 +1,20 @@
+<script lang="ts">
+	import ContextGaugePanel from './ContextGaugePanel.svelte';
+	import { gaugePopup } from './gauge-popup.svelte';
+	import * as Drawer from '@ggml-org/llama-ui/ui/drawer';
+</script>
+
+<!-- a phone shows the context panel in a drawer from the screen's bottom; wider screens use the gauge's popover -->
+<Drawer.Root bind:open={gaugePopup.open}>
+	<Drawer.Content>
+		<Drawer.Header>
+			<Drawer.Title>Context</Drawer.Title>
+
+			<Drawer.Description class="sr-only">
+				Context window usage of the model the chat runs
+			</Drawer.Description>
+		</Drawer.Header>
+
+		<ContextGaugePanel inDrawer />
+	</Drawer.Content>
+</Drawer.Root>
diff --git a/ui/apps/chat/src/lib/components/app/chat/ChatForm/ChatFormContextGauge/ContextGaugePopup.svelte b/ui/apps/chat/src/lib/components/app/chat/ChatForm/ChatFormContextGauge/ContextGaugePanel.svelte
similarity index 59%
rename from ui/apps/chat/src/lib/components/app/chat/ChatForm/ChatFormContextGauge/ContextGaugePopup.svelte
rename to ui/apps/chat/src/lib/components/app/chat/ChatForm/ChatFormContextGauge/ContextGaugePanel.svelte
index fbd645720..5a0501947 100644
--- a/ui/apps/chat/src/lib/components/app/chat/ChatForm/ChatFormContextGauge/ContextGaugePopup.svelte
+++ b/ui/apps/chat/src/lib/components/app/chat/ChatForm/ChatFormContextGauge/ContextGaugePanel.svelte
@@ -2,54 +2,29 @@
 	import { colorLevelBgClass, colorLevelTextClass } from './context-gauge';
 	import ContextGaugeDetails from './ContextGaugeDetails.svelte';
 	import ContextGaugeLoadModel from './ContextGaugeLoadModel.svelte';
-	import {
-		gaugeCardEnter,
-		gaugeCardLeave,
-		gaugePopup,
-		gaugePopupClose
-	} from './gauge-popup.svelte';
+	import { gaugePopupClose } from './gauge-popup.svelte';
 	import { Button } from '@ggml-org/llama-ui/ui/button';
-	import * as Drawer from '@ggml-org/llama-ui/ui/drawer';
 	import { FoldVertical, Loader2 } from '@lucide/svelte';
 	import { useContextGauge } from '#lib/hooks/use-context-gauge.svelte.ts';
-	import { agenticStore, chatStore, conversationsStore, deviceStore } from '#lib/stores/index.ts';
+	import { agenticStore, chatStore, conversationsStore } from '#lib/stores/index.ts';
 	import { formatParameters } from '#lib/utils/formatters.ts';

+	interface Props {
+		/** The drawer brings its own title, so the panel drops the inline one there. */
+		inDrawer?: boolean;
+	}
+
+	let { inDrawer = false }: Props = $props();
+
 	const gauge = useContextGauge();

 	// The gauge hook wraps a processing state instance that only follows the
-	// live stream while its own monitoring flag is set, so the card instance
+	// live stream while its own monitoring flag is set, so the panel instance
 	// starts monitoring like the dial does.
 	$effect(() => {
 		gauge.startMonitoring();
 	});

-	let cardEl = $state<HTMLElement | null>(null);
-
-	// Any press outside the card and outside the dial closes the card.
-	// Presses on the dial are excluded because the dial handles its own
-	// toggle; the listener only exists while the card is open. A phone shows
-	// the panel in a drawer instead, which brings its own dismissal.
-	$effect(() => {
-		if (!gaugePopup.open || deviceStore.isMobile) return;
-
-		const onPointerDown = (event: PointerEvent) => {
-			const target = event.target;
-
-			if (!(target instanceof Node)) return;
-
-			if (cardEl?.contains(target)) return;
-
-			if (target instanceof Element && target.closest('[data-context-gauge-trigger]')) return;
-
-			gaugePopupClose();
-		};
-
-		document.addEventListener('pointerdown', onPointerDown, true);
-
-		return () => document.removeEventListener('pointerdown', onPointerDown, true);
-	});
-
 	const showProgressBar = $derived(
 		gauge.contextTotal !== null &&
 			gauge.contextTotal > 0 &&
@@ -60,7 +35,7 @@

 	const activeConvId = $derived(conversationsStore.activeConversation?.id ?? null);

-	// A summary in flight keeps the card open for the numbers, so the action
+	// A summary in flight keeps the panel open for the numbers, so the action
 	// reports the run instead of inviting a second one.
 	const isCompacting = $derived(activeConvId !== null && chatStore.isCompacting(activeConvId));

@@ -149,47 +124,20 @@
 	{/if}
 {/snippet}

-{#if deviceStore.isMobile}
-	<Drawer.Root bind:open={gaugePopup.open}>
-		<Drawer.Content>
-			<Drawer.Header>
-				<Drawer.Title>Context</Drawer.Title>
-
-				<Drawer.Description class="sr-only">
-					Context window usage of the model the chat runs
-				</Drawer.Description>
-			</Drawer.Header>
-
-			<div class="flex flex-col gap-2 px-4 pb-4 max-md:gap-3.5">
-				{@render usage()}
-
-				{@render body()}
-
-				{@render compactAction()}
-			</div>
-		</Drawer.Content>
-	</Drawer.Root>
-{:else if gaugePopup.open}
-	<div
-		bind:this={cardEl}
-		class="absolute z-50 w-64 -translate-x-1/2 rounded-xl border matte-float p-1.5 text-body-sm"
-		onpointerenter={gaugeCardEnter}
-		onpointerleave={gaugeCardLeave}
-		role="status"
-		style="left: {gaugePopup.centerX}px; bottom: {gaugePopup.bottom}px"
-	>
-		<div class="flex flex-col gap-2 px-2 py-1.5">
-			<div class="flex items-center gap-2">
-				<span class="font-medium">Context</span>
-
-				<span class="text-muted-foreground">·</span>
-
-				{@render usage()}
-			</div>
-
-			{@render body()}
-
-			{@render compactAction()}
+<div class={['flex flex-col gap-2', inDrawer ? 'px-4 pb-4 max-md:gap-3.5' : 'px-2 py-1.5']}>
+	{#if inDrawer}
+		{@render usage()}
+	{:else}
+		<div class="flex items-center gap-2">
+			<span class="font-medium">Context</span>
+
+			<span class="text-muted-foreground">·</span>
+
+			{@render usage()}
 		</div>
-	</div>
-{/if}
+	{/if}
+
+	{@render body()}
+
+	{@render compactAction()}
+</div>
diff --git a/ui/apps/chat/src/lib/components/app/chat/ChatForm/ChatFormContextGauge/gauge-popup.svelte.ts b/ui/apps/chat/src/lib/components/app/chat/ChatForm/ChatFormContextGauge/gauge-popup.svelte.ts
index 4885326fb..9e2f50cd9 100644
--- a/ui/apps/chat/src/lib/components/app/chat/ChatForm/ChatFormContextGauge/gauge-popup.svelte.ts
+++ b/ui/apps/chat/src/lib/components/app/chat/ChatForm/ChatFormContextGauge/gauge-popup.svelte.ts
@@ -1,99 +1,11 @@
-// Shared state for the context gauge popup. The dial and the card live in
-// different DOM subtrees, so open state and placement are coordinated here.
-// centerX and bottom place the card just above the dial: both are measured
-// once at open time, relative to the closest form ancestor; the dial and
-// the card share that positioning frame, so the values stay exact for the
-// whole time the card is open.
-// Mouse pointers open on hover with a short grace delay to travel from
-// dial to card; touch pointers toggle on tap.
-import {
-	CONTEXT_GAUGE_CARD_HALF_WIDTH_PX,
-	CONTEXT_GAUGE_CLOSE_GRACE_MS,
-	CONTEXT_GAUGE_DIAL_GAP_PX,
-	CONTEXT_GAUGE_EDGE_MARGIN_PX
-} from '#lib/constants/index.ts';
+// Open state of the context panel, shared by the gauge's popover and the phone's drawer: the
+// phone's corner key and the drawer live in different DOM subtrees.
+export const gaugePopup = $state({ open: false });

-let closeTimer: ReturnType<typeof setTimeout> | undefined;
-let lastPointerType = '';
-
-export const gaugePopup = $state({ bottom: 0, centerX: 0, open: false });
-
-function openFrom(trigger: HTMLElement): void {
-	clearTimeout(closeTimer);
-	const frame = trigger.closest('form');
-
-	if (frame) {
-		const frameRect = frame.getBoundingClientRect();
-		const triggerRect = trigger.getBoundingClientRect();
-		const centerX = triggerRect.left + triggerRect.width / 2 - frameRect.left;
-		const min = CONTEXT_GAUGE_CARD_HALF_WIDTH_PX + CONTEXT_GAUGE_EDGE_MARGIN_PX;
-		const max = frameRect.width - CONTEXT_GAUGE_CARD_HALF_WIDTH_PX - CONTEXT_GAUGE_EDGE_MARGIN_PX;
-
-		gaugePopup.centerX = Math.min(Math.max(centerX, min), Math.max(min, max));
-		gaugePopup.bottom = frameRect.bottom - triggerRect.top + CONTEXT_GAUGE_DIAL_GAP_PX;
-	}
-
-	gaugePopup.open = true;
-}
-
-function toggleFrom(trigger: HTMLElement): void {
-	if (gaugePopup.open) {
-		clearTimeout(closeTimer);
-		gaugePopup.open = false;
-	} else {
-		openFrom(trigger);
-	}
+export function gaugePopupToggle(): void {
+	gaugePopup.open = !gaugePopup.open;
 }

 export function gaugePopupClose(): void {
-	clearTimeout(closeTimer);
 	gaugePopup.open = false;
 }
-
-export function gaugeTriggerPointerDown(event: PointerEvent): void {
-	lastPointerType = event.pointerType;
-}
-
-export function gaugeTriggerClick(event: MouseEvent): void {
-	if (lastPointerType !== 'touch') return;
-
-	toggleFrom(event.currentTarget as HTMLElement);
-}
-
-export function gaugeTriggerKeydown(event: KeyboardEvent): void {
-	if (event.key !== 'Enter' && event.key !== ' ') return;
-
-	event.preventDefault();
-	toggleFrom(event.currentTarget as HTMLElement);
-}
-
-export function gaugeTriggerEnter(event: PointerEvent): void {
-	if (event.pointerType !== 'mouse') return;
-
-	openFrom(event.currentTarget as HTMLElement);
-}
-
-export function gaugeTriggerLeave(event: PointerEvent): void {
-	if (event.pointerType !== 'mouse') return;
-
-	scheduleClose();
-}
-
-export function gaugeCardEnter(event: PointerEvent): void {
-	if (event.pointerType !== 'mouse') return;
-
-	clearTimeout(closeTimer);
-}
-
-export function gaugeCardLeave(event: PointerEvent): void {
-	if (event.pointerType !== 'mouse') return;
-
-	scheduleClose();
-}
-
-function scheduleClose(): void {
-	clearTimeout(closeTimer);
-	closeTimer = setTimeout(() => {
-		gaugePopup.open = false;
-	}, CONTEXT_GAUGE_CLOSE_GRACE_MS);
-}
diff --git a/ui/apps/chat/src/lib/constants/context-gauge-popup.constants.ts b/ui/apps/chat/src/lib/constants/context-gauge-popup.constants.ts
deleted file mode 100644
index fe2e6a1b5..000000000
--- a/ui/apps/chat/src/lib/constants/context-gauge-popup.constants.ts
+++ /dev/null
@@ -1,8 +0,0 @@
-// Half of the card width, matching the w-64 class on the card.
-export const CONTEXT_GAUGE_CARD_HALF_WIDTH_PX = 128;
-// Minimum distance kept between the card and the form edges.
-export const CONTEXT_GAUGE_EDGE_MARGIN_PX = 8;
-// Gap between the top of the dial and the bottom edge of the card.
-export const CONTEXT_GAUGE_DIAL_GAP_PX = 8;
-// Grace delay before closing, letting the pointer travel from dial to card.
-export const CONTEXT_GAUGE_CLOSE_GRACE_MS = 150;
diff --git a/ui/apps/chat/src/lib/constants/index.ts b/ui/apps/chat/src/lib/constants/index.ts
index 6f6ac5a10..399e75ac7 100644
--- a/ui/apps/chat/src/lib/constants/index.ts
+++ b/ui/apps/chat/src/lib/constants/index.ts
@@ -14,7 +14,6 @@ export * from './icons.constants';
 export * from './attachment-menu.constants';
 export * from './auto-scroll.constants';
 export * from './context-gauge-dial.constants';
-export * from './context-gauge-popup.constants';
 export * from './conversation-import.constants';
 export * from './conversation-search.constants';
 export * from './binary-detection.constants';
diff --git a/ui/apps/chat/tests/client/context-panel-mobile.svelte.test.ts b/ui/apps/chat/tests/client/context-panel-mobile.svelte.test.ts
deleted file mode 100644
index 5e385dc46..000000000
--- a/ui/apps/chat/tests/client/context-panel-mobile.svelte.test.ts
+++ /dev/null
@@ -1,42 +0,0 @@
-// Guards the phone shape of the context panel: a phone shows it in a drawer, while a
-// wider screen keeps the card anchored above the dial.
-
-import ContextGaugePopup from '#lib/components/app/chat/ChatForm/ChatFormContextGauge/ContextGaugePopup.svelte';
-import { gaugePopup } from '#lib/components/app/chat/ChatForm/ChatFormContextGauge/gauge-popup.svelte.ts';
-import { afterEach, beforeEach, describe, expect, it } from 'vitest';
-import { page } from 'vitest/browser';
-import { render } from 'vitest-browser-svelte';
-
-const PHONE = { height: 844, width: 390 };
-const DESKTOP = { height: 900, width: 1280 };
-
-describe('context panel on a phone', () => {
-	beforeEach(async () => {
-		gaugePopup.open = false;
-	});
-
-	afterEach(async () => {
-		gaugePopup.open = false;
-		await page.viewport(DESKTOP.width, DESKTOP.height);
-	});
-
-	it('shows the panel in a drawer', async () => {
-		await page.viewport(PHONE.width, PHONE.height);
-
-		const screen = render(ContextGaugePopup);
-
-		gaugePopup.open = true;
-
-		await expect.element(screen.getByRole('heading', { name: 'Context' })).toBeVisible();
-	});
-
-	it('keeps the anchored card on a wider screen', async () => {
-		await page.viewport(DESKTOP.width, DESKTOP.height);
-
-		const screen = render(ContextGaugePopup);
-
-		gaugePopup.open = true;
-
-		await expect.element(screen.getByRole('status')).toBeVisible();
-	});
-});
diff --git a/ui/apps/chat/tests/client/context-panel.svelte.test.ts b/ui/apps/chat/tests/client/context-panel.svelte.test.ts
new file mode 100644
index 000000000..d9c46b6e4
--- /dev/null
+++ b/ui/apps/chat/tests/client/context-panel.svelte.test.ts
@@ -0,0 +1,62 @@
+// Guards how the context panel opens: a phone shows it in a drawer, while a wider screen opens a
+// popover from the gauge on click (not on hover) and closes it on Escape or a click outside.
+
+import ChatFormContextGauge from '#lib/components/app/chat/ChatForm/ChatFormContextGauge/ChatFormContextGauge.svelte';
+import ContextGaugeDrawer from '#lib/components/app/chat/ChatForm/ChatFormContextGauge/ContextGaugeDrawer.svelte';
+import { gaugePopup } from '#lib/components/app/chat/ChatForm/ChatFormContextGauge/gauge-popup.svelte.ts';
+import { afterEach, beforeEach, describe, expect, it } from 'vitest';
+import { page, userEvent } from 'vitest/browser';
+import { render } from 'vitest-browser-svelte';
+
+const PHONE = { height: 844, width: 390 };
+const DESKTOP = { height: 900, width: 1280 };
+
+describe('context panel', () => {
+	beforeEach(async () => {
+		gaugePopup.open = false;
+	});
+
+	afterEach(async () => {
+		gaugePopup.open = false;
+		await page.viewport(DESKTOP.width, DESKTOP.height);
+	});
+
+	it('shows the panel in a drawer on a phone', async () => {
+		await page.viewport(PHONE.width, PHONE.height);
+
+		const screen = render(ContextGaugeDrawer);
+
+		gaugePopup.open = true;
+
+		await expect.element(screen.getByRole('heading', { name: 'Context' })).toBeVisible();
+	});
+
+	it('opens the popover on click, not on hover, on a wider screen', async () => {
+		await page.viewport(DESKTOP.width, DESKTOP.height);
+
+		render(ChatFormContextGauge);
+
+		const trigger = page.getByRole('button', { name: 'Context usage' });
+
+		await trigger.hover();
+		expect(gaugePopup.open).toBe(false);
+
+		await trigger.click();
+		await expect.element(page.getByRole('dialog')).toBeVisible();
+
+		await userEvent.keyboard('{Escape}');
+		await expect.poll(() => gaugePopup.open).toBe(false);
+	});
+
+	it('closes the popover on a click outside', async () => {
+		await page.viewport(DESKTOP.width, DESKTOP.height);
+
+		render(ChatFormContextGauge);
+
+		await page.getByRole('button', { name: 'Context usage' }).click();
+		await expect.element(page.getByRole('dialog')).toBeVisible();
+
+		await userEvent.click(document.body, { position: { x: 5, y: 5 } });
+		await expect.poll(() => gaugePopup.open).toBe(false);
+	});
+});
diff --git a/ui/apps/chat/tests/stories/chat/form/ChatFormContextGauge.stories.svelte b/ui/apps/chat/tests/stories/chat/form/ChatFormContextGauge.stories.svelte
index a0416fd5d..b5939a48e 100644
--- a/ui/apps/chat/tests/stories/chat/form/ChatFormContextGauge.stories.svelte
+++ b/ui/apps/chat/tests/stories/chat/form/ChatFormContextGauge.stories.svelte
@@ -10,8 +10,9 @@
 	} from './fixtures';
 	import { defineMeta } from '@storybook/addon-svelte-csf';
 	import ChatFormContextGauge from '#lib/components/app/chat/ChatForm/ChatFormContextGauge/ChatFormContextGauge.svelte';
-	import ContextGaugePopup from '#lib/components/app/chat/ChatForm/ChatFormContextGauge/ContextGaugePopup.svelte';
+	import ContextGaugeDrawer from '#lib/components/app/chat/ChatForm/ChatFormContextGauge/ContextGaugeDrawer.svelte';
 	import { gaugePopupClose } from '#lib/components/app/chat/ChatForm/ChatFormContextGauge/gauge-popup.svelte.ts';
+	import { deviceStore } from '#lib/stores/index.ts';
 	import { userEvent, within } from 'storybook/test';

 	const { Story } = defineMeta({
@@ -24,7 +25,7 @@

 	const N_CTX = 32768;

-	// the popup state is module-wide, so close it around each story
+	// the open state is module-wide, so close it around each story
 	function seedUsage(promptTokens: number) {
 		return () => {
 			gaugePopupClose();
@@ -67,21 +68,22 @@
 		};
 	}

+	// the popover renders in a portal, so it is looked up on the whole page
 	async function openPopup({ canvasElement }: { canvasElement: HTMLElement }) {
-		const canvas = within(canvasElement);
-
-		canvas.getByRole('button', { name: 'Context usage' }).focus();
-		await userEvent.keyboard('{Enter}');
-		await canvas.findByRole('status');
+		await userEvent.click(within(canvasElement).getByRole('button', { name: 'Context usage' }));
+		await within(document.body).findByRole('dialog');
 	}
 </script>

 {#snippet frame()}
-	<!-- the popup positions itself against the closest form -->
+	<!-- room above the form for the popover -->
 	<form class="relative mt-96 flex w-80 justify-end rounded-3xl border p-3">
 		<ChatFormContextGauge />

-		<ContextGaugePopup />
+		<!-- a phone opens the panel in the drawer the chat form renders -->
+		{#if deviceStore.isMobile}
+			<ContextGaugeDrawer />
+		{/if}
 	</form>
 {/snippet}