fix(editor): no focus in the editor header lands under the top bar
This commit is contained in:
1 parent
1ab3b6afba
commit
238650719e
2 files changed
+142
-11
No files matched your search
@@ -1,5 +1,5 @@
|
||||
import { fr } from '@/i18n/fr'
|
||||
import type { Page, TestInfo } from '@playwright/test'
|
||||
import type { Locator, Page, TestInfo } from '@playwright/test'
|
||||
import { expect, expectAccessible, test } from '../support/browser'
|
||||
import { expectNoShift } from '../support/layout'
|
||||
import { dropLateReplays, routeToSandbox } from '../support/sandbox'
|
||||
@@ -607,26 +607,135 @@ 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).
|
||||
* The focused element's top against the bottom of what covers it (the strip in the drawing
|
||||
* place, else the bar); null on the sticky chrome itself, whose focus never scrolls the page.
|
||||
*/
|
||||
function focusedUnderStrip(page: Page) {
|
||||
return page.evaluate(() => {
|
||||
const active = document.activeElement as HTMLElement
|
||||
const strip = document.querySelector('[data-testid="edit-strip"]')!
|
||||
const label = active.getAttribute('aria-label') ?? active.textContent ?? ''
|
||||
const bar = document.querySelector(
|
||||
'header:has([data-testid="topbar-account"])',
|
||||
)!
|
||||
const inPlace =
|
||||
!!active.closest('[data-place="annotations.drawing"]') &&
|
||||
!strip.contains(active)
|
||||
// Below the strip in the drawing place, below the bar elsewhere; the sticky chrome
|
||||
// itself (the strip's commands, the bar's links) never scrolls the page; the shell's own
|
||||
// links, outside the editor page, are not its concern.
|
||||
const sticky =
|
||||
strip.contains(active) ||
|
||||
bar.contains(active) ||
|
||||
!active.closest('[data-editor-workspace]')
|
||||
return {
|
||||
inPlace,
|
||||
limit: sticky
|
||||
? null
|
||||
: inPlace
|
||||
? strip.getBoundingClientRect().bottom
|
||||
: bar.getBoundingClientRect().bottom,
|
||||
name: `${active.tagName} « ${label.trim().slice(0, 30)} »`,
|
||||
top: active.getBoundingClientRect().top,
|
||||
stripBottom: strip.getBoundingClientRect().bottom,
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// Criterion 25: the header's « Enregistrer » and the tab row's « Défaire » and « Refaire » sit
|
||||
// outside the drawing place; a keyboard focus on them, the page scrolled, never lands under the bar.
|
||||
const HEADER_WIDTHS = [820, 1024, 1280]
|
||||
|
||||
/** Focuses the tabbable next to `target` without scrolling, then scrolls it under the bar. */
|
||||
function parkBesideTarget(target: Locator, key: 'Tab' | 'Shift+Tab') {
|
||||
return target.evaluate((el, step) => {
|
||||
const tabbable = [
|
||||
...document.querySelectorAll<HTMLElement>(
|
||||
'a[href], button, input, select, textarea, [tabindex]',
|
||||
),
|
||||
].filter((n) => n.tabIndex >= 0 && n.getClientRects().length > 0)
|
||||
const beside =
|
||||
tabbable[tabbable.indexOf(el as HTMLElement) + (step === 'Tab' ? -1 : 1)]
|
||||
beside.focus({ preventScroll: true })
|
||||
const bar = document.querySelector(
|
||||
'header:has([data-testid="topbar-account"])',
|
||||
)!
|
||||
const top = el.getBoundingClientRect().top + window.scrollY
|
||||
window.scrollTo(0, top - bar.getBoundingClientRect().bottom + 10)
|
||||
}, key)
|
||||
}
|
||||
|
||||
for (const width of HEADER_WIDTHS) {
|
||||
test.describe(`the editor header's controls under the top bar at ${width} px (criterion 25)`, () => {
|
||||
test.use({
|
||||
locale: 'fr-FR',
|
||||
actionTimeout: 15_000,
|
||||
viewport: { width, height: 768 },
|
||||
})
|
||||
test.beforeEach(async ({ context }, info) => {
|
||||
test.skip(isPhone(info), 'the phone project has its own viewport') // floor-guard: allow C16 sticky bar probed at 820, 1 024 and 1 280 px
|
||||
await routeToSandbox(context)
|
||||
})
|
||||
test.afterEach(async ({ context }) => {
|
||||
await dropLateReplays(context)
|
||||
})
|
||||
|
||||
test('Tab and Shift+Tab onto « Enregistrer », « Défaire » and « Refaire » end below the bar', async ({
|
||||
page,
|
||||
}) => {
|
||||
const actor = await editorActor('fr')
|
||||
const seed = await seedDraft(actor, { shape: shapeWith(...manyPoints()) })
|
||||
await openEditor(page, dict, actor, seed.sheetId)
|
||||
// A committed edit enables « Enregistrer » and « Défaire »; back on the annotations tab.
|
||||
await selectTab(page, dict, 'general')
|
||||
const name = page.getByLabel(dict['editor.general.name_en'], {
|
||||
exact: true,
|
||||
})
|
||||
// Read-only below 1 024 px: the name is text and only the tab row's controls remain.
|
||||
const editable = await name.evaluate((el) => el.tagName === 'INPUT')
|
||||
if (editable) {
|
||||
await name.fill(`Edited ${Date.now()}`)
|
||||
await name.press('Enter')
|
||||
}
|
||||
await selectTab(page, dict, 'annotations')
|
||||
const named = (label: string) =>
|
||||
page.getByRole('button', { name: label, exact: true })
|
||||
const targets = [
|
||||
page.getByRole('tab', { name: dict['editor.tab.annotations'] }),
|
||||
...(editable
|
||||
? [
|
||||
named(dict['common.save']),
|
||||
named(dict['editor.history.undo_title']),
|
||||
named(dict['editor.history.redo_title']),
|
||||
]
|
||||
: []),
|
||||
]
|
||||
if (editable) await expect(targets[1]).toBeEnabled()
|
||||
for (const target of targets) {
|
||||
for (const key of ['Tab', 'Shift+Tab'] as const) {
|
||||
await parkBesideTarget(target, key)
|
||||
const bar = await topBar(page).boundingBox()
|
||||
const before = (await target.boundingBox())!
|
||||
expect(before.y, 'precondition: starts under the bar').toBeLessThan(
|
||||
bar!.y + bar!.height,
|
||||
)
|
||||
const label =
|
||||
(await target.getAttribute('aria-label')) ??
|
||||
(await target.textContent())
|
||||
await page.keyboard.press(key)
|
||||
await expect(target, `${key} onto ${label}`).toBeFocused()
|
||||
const after = (await target.boundingBox())!
|
||||
const barBottom = (await topBar(page).boundingBox())!.y + bar!.height
|
||||
expect
|
||||
.soft(
|
||||
after.y,
|
||||
`${key} onto ${label}: top ${after.y} vs bar bottom ${barBottom}`,
|
||||
)
|
||||
.toBeGreaterThanOrEqual(barBottom - 0.5)
|
||||
}
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
for (const viewport of VIEWPORTS) {
|
||||
test.describe(`the strip under the top bar at ${viewport.width} px (U2 Task 14)`, () => {
|
||||
test.use({
|
||||
@@ -813,14 +922,14 @@ for (const viewport of VIEWPORTS) {
|
||||
window.scrollTo(0, top - 100)
|
||||
canvas.focus({ preventScroll: true })
|
||||
})
|
||||
for (let step = 0; step < 14; step++) {
|
||||
for (let step = 0; step < 40; step++) {
|
||||
await page.keyboard.press(key)
|
||||
const at = await focusedUnderStrip(page)
|
||||
if (!at.inPlace) break
|
||||
if (at.limit === null) continue
|
||||
expect(
|
||||
at.top,
|
||||
`${key} ${step + 1}: ${at.name} below the strip`,
|
||||
).toBeGreaterThanOrEqual(at.stripBottom - 0.5)
|
||||
`${key} ${step + 1}: ${at.name} below the strip or the bar`,
|
||||
).toBeGreaterThanOrEqual(at.limit - 0.5)
|
||||
}
|
||||
}
|
||||
})
|
||||
@@ -866,7 +975,7 @@ for (const viewport of VIEWPORTS) {
|
||||
)
|
||||
})
|
||||
|
||||
test('with the strip hidden the scroll offset is not applied', async ({
|
||||
test('with the strip hidden only the bar offset is applied', async ({
|
||||
page,
|
||||
}) => {
|
||||
await open(page, ...manyPoints())
|
||||
@@ -884,7 +993,11 @@ for (const viewport of VIEWPORTS) {
|
||||
)
|
||||
await openSection(page, dict, 'categories')
|
||||
await expect(page.getByTestId('edit-strip')).toBeHidden()
|
||||
expect(await margin(), 'the strip is hidden').toBe('0px')
|
||||
// Only the bar's margin (its height and the 0.5 rem gap) remains, not the strip's.
|
||||
const bar = (await topBar(page).boundingBox())!
|
||||
expect(parseFloat(await margin()), 'the strip is hidden').toBe(
|
||||
bar.height + 8,
|
||||
)
|
||||
})
|
||||
})
|
||||
}
|
||||
@@ -12,6 +12,24 @@ body,
|
||||
--shell-top-bar-height: calc(3.5rem + env(safe-area-inset-top, 0px));
|
||||
--edit-strip-height: 4rem;
|
||||
}
|
||||
/* The editor page's other focusables (header, tab row, history buttons, notices) are never
|
||||
left under the sticky top bar either (criterion 25), at every width: the bar is sticky
|
||||
everywhere. Same margin, not a padding, and the same exclusions (the strip, dialogs; the
|
||||
bar is outside the workspace). :where() keeps its specificity under the drawing place's
|
||||
rule below, which adds the strip's height and wins for its targets. */
|
||||
:where([data-editor-workspace])
|
||||
:is(
|
||||
a,
|
||||
button,
|
||||
input,
|
||||
select,
|
||||
textarea,
|
||||
[tabindex],
|
||||
[data-focus-key],
|
||||
[data-focus-target]
|
||||
):not([data-testid='edit-strip'] *, dialog *) {
|
||||
scroll-margin-top: calc(var(--shell-top-bar-height) + 0.5rem);
|
||||
}
|
||||
/* 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). It is a margin on the
|
||||
drawing place's focus targets, not a padding on the page: scroll-padding also pushed the
|
||||
|
||||
Reference in new issue
Block a user