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

@@ -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()
})
})