fix(editor): Task 2 review round 1, trace calls, form hooks, keyboard proof
This commit is contained in:
1 parent
c893dec60b
commit
b703333b20
15 files changed
+476
-261
No files matched your search
@@ -362,27 +362,36 @@ test.describe('citations sheet, editing', () => {
|
||||
await expect(page.locator('dialog[open]')).toHaveCount(1)
|
||||
})
|
||||
|
||||
test('keyboard: Tab stays in the sheet, Escape closes only it, the trigger holds the focus', async ({
|
||||
test('keyboard: Enter opens the sheet, Tab reaches each control in order, Escape from one closes only the sheet', async ({
|
||||
page,
|
||||
}) => {
|
||||
test.setTimeout(150_000)
|
||||
await open(page)
|
||||
await openCitations(page, dict, 'Constat A')
|
||||
const controls = await panel(page)
|
||||
.locator('button, [href], input, select, textarea')
|
||||
.count()
|
||||
for (let step = 0; step < controls + 2; step++) {
|
||||
await openFinding(page, dict, 'Constat A')
|
||||
await trigger(page).focus()
|
||||
await page.keyboard.press('Enter')
|
||||
await expect(place(page, 'citations')).toBeVisible()
|
||||
await expect(page.locator('dialog[open]')).toHaveCount(2)
|
||||
// The tab order of the sheet, in the document's order, each control tagged.
|
||||
const count = await panel(page).evaluate((root) => {
|
||||
const sheet = root.closest('dialog')!
|
||||
const tabbable = [
|
||||
...sheet.querySelectorAll<HTMLElement>(
|
||||
'button:not([disabled]), [href], input:not([disabled]), select, textarea',
|
||||
),
|
||||
]
|
||||
tabbable.forEach((el, index) => el.setAttribute('data-kb', String(index)))
|
||||
return tabbable.length
|
||||
})
|
||||
expect(count).toBeGreaterThanOrEqual(5)
|
||||
const at = () =>
|
||||
page.evaluate(() => document.activeElement?.getAttribute('data-kb'))
|
||||
// On open the first control (✕) holds the focus; Tab then walks the rest.
|
||||
expect(await at()).toBe('0')
|
||||
for (let index = 1; index < count; index++) {
|
||||
await page.keyboard.press('Tab')
|
||||
const where = await page.evaluate(() => {
|
||||
const active = document.activeElement
|
||||
if (!active || active === document.body) return 'outside'
|
||||
return active.closest('[data-place="citations"]') ? 'sheet' : 'page'
|
||||
})
|
||||
// Past the last control the focus leaves for the browser's own interface
|
||||
// (body): it never reaches the dialog under the sheet or the page.
|
||||
expect(where, `Tab ${step + 1}`).not.toBe('page')
|
||||
expect(await at(), `Tab to control ${index}`).toBe(String(index))
|
||||
}
|
||||
await sheet(page).evaluate((node) => (node as HTMLElement).focus())
|
||||
await page.keyboard.press('Escape')
|
||||
await expect(panel(page)).toHaveCount(0)
|
||||
await expect(findingDialog(page)).toBeVisible()
|
||||
|
||||
Reference in new issue
Block a user