Skip to content

The all-in-one local AI studio for your desktop: chat, image and video generation and a coding agent in one free, open source app. Windows and Linux. No Docker, no terminal, no cloud required.

fix(ui): a dialog taller than the window scrolls, so every button stays in reach

purpleb4b87feb996a
diff --git a/e2e/cloud-gate-scrolls-in-a-low-window.spec.ts b/e2e/cloud-gate-scrolls-in-a-low-window.spec.ts
new file mode 100644
index 00000000..55b65fee
--- /dev/null
+++ b/e2e/cloud-gate-scrolls-in-a-low-window.spec.ts
@@ -0,0 +1,110 @@
+import { test, expect, type Locator, type Page } from '@playwright/test'
+import { tauriMockInit, DEFAULT_ASSISTANT_REPLY, DEFAULT_MODEL_NAME } from './support/tauri-mock'
+import { routeCloud, seedOnboardingDone, cloudSwitch } from './support/cloud-mock'
+
+/**
+ * A window 230 px high (a tiling window manager gives the app a strip): the
+ * cloud gate is taller than the window. The shared Modal centred its panel in
+ * an overlay that did not scroll, so the panel was cut off at both ends and
+ * "Sign in" lay below the window edge, out of reach.
+ *
+ * The overlay scrolls now. This spec walks the whole signed-out way through the
+ * gate in a 900x230 window with the mouse wheel and real clicks, and checks
+ * that Escape and the X still close it.
+ */
+
+const LOW = { width: 900, height: 230 }
+
+test.use({ viewport: LOW })
+
+/** Is the whole element inside the window? Visible pixels on both sides. */
+async function insideWindow(el: Locator): Promise<boolean> {
+ const box = await el.boundingBox()
+ if (!box) return false
+ return box.y >= 0 && box.y + box.height <= LOW.height && box.x >= 0 && box.x + box.width <= LOW.width
+}
+
+/** Turn the wheel over the dialog until the element is inside the window. */
+async function wheelTo(page: Page, el: Locator): Promise<void> {
+ await page.mouse.move(LOW.width / 2, LOW.height / 2)
+ for (let i = 0; i < 40 && !(await insideWindow(el)); i++) {
+ const box = await el.boundingBox()
+ await page.mouse.wheel(0, box && box.y < 0 ? -60 : 60)
+ await page.waitForTimeout(50)
+ }
+ expect(await insideWindow(el), 'the wheel never brought the element into the window').toBe(true)
+}
+
+async function openGate(page: Page) {
+ await page.addInitScript(tauriMockInit, {
+ assistantReply: DEFAULT_ASSISTANT_REPLY,
+ modelName: DEFAULT_MODEL_NAME,
+ })
+ await seedOnboardingDone(page)
+ await routeCloud(page, { license: 'none' })
+ await page.goto('/')
+ await expect(cloudSwitch(page)).toBeVisible({ timeout: 20_000 })
+ await cloudSwitch(page).click()
+ await expect(page.getByRole('dialog')).toBeVisible()
+}
+
+test('the gate is taller than a 230 px window, and every button is reached by scrolling', async ({ page }) => {
+ await openGate(page)
+
+ // The premise: the panel does not fit, and the way to the sign in form
+ // starts below the window edge.
+ const dialog = page.getByRole('dialog')
+ const panel = await dialog.boundingBox()
+ expect(panel!.height, 'the gate fits into the window, this spec tests nothing').toBeGreaterThan(LOW.height)
+ const toLogin = page.getByRole('button', { name: /Already subscribed\? Sign in/i })
+
+ // The top of the dialog is not cut off: the wheel brings the X into the
+ // window, and from up there the way to the sign in form is below the edge.
+ await wheelTo(page, dialog.locator('[data-dialog-close]'))
+ expect(await insideWindow(toLogin)).toBe(false)
+
+ await wheelTo(page, toLogin)
+ await toLogin.click()
+
+ // The sign in step. The form is filled from the keyboard, the button is
+ // reached with the wheel and pressed with a real click.
+ await page.getByPlaceholder('Email').fill('[email protected]')
+ await page.getByPlaceholder('Password').fill('e2e-password')
+ const signIn = page.getByRole('button', { name: /^Sign in$/i })
+ await wheelTo(page, signIn)
+ await signIn.click()
+
+ // The click arrived: the account has no plan, and the gate says so.
+ await expect(page.getByText(/no active plan/i)).toBeAttached({ timeout: 20_000 })
+ // The last button of that wall is reachable too.
+ const again = page.getByRole('button', { name: /I subscribed, check again/i })
+ await wheelTo(page, again)
+ await again.click({ trial: true })
+})
+
+test('Escape and the X close the gate in the low window, and Tab stays inside it', async ({ page }) => {
+ await openGate(page)
+ const dialog = page.getByRole('dialog')
+
+ // The focus trap: a dozen Tabs never leave the dialog, and a focused button
+ // further down is scrolled into the window.
+ for (let i = 0; i < 12; i++) {
+ await page.keyboard.press('Tab')
+ const inside = await page.evaluate(() => !!document.activeElement?.closest('[role="dialog"]'))
+ expect(inside, `Tab ${i + 1} left the dialog`).toBe(true)
+ const focused = page.locator(':focus')
+ const box = await focused.boundingBox()
+ expect(box!.y + box!.height, `Tab ${i + 1}: the focused control is below the window`).toBeLessThanOrEqual(LOW.height + 1)
+ expect(box!.y, `Tab ${i + 1}: the focused control is above the window`).toBeGreaterThanOrEqual(-1)
+ }
+
+ await page.keyboard.press('Escape')
+ await expect(dialog).toBeHidden()
+
+ await cloudSwitch(page).click()
+ await expect(dialog).toBeVisible()
+ const x = dialog.locator('[data-dialog-close]')
+ await wheelTo(page, x)
+ await x.click()
+ await expect(dialog).toBeHidden()
+})
diff --git a/src/components/ui/Modal.tsx b/src/components/ui/Modal.tsx
index 76fd2134..268cd1d3 100644
--- a/src/components/ui/Modal.tsx
+++ b/src/components/ui/Modal.tsx
@@ -1,6 +1,6 @@
import { motion, AnimatePresence } from 'framer-motion'
import { X } from 'lucide-react'
-import { useCallback, useEffect, useId, useRef, type ReactNode } from 'react'
+import { useCallback, useEffect, useId, useRef, type MouseEvent, type ReactNode } from 'react'
import {
FOCUSABLE_SELECTOR,
backgroundNodesToHide,
@@ -193,6 +193,21 @@ export function Modal({ open, onClose, title, children, hideHeader, maxWidth = '
</div>
)
const panelClass = `relative z-10 w-full outline-none ${panelRadius} ${panelPad} lu-elevated ` + maxWidth
+ // A window lower than the dialog (230 px in a tiling window manager) used to
+ // cut the panel off at both ends: the overlay centred it and did not scroll,
+ // so the buttons at the bottom could not be reached. The overlay scrolls now
+ // and the row inside it is at least as high as the overlay, so a dialog that
+ // fits is still centred and one that does not starts at the top and scrolls.
+ // Percentages only: viewport units do not follow the zoom on the app root
+ // (--ui-scale, see lib/popover-placement.ts). The panel itself does not
+ // clip, so a menu that reaches out of a dialog still shows.
+ const overlayClass = 'fixed inset-0 z-50 overflow-y-auto overscroll-contain'
+ const backdropClass = 'fixed inset-0 bg-black/60 backdrop-blur-sm'
+ const rowClass = 'relative flex min-h-full items-center justify-center p-4'
+ /** A click beside the panel closes, as the backdrop under it always did. */
+ const closeBeside = (e: MouseEvent<HTMLDivElement>) => {
+ if (e.target === e.currentTarget) onClose()
+ }
const dialogA11y = hasVisibleTitle
? { 'aria-labelledby': titleId }
: { 'aria-label': ariaLabel || title || 'Dialog' }
@@ -206,19 +221,21 @@ export function Modal({ open, onClose, title, children, hideHeader, maxWidth = '
<div
ref={overlayRef}
data-lu-dialog={open ? '' : undefined}
- className={open ? 'fixed inset-0 z-50 flex items-center justify-center p-4' : 'hidden'}
+ className={open ? overlayClass : 'hidden'}
>
- <div className="absolute inset-0 bg-black/60 backdrop-blur-sm" onClick={onClose} />
- <div
- ref={panelRef}
- role="dialog"
- aria-modal="true"
- {...dialogA11y}
- tabIndex={-1}
- className={panelClass}
- >
- {header}
- {children}
+ <div className={backdropClass} onClick={onClose} />
+ <div className={rowClass} onClick={closeBeside}>
+ <div
+ ref={panelRef}
+ role="dialog"
+ aria-modal="true"
+ {...dialogA11y}
+ tabIndex={-1}
+ className={panelClass}
+ >
+ {header}
+ {children}
+ </div>
</div>
</div>
)
@@ -230,27 +247,29 @@ export function Modal({ open, onClose, title, children, hideHeader, maxWidth = '
<motion.div
ref={overlayRef}
data-lu-dialog
- className="fixed inset-0 z-50 flex items-center justify-center p-4"
+ className={overlayClass}
initial={{ opacity: 0 }}
animate={{ opacity: 1 }}
exit={{ opacity: 0 }}
>
- <div className="absolute inset-0 bg-black/60 backdrop-blur-sm" onClick={onClose} />
- <motion.div
- ref={panelRef}
- role="dialog"
- aria-modal="true"
- {...dialogA11y}
- tabIndex={-1}
- className={panelClass}
- initial={{ scale: 0.9, opacity: 0 }}
- animate={{ scale: 1, opacity: 1 }}
- exit={{ scale: 0.9, opacity: 0 }}
- transition={SPRING_PANEL}
- >
- {header}
- {children}
- </motion.div>
+ <div className={backdropClass} onClick={onClose} />
+ <div className={rowClass} onClick={closeBeside}>
+ <motion.div
+ ref={panelRef}
+ role="dialog"
+ aria-modal="true"
+ {...dialogA11y}
+ tabIndex={-1}
+ className={panelClass}
+ initial={{ scale: 0.9, opacity: 0 }}
+ animate={{ scale: 1, opacity: 1 }}
+ exit={{ scale: 0.9, opacity: 0 }}
+ transition={SPRING_PANEL}
+ >
+ {header}
+ {children}
+ </motion.div>
+ </div>
</motion.div>
)}
</AnimatePresence>