fix(editor): focus follows the action after a touch commit

This commit is contained in:
bchanot committed 2026-11-19 11:26:37 +01:00
1 parent df46390bdb
commit 03e85a7c67
5 files changed
+135 -4

No files matched your search

@@ -748,3 +748,48 @@ describe('Safari: « Déplacer le point » clicked with the focus left on the sl
expect(useAnnotationWork.getState().mode?.kind).toBe('move')
})
})
describe('Safari: the focus after a press that commits a pending change', () => {
const tapDrag = (el: Element) => {
const init = {
pointerId: 1,
isPrimary: true,
button: 0,
buttons: 1,
pointerType: 'mouse',
}
fireEvent.pointerDown(el, { ...init, clientX: 50, clientY: 50 })
fireEvent.pointerMove(el, { ...init, clientX: 80, clientY: 80 })
}
it('a press on the point handle commits the slider change and focuses the handle', async () => {
await mount(withPoints(point('a', 50, 50, 5), point('b', 20, 20, 8)))
await select()
act(() => slider().focus())
fireEvent.keyDown(slider(), { key: 'PageUp' })
const before = depth()
tapDrag(handle().querySelector('[data-handle]')!)
expect(depth()).toBe(before + 1)
expect(document.activeElement).toBe(handle())
})
it('a press on the handle commits its arrow series and keeps the handle focused', async () => {
await mount(withPoints(point('a', 50, 50, 5)))
await select()
act(() => handle().focus())
fireEvent.keyDown(handle(), { key: 'ArrowRight' })
const before = depth()
tapDrag(handle().querySelector('[data-handle]')!)
expect(depth()).toBe(before + 1)
expect(document.activeElement).toBe(handle())
})
it('« Redessiner » and « Désélectionner » never leave the focus on body', async () => {
await mount(withPoints(point('a', 50, 50, 5)))
await select()
act(() => slider().focus())
fireEvent.keyDown(slider(), { key: 'PageUp' })
fireEvent.click(screen.getByRole('button', { name: 'Désélectionner' }))
expect(document.activeElement).not.toBe(document.body)
})
})
@@ -1292,3 +1292,58 @@ describe('Safari: a strip command clicked with the focus left on a keyed vertex'
expect(depth()).toBe(before + 1)
})
})
describe('Safari: the focus after a press that commits a pending series', () => {
// A tap that moves no focus (jsdom moves none either): the commit must not send the focus
// to body, and the press lands it where the same action sends it from the keyboard.
async function keyedVertex() {
await mount(squareText())
await select()
clickHandle('Sommet 1 de N', [20, 20])
act(() => vertex(1).focus())
fireEvent.keyDown(vertex(1), { key: 'ArrowRight' })
expect(useAnnotationWork.getState().preview?.source).toBe('keys')
}
it('a press on another vertex commits the series and focuses that vertex', async () => {
await keyedVertex()
const before = depth()
clickHandle('Sommet 2 de N', [80, 20])
expect(depth()).toBe(before + 1)
expect(pointsOf('z')![0]).toEqual([20.5, 20])
expect(document.activeElement).toBe(vertex(2))
})
it('a press on the interior keeps the focus on the handle that held the series', async () => {
await keyedVertex()
const before = depth()
pressAt(marker('z'), 50, 50)
expect(depth()).toBe(before + 1)
expect(document.activeElement).toBe(vertex(1))
})
it('a press on « + » commits the series and keeps a vertex focused', async () => {
await keyedVertex()
clickHandle('Ajouter un sommet après le sommet 1 de N', [50, 20])
expect(document.activeElement).not.toBe(document.body)
expect(document.activeElement?.getAttribute('data-vertex')).not.toBeNull()
})
it('« Redessiner » and « Déplacer le sommet » never leave it on body', async () => {
await keyedVertex()
fireEvent.click(screen.getByRole('button', { name: 'Déplacer le sommet' }))
expect(document.activeElement).not.toBe(document.body)
cleanup()
resetStore()
resetWork()
await keyedVertex()
fireEvent.click(screen.getByRole('button', { name: 'Redessiner' }))
expect(document.activeElement).not.toBe(document.body)
})
it('« Désélectionner » focuses the row, as its key does', async () => {
await keyedVertex()
fireEvent.click(screen.getByRole('button', { name: 'Désélectionner' }))
expect(document.activeElement).not.toBe(document.body)
})
})