diff --git a/apps/app/e2e/shell/editor-more-menu.spec.ts b/apps/app/e2e/shell/editor-more-menu.spec.ts
new file mode 100644
index 00000000..60ebac69
--- /dev/null
+++ b/apps/app/e2e/shell/editor-more-menu.spec.ts
@@ -0,0 +1,180 @@
+import { fr } from '@/i18n/fr'
+import type { Page, TestInfo } from '@playwright/test'
+import { stepUpAdmin } from '../support/admin'
+import {
+ expect,
+ expectAccessible,
+ expectNoHorizontalOverflow,
+ test,
+} from '../support/browser'
+import { dropLateReplays, routeToSandbox } from '../support/sandbox'
+import {
+ draftPath,
+ draftTitle,
+ editorActor,
+ pointOf,
+ seedDraft,
+ shapeWith,
+} from '../support/editor'
+import { signIn } from '../support/shell'
+
+// V1-2.6 R2F-7 (items 6, 7): « Plus » is an overlay that moves nothing, and the left
+// sidebar stays in view while the content scrolls.
+
+const dict = fr
+const isPhone = (info: TestInfo) => info.project.name === 'chromium-375'
+const seedShape = shapeWith(
+ pointOf('p1', 'main', { cx: 500, cy: 400, r: 40 }, 'Point un'),
+)
+
+async function openAt(page: Page, width: number, height = 800) {
+ const actor = await editorActor('fr')
+ const seed = await seedDraft(actor, { shape: seedShape })
+ await signIn(page, actor.account, dict)
+ await page.goto('/app/admin')
+ await stepUpAdmin(page, dict, actor.secret)
+ await page.setViewportSize({ width, height })
+ await page.goto(draftPath(seed.sheetId))
+ await expect(
+ page.getByRole('heading', { level: 1, name: draftTitle(dict) }),
+ ).toBeVisible()
+}
+
+const more = (page: Page) =>
+ page.getByRole('button', { name: dict['editor.tab.more'], exact: true })
+const list = (page: Page) => page.locator('#editor-tabs-more')
+
+/** The boxes that must not move when « Plus » opens: the row, the page below it, the document. */
+async function layout(page: Page) {
+ return page.evaluate(() => {
+ const row = document.querySelector('[data-editor-tabs]')!
+ const below = row.nextElementSibling
+ const box = (el: Element | null) => {
+ const r = el?.getBoundingClientRect()
+ return r && [r.x, r.y, r.width, r.height].map(Math.round)
+ }
+ const root = document.documentElement
+ return {
+ row: box(row),
+ below: box(below),
+ doc: [root.scrollWidth, root.scrollHeight],
+ }
+ })
+}
+
+test.describe('« Plus » dropdown', () => {
+ test.use({ locale: 'fr-FR', actionTimeout: 15_000 })
+ test.beforeEach(async ({ context }, info) => {
+ test.skip(isPhone(info), 'the widths are set by the tests themselves') // floor-guard: allow C16 phone width read-only, set by the tests
+ await routeToSandbox(context)
+ })
+ test.afterEach(async ({ context }) => {
+ await dropLateReplays(context)
+ })
+
+ for (const width of [375, 320]) {
+ test(`at ${width} px it overlays without moving anything, axe open`, async ({
+ page,
+ }) => {
+ await openAt(page, width)
+ await expect(more(page)).toBeVisible()
+ const closed = await layout(page)
+ await more(page).click()
+ await expect(list(page)).toBeVisible()
+ expect(await layout(page), 'boxes open vs closed').toEqual(closed)
+ const menu = await list(page).boundingBox()
+ expect(menu!.x).toBeGreaterThanOrEqual(0)
+ expect(menu!.x + menu!.width).toBeLessThanOrEqual(width)
+ await expectNoHorizontalOverflow(page, `« Plus » open at ${width} px`)
+ await expectAccessible(page, `« Plus » open at ${width} px`)
+ })
+ }
+
+ test('closes on a selection, outside tap and Escape, focus kept sane', async ({
+ page,
+ }) => {
+ await openAt(page, 375)
+ await more(page).click()
+ await page.keyboard.press('Escape')
+ await expect(list(page)).toHaveCount(0)
+ await expect(more(page)).toBeFocused()
+ await more(page).click()
+ await page
+ .getByRole('heading', { level: 1, name: draftTitle(dict) })
+ .click()
+ await expect(list(page)).toHaveCount(0)
+ await more(page).click()
+ await list(page)
+ .getByRole('button', { name: dict['editor.tab.findings'] })
+ .click()
+ await expect(list(page)).toHaveCount(0)
+ await expect(more(page)).toHaveAttribute('aria-expanded', 'false')
+ })
+})
+
+test.describe('the sidebar stays fixed', () => {
+ test.use({ locale: 'fr-FR', actionTimeout: 15_000 })
+ test.beforeEach(async ({ context }, info) => {
+ test.skip(isPhone(info), 'the widths are set by the tests themselves') // floor-guard: allow C16 sidebar needs a desktop width
+ await routeToSandbox(context)
+ })
+ test.afterEach(async ({ context }) => {
+ await dropLateReplays(context)
+ })
+
+ const firstLink = (page: Page) =>
+ page
+ .getByRole('navigation', { name: dict['shell.nav_label'] })
+ .getByRole('link')
+ .first()
+
+ async function expectInView(page: Page, state: string) {
+ const box = await firstLink(page).boundingBox()
+ const height = await page.evaluate(() => window.innerHeight)
+ expect(box!.y, `${state}: top`).toBeGreaterThanOrEqual(0)
+ expect(box!.y + box!.height, `${state}: bottom`).toBeLessThanOrEqual(height)
+ }
+
+ test('at 1280 px the editor sidebar stays while the page scrolls, no sideways scroll', async ({
+ page,
+ }) => {
+ await openAt(page, 1280)
+ await expectAccessible(page, 'the editor at 1280 px, top')
+ await page.evaluate(() => window.scrollTo(0, document.body.scrollHeight))
+ expect(await page.evaluate(() => window.scrollY)).toBeGreaterThan(0)
+ await expectInView(page, 'scrolled editor')
+ await expectNoHorizontalOverflow(page, 'the editor at 1280 px')
+ })
+
+ test('at 1280 x 500 the sidebar scrolls on its own', async ({ page }) => {
+ await openAt(page, 1280, 500)
+ const own = await page.evaluate(() => {
+ const aside = document.querySelector('aside') as HTMLElement
+ aside.scrollTop = aside.scrollHeight
+ return {
+ scrolls: aside.scrollHeight > aside.clientHeight,
+ top: aside.scrollTop,
+ page: window.scrollY,
+ }
+ })
+ expect(own.scrolls).toBe(true)
+ expect(own.top).toBeGreaterThan(0)
+ expect(own.page).toBe(0)
+ })
+
+ test('at 1024 px the default shell sidebar stays while the page scrolls', async ({
+ page,
+ }) => {
+ await openAt(page, 1024)
+ await page.goto('/app')
+ await expect(firstLink(page)).toBeVisible()
+ await expectAccessible(page, 'the dashboard at 1024 px, top')
+ await page.evaluate(() => {
+ document.querySelector('main')!.style.minHeight = '3000px'
+ window.scrollTo(0, 1000)
+ })
+ expect(await page.evaluate(() => window.scrollY)).toBeGreaterThan(0)
+ await expectInView(page, 'scrolled dashboard')
+ await expectNoHorizontalOverflow(page, 'the dashboard at 1024 px')
+ })
+})
diff --git a/apps/app/e2e/support/editor.ts b/apps/app/e2e/support/editor.ts
index dc0dd084..8269ff32 100644
--- a/apps/app/e2e/support/editor.ts
+++ b/apps/app/e2e/support/editor.ts
@@ -417,6 +417,8 @@ export async function openTab(page: Page, dict: Dict, tab: string) {
.locator('#editor-tabs-more')
.getByRole('button', { name })
.click()
+ // The dropdown fades out: wait for it to be gone before the next move.
+ await expect(page.locator('#editor-tabs-more')).toHaveCount(0)
} else {
await page.getByRole('tab', { name }).click()
}
diff --git a/apps/app/src/components/editor/EditorTabs.tsx b/apps/app/src/components/editor/EditorTabs.tsx
index cc586f5f..85a485d2 100644
--- a/apps/app/src/components/editor/EditorTabs.tsx
+++ b/apps/app/src/components/editor/EditorTabs.tsx
@@ -1,6 +1,10 @@
-import { useEffect, useRef, useState, type KeyboardEvent } from 'react'
-import { inWorkspace } from '@/editor/annotations/deselect'
-import { isTextField } from '@/editor/focusRequest'
+import type { KeyboardEvent } from 'react'
+import {
+ AnimatePresence,
+ motion,
+ useIsPresent,
+ useReducedMotion,
+} from 'motion/react'
import { useEditorStore } from '@/editor/state/editorStore'
import { usePlural } from '@/editor/plural'
import {
@@ -13,6 +17,7 @@ import {
import type { TabTier } from '@/editor/useViewport'
import { useT } from '@/i18n/useT'
import HistoryButtons from './HistoryButtons'
+import { MORE_LIST_ID, useMoreDismiss, useMoreMenu } from './useMoreMenu'
const BASE =
'min-h-11 whitespace-nowrap border-b-2 px-3 text-sm focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--color-accent)]'
@@ -99,71 +104,73 @@ interface MoreTabsProps {
onSelect: SelectTab
}
-/**
- * While « Plus » is open, Escape closes it and returns the focus to it. Captured on the
- * document so the key is marked handled before any body's deselection sees it; a modal
- * dialog keeps its own Escape.
- */
-function useMoreEscape(open: boolean, close: () => void) {
- const closeRef = useRef(close)
- closeRef.current = close
- useEffect(() => {
- if (!open) return
- const onKey = (event: globalThis.KeyboardEvent) => {
- if (event.key !== 'Escape' || event.isComposing) return
- if (document.querySelector('dialog[open]')) return
- if (isTextField(event.target) || !inWorkspace(event.target)) return
- event.preventDefault()
- closeRef.current()
- document.getElementById(MORE_BUTTON_ID)?.focus()
- }
- document.addEventListener('keydown', onKey, true)
- return () => document.removeEventListener('keydown', onKey, true)
- }, [open])
+interface MoreListProps {
+ more: readonly EditorTabId[]
+ active: EditorTabId
+ onPick: (tab: EditorTabId) => void
}
-/** Below 640 px: « Plus » and its disclosure of the tabs that do not fit. */
+/** The overlay list: a closing list is inert, so nothing in it takes focus or a tap. */
+function MoreList({ more, active, onPick }: MoreListProps) {
+ const t = useT()
+ const reduced = useReducedMotion()
+ const present = useIsPresent()
+ const hidden = { opacity: 0, y: reduced ? 0 : -4 }
+ return (
+
+ {more.map((tab) => (
+
+
+
+ ))}
+
+ )
+}
+
+/** Below 640 px: « Plus » and its dropdown of the tabs that do not fit. */
function MoreTabs({ more, active, onSelect }: MoreTabsProps) {
const t = useT()
- const [open, setOpen] = useState(false)
+ const { open, close, toggle } = useMoreMenu(active)
const pick = (tab: EditorTabId) => {
onSelect(tab)
- setOpen(false)
+ close()
}
- useMoreEscape(open, () => setOpen(false))
+ useMoreDismiss(open, close)
return (
<>
- {open && (
-
- {more.map((tab) => (
-
-
-
- ))}
-
- )}
+
+ {open && }
+
>
)
}
@@ -177,7 +184,7 @@ interface EditorTabsProps {
/**
* The draft's tab row (boards 04 and 05): the five tabs from 640 px (the row may wrap
* between 640 and 1 023 px, never scroll sideways), Annotations and
- * Vérification below it with « Plus » opening a disclosure of the others (no measurement).
+ * Vérification below it with « Plus » opening a dropdown overlay of the others (no measurement).
* « Défaire » and « Refaire » sit at the right end of the row on every tab.
*/
export default function EditorTabs({
@@ -187,7 +194,10 @@ export default function EditorTabs({
}: EditorTabsProps) {
const { shown, more } = tabsFor(tier)
return (
-
+
{more.length > 0 && (
diff --git a/apps/app/src/components/editor/useMoreMenu.ts b/apps/app/src/components/editor/useMoreMenu.ts
new file mode 100644
index 00000000..5b936e8b
--- /dev/null
+++ b/apps/app/src/components/editor/useMoreMenu.ts
@@ -0,0 +1,111 @@
+import { useCallback, useEffect, useState } from 'react'
+import { inWorkspace } from '@/editor/annotations/deselect'
+import { isTextField } from '@/editor/focusRequest'
+import { MORE_BUTTON_ID, type EditorTabId } from '@/editor/tabs'
+
+export const MORE_LIST_ID = 'editor-tabs-more'
+const ROW_MARK = '[data-editor-tabs]'
+const MENU_PARTS = `#${MORE_LIST_ID}, #${MORE_BUTTON_ID}`
+/** A closing tap's click follows within this delay or never comes (a drag). */
+const SWALLOW_MS = 600
+
+/** The platform's back request (Android Back), where the browser offers it. */
+interface CloseWatcherLike {
+ onclose: (() => void) | null
+ destroy: () => void
+}
+type CloseWatcherCtor = new () => CloseWatcherLike
+
+const focusMore = () => document.getElementById(MORE_BUTTON_ID)?.focus()
+
+/**
+ * Open state of « Plus », closed by any change of the active tab (render-time reset, no
+ * effect).
+ */
+export function useMoreMenu(active: EditorTabId) {
+ const [open, setOpen] = useState(false)
+ const [seen, setSeen] = useState(active)
+ if (seen !== active) {
+ setSeen(active)
+ setOpen(false)
+ }
+ const close = useCallback(() => setOpen(false), [])
+ return { open, close, toggle: () => setOpen((value) => !value) }
+}
+
+/**
+ * While « Plus » is open, Escape closes it and returns the focus to it. Captured on the
+ * document so the key is marked handled before any body's deselection sees it; a modal
+ * dialog keeps its own Escape.
+ */
+function useMoreEscape(open: boolean, close: () => void) {
+ useEffect(() => {
+ if (!open) return
+ const onKey = (event: KeyboardEvent) => {
+ if (event.key !== 'Escape' || event.isComposing) return
+ if (document.querySelector('dialog[open]')) return
+ if (isTextField(event.target) || !inWorkspace(event.target)) return
+ event.preventDefault()
+ close()
+ focusMore()
+ }
+ document.addEventListener('keydown', onKey, true)
+ return () => document.removeEventListener('keydown', onKey, true)
+ }, [open, close])
+}
+
+/** Swallows the click that completes a closing tap, once, so the page never sees it. */
+function swallowNextClick() {
+ const stop = (event: Event) => {
+ event.stopPropagation()
+ event.preventDefault()
+ release()
+ }
+ const timer = window.setTimeout(() => release(), SWALLOW_MS)
+ const release = () => {
+ window.clearTimeout(timer)
+ document.removeEventListener('click', stop, true)
+ }
+ document.addEventListener('click', stop, true)
+}
+
+/**
+ * A press outside « Plus » closes it. Taps outside the tab row never reach the page (no
+ * deselection, no click); taps inside the row (a tab, Défaire) go on and act.
+ */
+function useOutsidePress(open: boolean, close: () => void) {
+ useEffect(() => {
+ if (!open) return
+ const onDown = (event: PointerEvent) => {
+ const target = event.target instanceof Element ? event.target : null
+ if (target?.closest(MENU_PARTS)) return
+ close()
+ if (target?.closest(ROW_MARK)) return
+ event.stopPropagation()
+ swallowNextClick()
+ }
+ document.addEventListener('pointerdown', onDown, true)
+ return () => document.removeEventListener('pointerdown', onDown, true)
+ }, [open, close])
+}
+
+/** The platform's back request closes the open menu before history goes back. */
+function useBackRequest(open: boolean, close: () => void) {
+ useEffect(() => {
+ const Ctor = (window as { CloseWatcher?: CloseWatcherCtor }).CloseWatcher
+ if (!open || !Ctor) return
+ const watcher = new Ctor()
+ watcher.onclose = () => {
+ close()
+ focusMore()
+ }
+ return () => watcher.destroy()
+ }, [open, close])
+}
+
+/** Every way « Plus » closes besides a selection and a tab change. */
+export function useMoreDismiss(open: boolean, close: () => void) {
+ useMoreEscape(open, close)
+ useOutsidePress(open, close)
+ useBackRequest(open, close)
+}
diff --git a/apps/app/src/components/shell/ShellChrome.tsx b/apps/app/src/components/shell/ShellChrome.tsx
index 2f94d8ff..05153de0 100644
--- a/apps/app/src/components/shell/ShellChrome.tsx
+++ b/apps/app/src/components/shell/ShellChrome.tsx
@@ -48,7 +48,7 @@ export function Sidebar({ shell }: { shell: ShellBreakpoint }) {
const t = useT()
return (