fix(editor): focus margin on the strip's targets, not a page padding

This commit is contained in:
bchanot committed 2026-11-19 12:24:34 +01:00
1 parent f2809f20ca
commit 399a5adae6
3 files changed
+84 -10

No files matched your search

@@ -18,6 +18,7 @@ import {
seedDraft, seedDraft,
selectionTag, selectionTag,
selectTab, selectTab,
annotationList,
serverDocument, serverDocument,
shapeWith, shapeWith,
standardShape, standardShape,
@@ -573,6 +574,9 @@ const VIEWPORTS = [
] ]
/** Enough annotations for the overview to grow the page well past one screen. */ /** 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"])')
const manyPoints = () => const manyPoints = () =>
Array.from({ length: 14 }, (_, i) => Array.from({ length: 14 }, (_, i) =>
pointOf(`pt-${i}`, 'main', { cx: 100 + i * 40, cy: 100, r: 10 }, `Pt ${i}`), pointOf(`pt-${i}`, 'main', { cx: 100 + i * 40, cy: 100, r: 10 }, `Pt ${i}`),
@@ -682,5 +686,63 @@ for (const viewport of VIEWPORTS) {
}) })
expect((await stripGeometry(page)).scrollY).toBe(bottom) expect((await stripGeometry(page)).scrollY).toBe(bottom)
}) })
test('a focus never scrolls onto the bar or the strip, nor lands under them', async ({
page,
}) => {
await open(page, ...manyPoints())
await pickAnnotation(page, dict, 'Pt 0')
await page.evaluate(() => window.scrollTo(0, 300))
const before = (await stripGeometry(page)).scrollY
// The keyboard's focus move on the strip's command and on the bar's first control.
for (const target of [
page
.getByTestId('edit-strip')
.getByRole('button', { name: dict['editor.annotations.properties'] }),
topBar(page).getByRole('link').first(),
]) {
await target.focus()
expect(
(await stripGeometry(page)).scrollY,
'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)
await page.evaluate(
(el) => {
const top = el.getBoundingClientRect().top + window.scrollY
window.scrollTo(0, top - 100)
},
await row.elementHandle(),
)
await row.focus()
const now = await stripGeometry(page)
const top = (await row.boundingBox())!.y
expect(top, 'the focused row is below the strip').toBeGreaterThanOrEqual(
now.bottom,
)
})
test('with the strip hidden the scroll offset is not applied', async ({
page,
}) => {
await open(page, ...manyPoints())
const margin = () =>
page.evaluate(
() =>
getComputedStyle(
document.querySelector(
'[data-place="annotations.drawing"] [data-focus-key]',
)!,
).scrollMarginTop,
)
expect(parseFloat(await margin()), 'the strip is shown').toBeGreaterThan(
100,
)
await openSection(page, dict, 'categories')
await expect(page.getByTestId('edit-strip')).toBeHidden()
expect(await margin(), 'the strip is hidden').toBe('0px')
})
}) })
} }
+17 -8
View File
@@ -7,21 +7,30 @@ body,
height: 100%; height: 100%;
} }
/* The top bar's total height, read by the bar, by the editor strip's sticky top and by the /* The top bar's total height, read by the bar, by the editor strip's sticky top and by the
scroll padding: one place, so they can never drift apart. */ scroll margin below: one place, so they can never drift apart. */
:root { :root {
--shell-top-bar-height: calc(3.5rem + env(safe-area-inset-top, 0px)); --shell-top-bar-height: calc(3.5rem + env(safe-area-inset-top, 0px));
--edit-strip-height: 4rem; --edit-strip-height: 4rem;
} }
/* A focus or a scrollIntoView never lands a target under the bar, nor under the editor's /* A focus or a scrollIntoView never lands a target under the bar nor under the editor's
sticky strip (its height plus the gap below it, space-y-3). */ sticky strip (its height plus the gap below it, space-y-3). It is a margin on the
html { drawing place's focus targets, not a padding on the page: scroll-padding also pushed the
scroll-padding-top: calc(var(--shell-top-bar-height) + 0.75rem); page when the focus went to the sticky bar or strip themselves (probed, U2 Task 14), and a
} page-wide rule outlived a hidden strip. The place is `hidden` while another section
html:has([data-testid='edit-strip']) { shows, and the strip is sticky from 1 024 px only. */
scroll-padding-top: calc( @media (min-width: 1024px) {
[data-place='annotations.drawing']:not([hidden])
:is(
[data-focus-key],
[data-vertex],
[data-testid='point-handle'],
[role='group'][tabindex='0']
) {
scroll-margin-top: calc(
var(--shell-top-bar-height) + var(--edit-strip-height) + 1.5rem var(--shell-top-bar-height) + var(--edit-strip-height) + 1.5rem
); );
} }
}
/* A modal dialog is open (components/ui/ModalDialog): the page behind it does not scroll. */ /* A modal dialog is open (components/ui/ModalDialog): the page behind it does not scroll. */
html:has(dialog:modal) { html:has(dialog:modal) {
overflow: hidden; overflow: hidden;
+5 -2
View File
@@ -229,8 +229,11 @@ The edit strip (U2 Task 14) stays under the shell's top bar from 1 024 px: it is
`sticky` at `top: var(--shell-top-bar-height)`, opaque, with a z-index of 5 (above the `sticky` at `top: var(--shell-top-bar-height)`, opaque, with a z-index of 5 (above the
drawing, under the loupe, the menus, the bar and the dialogs), and no ancestor sets an 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 `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 the strip's (`--edit-strip-height`) are CSS variables of `styles/index.css`, which also feed a
document's `scroll-padding-top`, so a focus or a `scrollIntoView` never lands under either. `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
`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. Below 1 024 px the strip is not sticky.
A creation (U2 Task 7, A2, A4, A12) is drawn by the overlay too, never by the A creation (U2 Task 7, A2, A4, A12) is drawn by the overlay too, never by the