fix(editor): no focus in the drawing place lands under the strip
The scroll margin now covers every native focusable of the place (tools, view chips, add buttons, the aside's controls), the strip's own commands excepted, as a real Tab walk found them hidden (I-3). A vertex chosen from the keyboard takes the focus with a scroll (M-1).
This commit is contained in:
1 parent
59e189c375
commit
966ad4fe45
4 files changed
+159
-18
No files matched your search
@@ -606,6 +606,26 @@ function stripGeometry(page: Page) {
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* The focused element's top against the strip's bottom, while the focus is in the drawing
|
||||
* place and outside the strip (the strip's own commands never scroll the page).
|
||||
*/
|
||||
function focusedUnderStrip(page: Page) {
|
||||
return page.evaluate(() => {
|
||||
const active = document.activeElement as HTMLElement
|
||||
const strip = document.querySelector('[data-testid="edit-strip"]')!
|
||||
const inPlace =
|
||||
!!active.closest('[data-place="annotations.drawing"]') &&
|
||||
!strip.contains(active)
|
||||
return {
|
||||
inPlace,
|
||||
name: `${active.tagName} « ${(active.getAttribute('aria-label') ?? active.textContent ?? '').trim().slice(0, 30)} »`,
|
||||
top: active.getBoundingClientRect().top,
|
||||
stripBottom: strip.getBoundingClientRect().bottom,
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
for (const viewport of VIEWPORTS) {
|
||||
test.describe(`the strip under the top bar at ${viewport.width} px (U2 Task 14)`, () => {
|
||||
test.use({
|
||||
@@ -771,6 +791,80 @@ for (const viewport of VIEWPORTS) {
|
||||
).toBeGreaterThanOrEqual((await stripGeometry(page)).bottom)
|
||||
})
|
||||
|
||||
test("Tab and Shift+Tab onto the drawing place's native controls land below the strip", async ({
|
||||
page,
|
||||
}) => {
|
||||
await open(page, ...manyPoints())
|
||||
await pickAnnotation(page, dict, 'Pt 0')
|
||||
// A commit puts « Défaire » in the message line under the drawing.
|
||||
await page.getByTestId('point-handle').focus()
|
||||
await page.keyboard.press('ArrowRight')
|
||||
await page.keyboard.press('Enter')
|
||||
await expect(page.getByTestId('gesture-message')).toBeVisible()
|
||||
// Each walk starts on the canvas box, the page scrolled so the canvas top and the
|
||||
// aside's top sit under the strip; the focus starts there without a scroll.
|
||||
for (const key of ['Shift+Tab', 'Tab']) {
|
||||
await page.evaluate(() => {
|
||||
const canvas = document.querySelector<HTMLElement>(
|
||||
'[data-testid="annotation-canvas"]',
|
||||
)!
|
||||
const top = canvas.getBoundingClientRect().top + window.scrollY
|
||||
window.scrollTo(0, top - 100)
|
||||
canvas.focus({ preventScroll: true })
|
||||
})
|
||||
for (let step = 0; step < 14; step++) {
|
||||
await page.keyboard.press(key)
|
||||
const at = await focusedUnderStrip(page)
|
||||
if (!at.inPlace) break
|
||||
expect(
|
||||
at.top,
|
||||
`${key} ${step + 1}: ${at.name} below the strip`,
|
||||
).toBeGreaterThanOrEqual(at.stripBottom - 0.5)
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
test('Delete from the keyboard focuses the next vertex below the strip', async ({
|
||||
page,
|
||||
}) => {
|
||||
await open(page, ...manyPoints(), {
|
||||
...pointOf('zone-k', 'main', { cx: 0, cy: 0, r: 1 }, 'Zone K'),
|
||||
kind: 'zone',
|
||||
geometry: {
|
||||
type: 'polygon',
|
||||
points: [
|
||||
[300, 600],
|
||||
[300, 150],
|
||||
[600, 150],
|
||||
[600, 600],
|
||||
],
|
||||
},
|
||||
})
|
||||
await pickAnnotation(page, dict, 'Zone K')
|
||||
// The next vertex (drawn higher) starts under the strip, the focused one below it.
|
||||
const top = await page.evaluate(() => {
|
||||
const next = document.querySelector('[data-vertex="1"]')!
|
||||
const y = next.getBoundingClientRect().top + window.scrollY
|
||||
window.scrollTo(0, y - 90)
|
||||
document
|
||||
.querySelector<SVGElement>('[data-vertex="0"]')!
|
||||
.focus({ preventScroll: true })
|
||||
return next.getBoundingClientRect().top
|
||||
})
|
||||
const strip = await stripGeometry(page)
|
||||
expect(
|
||||
top,
|
||||
'precondition: the next vertex is under the strip',
|
||||
).toBeLessThan(strip.bottom)
|
||||
await page.keyboard.press('Delete')
|
||||
await expect(page.locator('[data-vertex="3"]')).toHaveCount(0)
|
||||
const at = await focusedUnderStrip(page)
|
||||
expect(at.name).toContain('Sommet')
|
||||
expect(at.top, `${at.name} below the strip`).toBeGreaterThanOrEqual(
|
||||
(await stripGeometry(page)).bottom - 0.5,
|
||||
)
|
||||
})
|
||||
|
||||
test('with the strip hidden the scroll offset is not applied', async ({
|
||||
page,
|
||||
}) => {
|
||||
|
||||
Reference in new issue
Block a user