diff --git a/apps/app/e2e/shell/editor-geometry.spec.ts b/apps/app/e2e/shell/editor-geometry.spec.ts index 8ed12f1b..2ccec787 100644 --- a/apps/app/e2e/shell/editor-geometry.spec.ts +++ b/apps/app/e2e/shell/editor-geometry.spec.ts @@ -573,10 +573,10 @@ const VIEWPORTS = [ { width: 1280, height: 800 }, ] -/** Enough annotations for the overview to grow the page well past one screen. */ const topBar = (page: Page) => page.locator('header:has([data-testid="topbar-account"])') +/** Enough annotations for the overview to grow the page well past one screen. */ const manyPoints = () => Array.from({ length: 14 }, (_, i) => pointOf(`pt-${i}`, 'main', { cx: 100 + i * 40, cy: 100, r: 10 }, `Pt ${i}`), @@ -707,8 +707,13 @@ for (const viewport of VIEWPORTS) { 'focus on sticky chrome', ).toBe(before) } - // A row hidden under the strip comes out below it, not under it. - const row = annotationList(page, dict).getByRole('button').nth(4) + // A row hidden under the strip comes out below it, not under it. The row sits low in the + // page: a short window lets the page scroll far enough to put it under the strip. + await page.setViewportSize({ + width: page.viewportSize()!.width, + height: 400, + }) + const row = annotationList(page, dict).getByRole('button').first() await page.evaluate( (el) => { const top = el.getBoundingClientRect().top + window.scrollY @@ -716,6 +721,11 @@ for (const viewport of VIEWPORTS) { }, await row.elementHandle(), ) + const hidden = await stripGeometry(page) + expect( + (await row.boundingBox())!.y, + 'precondition: the row starts under the strip', + ).toBeLessThan(hidden.bottom) await row.focus() const now = await stripGeometry(page) const top = (await row.boundingBox())!.y @@ -724,6 +734,43 @@ for (const viewport of VIEWPORTS) { ) }) + test('a vertex handle (SVG) focused under the strip ends below it', async ({ + page, + }) => { + await open(page, ...manyPoints(), { + ...pointOf('zone-v', 'main', { cx: 0, cy: 0, r: 1 }, 'Zone V'), + kind: 'zone', + geometry: { + type: 'polygon', + points: [ + [300, 200], + [600, 200], + [600, 500], + [300, 500], + ], + }, + }) + await pickAnnotation(page, dict, 'Zone V') + const vertex = page.locator('[data-vertex="0"]') + await expect(vertex).toBeVisible() + await page.evaluate(() => { + const el = document.querySelector('[data-vertex="0"]')! + window.scrollTo(0, el.getBoundingClientRect().top + window.scrollY - 80) + }) + const strip = await stripGeometry(page) + const before = (await vertex.boundingBox())! + expect( + before.y, + 'precondition: the handle starts under the strip', + ).toBeLessThan(strip.bottom) + await vertex.focus() + const after = (await vertex.boundingBox())! + expect( + after.y, + 'the focused handle is below the strip', + ).toBeGreaterThanOrEqual((await stripGeometry(page)).bottom) + }) + test('with the strip hidden the scroll offset is not applied', async ({ page, }) => { diff --git a/apps/app/src/components/editor/annotations/HandleLayer.tsx b/apps/app/src/components/editor/annotations/HandleLayer.tsx index 5b1f6e02..760e5179 100644 --- a/apps/app/src/components/editor/annotations/HandleLayer.tsx +++ b/apps/app/src/components/editor/annotations/HandleLayer.tsx @@ -169,6 +169,7 @@ function PointHandleShape({ data-testid="point-handle" // Its arrow series commits on blur; the drawing guard sends it that blur (focus kept). data-series="" + data-focus-target="" className="group outline-none" onKeyDown={onKeyDown} onBlur={onBlur} diff --git a/apps/app/src/components/editor/annotations/ZoneHandles.tsx b/apps/app/src/components/editor/annotations/ZoneHandles.tsx index 465eaaaa..6f4ba5c0 100644 --- a/apps/app/src/components/editor/annotations/ZoneHandles.tsx +++ b/apps/app/src/components/editor/annotations/ZoneHandles.tsx @@ -80,6 +80,7 @@ function Insert({ role="button" tabIndex={0} aria-label={label} + data-focus-target="" className="group outline-none" onKeyDown={onKeyDown} > @@ -138,6 +139,7 @@ function Vertex({ data-vertex={index} // Its arrow series commits on blur; the drawing guard sends it that blur (focus kept). data-series="" + data-focus-target="" className="group outline-none" onKeyDown={(event) => keys.onVertexKey(index, event)} onFocus={() => keys.onVertexFocus(index)} @@ -204,6 +206,7 @@ function Remove({ tabIndex={0} aria-label={label} aria-disabled={disabled} + data-focus-target="" className="group outline-none" onKeyDown={onKeyDown} > diff --git a/apps/app/src/styles/index.css b/apps/app/src/styles/index.css index e3e3eaad..b1b910da 100644 --- a/apps/app/src/styles/index.css +++ b/apps/app/src/styles/index.css @@ -20,12 +20,7 @@ body, shows, and the strip is sticky from 1 024 px only. */ @media (min-width: 1024px) { [data-place='annotations.drawing']:not([hidden]) - :is( - [data-focus-key], - [data-vertex], - [data-testid='point-handle'], - [role='group'][tabindex='0'] - ) { + :is([data-focus-key], [data-focus-target], [role='group'][tabindex='0']) { scroll-margin-top: calc( var(--shell-top-bar-height) + var(--edit-strip-height) + 1.5rem ); diff --git a/docs/ANNOTATION-RENDERING.md b/docs/ANNOTATION-RENDERING.md index 2a93acdd..ee790140 100644 --- a/docs/ANNOTATION-RENDERING.md +++ b/docs/ANNOTATION-RENDERING.md @@ -230,8 +230,8 @@ The edit strip (U2 Task 14) stays under the shell's top bar from 1 024 px: it is drawing, under the loupe, the menus, the bar and the dialogs), and no ancestor sets an `overflow` other than visible. The bar's height (3.5 rem plus the safe-area inset) and the strip's (`--edit-strip-height`) are CSS variables of `styles/index.css`, which also feed a -`scroll-margin-top` on the drawing place's focus targets (rows, vertex and point handles, the -canvas box), from 1 024 px and only while the place is not `hidden`, so a focus or a +`scroll-margin-top` on the drawing place's focus targets (rows, every focusable handle through +`data-focus-target`, the canvas box), from 1 024 px and only while the place is not `hidden`, so a focus or a `scrollIntoView` never lands under either. It is a margin, not a page `scroll-padding`: the padding made the page jump when the focus went to the sticky bar or strip themselves. Below 1 024 px the strip is not sticky.