fix(editor): focus margin on the strip's targets, not a page padding
This commit is contained in:
1 parent
f2809f20ca
commit
399a5adae6
3 files changed
+86
-12
No files matched your search
@@ -18,6 +18,7 @@ import {
|
||||
seedDraft,
|
||||
selectionTag,
|
||||
selectTab,
|
||||
annotationList,
|
||||
serverDocument,
|
||||
shapeWith,
|
||||
standardShape,
|
||||
@@ -573,6 +574,9 @@ const VIEWPORTS = [
|
||||
]
|
||||
|
||||
/** 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 = () =>
|
||||
Array.from({ length: 14 }, (_, 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)
|
||||
})
|
||||
|
||||
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')
|
||||
})
|
||||
})
|
||||
}
|
||||
Reference in new issue
Block a user