fix(editor): a chip reached by Tab is revealed, never on a press
This commit is contained in:
1 parent
068ecd573e
commit
190471d4d9
3 files changed
+90
-34
No files matched your search
@@ -1667,10 +1667,6 @@ test.describe('the view row (criterion 32)', () => {
|
||||
id: 'detail-long-2',
|
||||
arrows: 3,
|
||||
at: 0,
|
||||
// Measured: Chromium does not scroll a Tab focus onto a chip only partly under the
|
||||
// fade (scrollLeft stays 0, the chip lies 211 px into it); the row has no focus reveal.
|
||||
// Reported to the controller, never made to pass by weakening the case.
|
||||
open: true,
|
||||
},
|
||||
{
|
||||
label: '(b2) the 6th view inside the end fade',
|
||||
@@ -1679,33 +1675,32 @@ test.describe('the view row (criterion 32)', () => {
|
||||
at: HINT_CLEAR - 20,
|
||||
},
|
||||
]) {
|
||||
;(entry.open ? test.fixme : test)(
|
||||
`Tab back into the row after a scroll: ${entry.label} lies clear`,
|
||||
async ({ page }) => {
|
||||
await openRow(page)
|
||||
await chipById(page, 'main').focus()
|
||||
for (let n = 0; n < entry.arrows; n++)
|
||||
await page.keyboard.press('ArrowRight')
|
||||
await page.keyboard.press('Enter')
|
||||
await expect(pressedChip(page)).toHaveAttribute(
|
||||
'data-view-chip',
|
||||
entry.id,
|
||||
)
|
||||
const { clientWidth } = await rowGeometry(page)
|
||||
await setRowScroll(
|
||||
page,
|
||||
entry.at === 0
|
||||
? 0
|
||||
: await scrollLeftFor(page, entry.id, clientWidth - entry.at),
|
||||
)
|
||||
await focusBefore(chipById(page, entry.id))
|
||||
const top = await scrollY(page)
|
||||
await page.keyboard.press('Tab')
|
||||
await expect(chipById(page, entry.id)).toBeFocused()
|
||||
await expectRevealed(page, entry.id, 'Tab from under the end fade')
|
||||
expect(await scrollY(page)).toBe(top)
|
||||
},
|
||||
)
|
||||
test(`Tab back into the row after a scroll: ${entry.label} lies clear`, async ({
|
||||
page,
|
||||
}) => {
|
||||
await openRow(page)
|
||||
await chipById(page, 'main').focus()
|
||||
for (let n = 0; n < entry.arrows; n++)
|
||||
await page.keyboard.press('ArrowRight')
|
||||
await page.keyboard.press('Enter')
|
||||
await expect(pressedChip(page)).toHaveAttribute(
|
||||
'data-view-chip',
|
||||
entry.id,
|
||||
)
|
||||
const { clientWidth } = await rowGeometry(page)
|
||||
await setRowScroll(
|
||||
page,
|
||||
entry.at === 0
|
||||
? 0
|
||||
: await scrollLeftFor(page, entry.id, clientWidth - entry.at),
|
||||
)
|
||||
await focusBefore(chipById(page, entry.id))
|
||||
const top = await scrollY(page)
|
||||
await page.keyboard.press('Tab')
|
||||
await expect(chipById(page, entry.id)).toBeFocused()
|
||||
await expectRevealed(page, entry.id, 'Tab from under the end fade')
|
||||
expect(await scrollY(page)).toBe(top)
|
||||
})
|
||||
}
|
||||
|
||||
test('no click lost: a pointer press on a chip partly under the end fade activates it at the first click', async ({
|
||||
@@ -1738,7 +1733,12 @@ test.describe('the view row (criterion 32)', () => {
|
||||
at.right,
|
||||
'precondition: the chip runs under the fade',
|
||||
).toBeGreaterThan(at.x)
|
||||
await page.mouse.click(at.x, at.y)
|
||||
const before = (await rowGeometry(page)).scrollLeft
|
||||
await page.mouse.move(at.x, at.y)
|
||||
await page.mouse.down()
|
||||
// Pressed, not yet released: the row has not moved under the pointer.
|
||||
expect((await rowGeometry(page)).scrollLeft).toBeCloseTo(before, 0)
|
||||
await page.mouse.up()
|
||||
await expect(pressedChip(page)).toHaveAttribute(
|
||||
'data-view-chip',
|
||||
'detail-long-3',
|
||||
|
||||
@@ -28,6 +28,15 @@ const DOT =
|
||||
'absolute -right-0.5 -top-0.5 h-2.5 w-2.5 rounded-full bg-[var(--color-ink)] ' +
|
||||
'ring-2 ring-white'
|
||||
|
||||
/** `:focus-visible` is unsupported in some environments (happy-dom): then not keyboard. */
|
||||
function isKeyboardFocus(element: HTMLElement): boolean {
|
||||
try {
|
||||
return element.matches(':focus-visible')
|
||||
} catch {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
/** A fade at one edge of the row; its chevron is a mouse aid, never a tab stop. */
|
||||
function Hint({
|
||||
side,
|
||||
@@ -95,9 +104,15 @@ export default function ViewSwitcher({
|
||||
|
||||
useEffect(() => setFocused(null), [current])
|
||||
|
||||
// Only a keyboard focus entering the row reveals its chip (a Tab does not scroll a chip
|
||||
// that is partly under a fade); a pointer focus never does, so a press never moves the row.
|
||||
const onFocus = (event: FocusEvent<HTMLElement>) => {
|
||||
const id = (event.target as HTMLElement).dataset.viewChip
|
||||
if (id) setFocused(id)
|
||||
const chip = event.target as HTMLElement
|
||||
const id = chip.dataset.viewChip
|
||||
if (!id) return
|
||||
setFocused(id)
|
||||
const from = event.relatedTarget as Node | null
|
||||
if (!event.currentTarget.contains(from) && isKeyboardFocus(chip)) reveal(id)
|
||||
}
|
||||
const onBlur = (event: FocusEvent<HTMLElement>) => {
|
||||
if (!event.currentTarget.contains(event.relatedTarget as Node | null))
|
||||
|
||||
@@ -259,6 +259,43 @@ describe('the reveal of the active chip', () => {
|
||||
})
|
||||
})
|
||||
|
||||
describe('the reveal of a chip focused from outside the row', () => {
|
||||
let scrollTo: ReturnType<typeof vi.fn>
|
||||
beforeEach(() => {
|
||||
scrollTo = vi.fn()
|
||||
Object.defineProperty(Element.prototype, 'scrollTo', {
|
||||
configurable: true,
|
||||
value: scrollTo,
|
||||
})
|
||||
})
|
||||
const focusFromOutside = (keyboard: boolean) => {
|
||||
renderRow(vi.fn(), viewsOf(), 'v1')
|
||||
stubGeometry()
|
||||
scrollTo.mockClear()
|
||||
const target = chip('Vue 5')
|
||||
target.matches = (selector: string) =>
|
||||
keyboard && selector === ':focus-visible'
|
||||
const outside = document.createElement('button')
|
||||
document.body.append(outside)
|
||||
outside.focus()
|
||||
act(() => target.focus())
|
||||
outside.remove()
|
||||
}
|
||||
|
||||
it('reveals a keyboard-focused chip past the end hint', () => {
|
||||
focusFromOutside(true)
|
||||
expect(scrollTo).toHaveBeenCalledTimes(1)
|
||||
expect(scrollTo).toHaveBeenCalledWith(
|
||||
expect.objectContaining({ left: 272 }),
|
||||
)
|
||||
})
|
||||
|
||||
it('never scrolls at a pointer focus (not :focus-visible)', () => {
|
||||
focusFromOutside(false)
|
||||
expect(scrollTo).not.toHaveBeenCalled()
|
||||
})
|
||||
})
|
||||
|
||||
describe('a press refused by the drawing guard', () => {
|
||||
const withView = (text: string) =>
|
||||
insert(text, {
|
||||
@@ -313,6 +350,10 @@ describe('a press refused by the drawing guard', () => {
|
||||
stubGeometry(700, 200)
|
||||
scrollTo.mockClear()
|
||||
const head = chip('Tête')
|
||||
// A pointer press is never :focus-visible in a browser (happy-dom says true for any focus).
|
||||
head.matches = (selector: string) =>
|
||||
selector !== ':focus-visible' &&
|
||||
Element.prototype.matches.call(head, selector)
|
||||
await user.click(head)
|
||||
expect(useAnnotationWork.getState().question?.work).toBe('move')
|
||||
await user.click(await screen.findByRole('button', { name: 'Continuer' }))
|
||||
|
||||
Reference in new issue
Block a user