fix(app): focus the shown tab after a crossing, one commit per typed field

- A field blurred by a 1 024 px crossing or a read-only switch hands its
  focus to the shown tab (or Plus), never to body (focusRequest, useViewport).
- TextField no longer commits a blurred value twice when it unmounts before
  the render that brings the new value: one undo step, one count.
- Annuler and Retablir share the field left by Tab, so Shift+Tab to Annuler
  and Enter still skips the undo of a refused field.
- Adding a reference clears the finding filter and the search.

Unit tests: no-loss (focus on tab and on Plus, one undo entry), history
buttons (field kept across the pair), references panel (add clears, refused
add keeps).
This commit is contained in:
bchanot committed 2026-11-08 20:23:40 +01:00
1 parent 9c03cf2413
commit 0bb150f860
9 files changed
+149 -29

No files matched your search

@@ -269,6 +269,26 @@ describe('typed text and the press', () => {
expect(store.getState().undo).toHaveLength(1)
})
it('a field left through « Rétablir » to « Annuler » still skips the undo', async () => {
const user = userEvent.setup()
mountDraft()
await ready()
act(() => void commitMove(40))
const field = await selectAnnotation(user)
await user.clear(field)
field.blur()
const redo = screen.getByRole('button', {
name: 'Rétablir la dernière modification annulée',
})
act(() => redo.focus())
fireEvent.focus(redo, { relatedTarget: field })
act(() => undoButton().focus())
fireEvent.focus(undoButton(), { relatedTarget: redo })
await user.keyboard('{Enter}')
expect(field).toHaveFocus()
expect(store.getState().undo).toHaveLength(1)
})
it('Ctrl+Z is ignored while a DeleteDialog is open', async () => {
mountDraft()
await ready()
@@ -245,9 +245,27 @@ describe('the guards of a width change', () => {
fireEvent.change(field, { target: { value: 'Nom saisi' } })
expect(store.getState().unsaved).toBe(false)
cross(800)
expect(store.getState().undo).toHaveLength(1)
expect(JSON.parse(store.getState().documentText).name.fr).toBe('Nom saisi')
expect(store.getState().unsaved).toBe(true)
await waitFor(() => expect(storedCopy()).not.toBeNull())
expect(document.activeElement).toBe(tab('Général'))
})
it('the focus of a typed field goes to « Plus » when the shown tab left the row', async () => {
const user = await mount()
await user.click(tab('Général'))
await user.click(byId('general-name-fr'))
cross(500)
expect(document.activeElement).toBe(button('Plus'))
})
it('a crossing with the focus on no field leaves the focus alone', async () => {
const user = await mount()
await user.click(tab('Général'))
;(document.activeElement as HTMLElement).blur()
cross(800)
expect(document.activeElement).toBe(document.body)
})
it('a field that switches in place loses a refused value, a field of a kept part keeps it', async () => {
@@ -282,3 +282,37 @@ describe('« Aller à » a reference', () => {
)
})
})
describe('adding a reference', () => {
async function add(user: ReturnType<typeof userEvent.setup>) {
const byId = (id: string) => panel().querySelector<HTMLElement>(id)!
await user.selectOptions(byId('#reference-new-type'), 'book')
await user.type(byId('#reference-new-citation'), 'Nouvelle source')
await user.click(
within(panel()).getByRole('button', { name: 'Ajouter la référence' }),
)
}
it('clears the finding filter and the search so the new reference shows', async () => {
const user = await mount()
await openFromFinding(user)
await user.type(search(), 'Barone')
expect(cards()).toHaveLength(1)
await add(user)
expect(search()).toHaveValue('')
expect(within(panel()).queryByTestId('references-filter-chip')).toBeNull()
expect(cards()).toHaveLength(4)
expect(within(panel()).getByText('Nouvelle source')).toBeInTheDocument()
})
it('a refused add keeps the filter and the search', async () => {
const user = await mount()
await openFromFinding(user)
await user.type(search(), 'Barone')
await user.click(
within(panel()).getByRole('button', { name: 'Ajouter la référence' }),
)
expect(search()).toHaveValue('Barone')
expect(within(panel()).getByTestId('references-filter-chip')).toBeInTheDocument()
})
})