fix(editor): dialog trigger for references, Task 11 review minors

This commit is contained in:
bchanot committed 2026-11-15 16:25:32 +01:00
1 parent da755f9768
commit d9dbcf1609
11 files changed
+47 -59

No files matched your search

+27 -3
View File
@@ -141,7 +141,8 @@ test.describe('references dialog, view mode', () => {
const { actor, seed } = await open(page) const { actor, seed } = await open(page)
requests.forbid(actor.account.email, actor.account.password) requests.forbid(actor.account.email, actor.account.password)
await openCitations(page, dict, 'Constat A') await openCitations(page, dict, 'Constat A')
await expect(trigger(page)).toHaveAttribute('aria-expanded', 'true') await expect(trigger(page)).toHaveAttribute('aria-haspopup', 'dialog')
await expect(trigger(page)).not.toHaveAttribute('aria-expanded')
await expect( await expect(
citationsDialog(page).getByRole('heading', { level: 2 }), citationsDialog(page).getByRole('heading', { level: 2 }),
).toHaveText(dict['editor.references.dialog_title']) ).toHaveText(dict['editor.references.dialog_title'])
@@ -217,6 +218,30 @@ test.describe('references dialog, view mode', () => {
await expect(trigger(page)).toBeFocused() await expect(trigger(page)).toBeFocused()
}) })
test('a family: « Tout afficher » filters the library by it, Back returns to its dialog', async ({
page,
}) => {
test.setTimeout(150_000)
await open(page)
await openCitations(page, dict, 'Dysfonction A')
await link(page).click()
await expectNoDialog(page)
const root = libraryRoot(page)
await expect(
root.locator('button[aria-controls][id$="-header"]'),
).toHaveCount(1)
await expect(root.getByRole('button', { name: /Source B/ })).toBeVisible()
await expect(root.getByTestId('editor-references-filter')).toContainText(
'Dysfonction A',
)
await page.goBack()
await expect(page.locator('dialog[open]')).toHaveCount(2)
await expect(panel(page)).toContainText('Zone A › Dysfonction A')
await expect(
findingDialog(page).getByRole('heading', { name: 'Dysfonction A' }),
).toBeVisible()
})
test('a long list scrolls inside the dialog; « 0 référence » opens the empty one', async ({ test('a long list scrolls inside the dialog; « 0 référence » opens the empty one', async ({
page, page,
}) => { }) => {
@@ -380,7 +405,6 @@ for (const reduced of [false, true]) {
await openCitations(page, dict, 'Constat A') await openCitations(page, dict, 'Constat A')
await closeCitations(page, dict) await closeCitations(page, dict)
await expect(trigger(page)).toBeFocused() await expect(trigger(page)).toBeFocused()
await expect(trigger(page)).toHaveAttribute('aria-expanded', 'false')
await showCitations(page) await showCitations(page)
await page.keyboard.press('Escape') await page.keyboard.press('Escape')
await expect(panel(page)).toHaveCount(0) await expect(panel(page)).toHaveCount(0)
@@ -534,7 +558,7 @@ test.describe('references dialog, read-only at 375 px', () => {
// A tile opens by a tap; the finding dialog's controls underneath stay as they were. // A tile opens by a tap; the finding dialog's controls underneath stay as they were.
await tap(heads(page).first()) await tap(heads(page).first())
await expect(heads(page).first()).toHaveAttribute('aria-expanded', 'true') await expect(heads(page).first()).toHaveAttribute('aria-expanded', 'true')
await expect(trigger(page)).toHaveAttribute('aria-expanded', 'true') await expect(citationsDialog(page)).toBeVisible()
// Its ✕ closes it only; the trigger holds the focus. // Its ✕ closes it only; the trigger holds the focus.
await tap( await tap(
citationsDialog(page).getByRole('button', { name: dict['common.close'] }), citationsDialog(page).getByRole('button', { name: dict['common.close'] }),
@@ -7,8 +7,6 @@ import { useT } from '@/i18n/useT'
interface CitationsProps { interface CitationsProps {
item: FindingItem item: FindingItem
/** The references dialog is open over the finding dialog (the trigger reads « expanded »). */
citationsOpen: boolean
/** Opens the references dialog of the family or node. */ /** Opens the references dialog of the family or node. */
onShowReferences: (opener: HTMLElement) => void onShowReferences: (opener: HTMLElement) => void
} }
@@ -23,7 +21,6 @@ const RING =
function CitationsTrigger({ function CitationsTrigger({
item, item,
count, count,
citationsOpen,
onShowReferences, onShowReferences,
}: CitationsProps & { count: number }) { }: CitationsProps & { count: number }) {
const plural = usePlural() const plural = usePlural()
@@ -31,8 +28,7 @@ function CitationsTrigger({
<button <button
type="button" type="button"
data-citations-trigger={JSON.stringify(item.key)} data-citations-trigger={JSON.stringify(item.key)}
aria-expanded={citationsOpen} aria-haspopup="dialog"
aria-controls="editor-citations-panel"
onClick={(event) => onShowReferences(event.currentTarget)} onClick={(event) => onShowReferences(event.currentTarget)}
className={`${PILL} ${RING}`} className={`${PILL} ${RING}`}
> >
@@ -65,8 +65,6 @@ function ItemBody(props: ItemBodyProps) {
const { layer } = props const { layer } = props
const t = useT() const t = useT()
const mode = useItemMode() const mode = useItemMode()
const citationsOpen =
!!layer.view && 'key' in layer.view && layer.view.citations
const showReferences = (opener: HTMLElement) => const showReferences = (opener: HTMLElement) =>
layer.openCitations(props.item.key, opener) layer.openCitations(props.item.key, opener)
return ( return (
@@ -78,14 +76,12 @@ function ItemBody(props: ItemBodyProps) {
guards={layer.guards} guards={layer.guards}
onDone={mode.done} onDone={mode.done}
onDiscardClose={() => layer.close(true)} onDiscardClose={() => layer.close(true)}
citationsOpen={citationsOpen}
onShowReferences={showReferences} onShowReferences={showReferences}
/> />
) : ( ) : (
<FindingView <FindingView
item={props.item} item={props.item}
readOnly={props.readOnly} readOnly={props.readOnly}
citationsOpen={citationsOpen}
onEdit={mode.startEdit} onEdit={mode.startEdit}
onDelete={() => props.onDelete(props.item)} onDelete={() => props.onDelete(props.item)}
onShowReferences={showReferences} onShowReferences={showReferences}
@@ -77,8 +77,6 @@ export interface FindingEditFormProps {
onDone: (saved: boolean) => void onDone: (saved: boolean) => void
/** « Abandonner » after a close request: the draft goes, so does the dialog. */ /** « Abandonner » after a close request: the draft goes, so does the dialog. */
onDiscardClose: () => void onDiscardClose: () => void
/** The references dialog is open over the finding dialog (the trigger reads « expanded »). */
citationsOpen: boolean
/** Opens the references dialog, which lists the element's citations. */ /** Opens the references dialog, which lists the element's citations. */
onShowReferences: (opener: HTMLElement) => void onShowReferences: (opener: HTMLElement) => void
} }
@@ -229,7 +227,6 @@ export default function FindingEditForm(props: FindingEditFormProps) {
)} )}
<CitationsHeader <CitationsHeader
item={props.item} item={props.item}
citationsOpen={props.citationsOpen}
onShowReferences={props.onShowReferences} onShowReferences={props.onShowReferences}
/> />
{form.error && ( {form.error && (
@@ -9,7 +9,6 @@ import { useT } from '@/i18n/useT'
export interface FindingViewProps { export interface FindingViewProps {
item: FindingItem item: FindingItem
readOnly: boolean readOnly: boolean
citationsOpen: boolean
onEdit: () => void onEdit: () => void
onDelete: () => void onDelete: () => void
onShowReferences: (opener: HTMLElement) => void onShowReferences: (opener: HTMLElement) => void
@@ -53,7 +52,7 @@ function Texts({ item }: { item: FindingItem }) {
* to its references dialog, and the actions of the edit tier. Nothing here edits a field in place. * to its references dialog, and the actions of the edit tier. Nothing here edits a field in place.
*/ */
export default function FindingView(props: FindingViewProps) { export default function FindingView(props: FindingViewProps) {
const { item, readOnly, citationsOpen } = props const { item, readOnly } = props
const t = useT() const t = useT()
const edit = useEditCommand() const edit = useEditCommand()
return ( return (
@@ -75,11 +74,7 @@ export default function FindingView(props: FindingViewProps) {
))} ))}
</div> </div>
<Texts item={item} /> <Texts item={item} />
<CitationsHeader <CitationsHeader item={item} onShowReferences={props.onShowReferences} />
item={item}
citationsOpen={citationsOpen}
onShowReferences={props.onShowReferences}
/>
<FindingActions <FindingActions
item={item} item={item}
readOnly={readOnly} readOnly={readOnly}
@@ -111,8 +111,6 @@ function EntryTile({
movable={false} movable={false}
on={{ on={{
toggle: () => tiles.toggle(key), toggle: () => tiles.toggle(key),
// Never offered: a read-only tile has no « Modifier ».
edit: () => undefined,
goTo: (target) => navigate(targetOfKey(target)), goTo: (target) => navigate(targetOfKey(target)),
}} }}
/> />
@@ -11,8 +11,11 @@ import type { ReferenceHost } from './referenceTypes'
/** What a tile asks of the library that owns its state. */ /** What a tile asks of the library that owns its state. */
export interface TileHandlers { export interface TileHandlers {
toggle: () => void toggle: () => void
/** « Modifier »: opens the reference dialog; `opener` is where the focus returns. */ /**
edit: (opener: HTMLElement) => void * « Modifier »: opens the reference dialog; `opener` is where the focus returns. The
* Références tab only: the references dialog's tiles are read only.
*/
edit?: (opener: HTMLElement) => void
/** « Supprimer »: the Références tab only. */ /** « Supprimer »: the Références tab only. */
remove?: () => void remove?: () => void
/** « Monter » / « Descendre »: the Références tab only. */ /** « Monter » / « Descendre »: the Références tab only. */
@@ -98,27 +101,11 @@ function TileHeader({ base, props }: { base: string; props: TileProps }) {
) )
} }
/** The panel's one action (P7): « Modifier ». Removing a citation is the edit form's. */
function PanelActions({ props }: { props: TileProps }) {
const t = useT()
return (
<ActionButton
readOnly={false}
variant="secondary"
size="sm"
onClick={(event) => props.on.edit(event.currentTarget)}
>
{t('editor.references.edit')}
</ActionButton>
)
}
/** « Modifier », « Supprimer » (uncited only, else the hint), « Monter » / « Descendre ». */ /** « Modifier », « Supprimer » (uncited only, else the hint), « Monter » / « Descendre ». */
function TileActions({ props }: { props: TileProps }) { function TileActions({ props }: { props: TileProps }) {
const t = useT() const t = useT()
const { position, count, citers, readOnly, movable, on } = props const { position, count, citers, readOnly, movable, on } = props
if (readOnly) return null if (readOnly || !on.edit) return null
if (props.panel) return <PanelActions props={props} />
return ( return (
<> <>
<div className="flex flex-wrap items-center gap-2"> <div className="flex flex-wrap items-center gap-2">
@@ -126,7 +113,7 @@ function TileActions({ props }: { props: TileProps }) {
readOnly={false} readOnly={false}
variant="secondary" variant="secondary"
size="sm" size="sm"
onClick={(event) => on.edit(event.currentTarget)} onClick={(event) => on.edit?.(event.currentTarget)}
> >
{t('editor.references.edit')} {t('editor.references.edit')}
</ActionButton> </ActionButton>
@@ -113,7 +113,7 @@ type LeaveNav = Pick<
'guards' | 'state' | 'closeCitations' | 'references' 'guards' | 'state' | 'closeCitations' | 'references'
> >
/** Closes the citations dialog and the reference dialog of the navigation `latest` holds, if open. */ /** Closes the citations and reference dialogs of the navigation `latest` holds, if open. */
function clearerOf(latest: { current: LeaveNav }): () => void { function clearerOf(latest: { current: LeaveNav }): () => void {
return () => { return () => {
const { state, closeCitations, references } = latest.current const { state, closeCitations, references } = latest.current
+1 -1
View File
@@ -85,7 +85,7 @@ export interface EditorPlaceProps {
focus?: FocusRequest focus?: FocusRequest
/** The finding dialog and the citations dialog over it (only Constats has them). */ /** The finding dialog and the citations dialog over it (only Constats has them). */
layer?: FindingLayer layer?: FindingLayer
/** The reference dialog and the filter (only the References tab and the citations dialog use them). */ /** The reference dialog and the filter (the References tab and the citations dialog). */
references?: ReferenceLayer references?: ReferenceLayer
/** Bumped by « Tout afficher »: the references library resets its search once per bump. */ /** Bumped by « Tout afficher »: the references library resets its search once per bump. */
libraryReset?: number libraryReset?: number
+3 -6
View File
@@ -731,17 +731,14 @@ describe('Constats tab', () => {
await user.click(items()[2]) await user.click(items()[2])
const trigger = () => const trigger = () =>
inFindingDialog().getByRole('button', { name: /^1 référence$/ }) inFindingDialog().getByRole('button', { name: /^1 référence$/ })
expect(trigger()).toHaveAttribute('aria-expanded', 'false') expect(trigger()).toHaveAttribute('aria-haspopup', 'dialog')
expect(trigger()).toHaveAttribute('aria-controls', 'editor-citations-panel') expect(trigger()).not.toHaveAttribute('aria-expanded')
await user.click(trigger()) await user.click(trigger())
expect(trigger()).toHaveAttribute('aria-expanded', 'true')
const citations = screen const citations = screen
.getByTestId('editor-citations-panel') .getByTestId('editor-citations-panel')
.closest('dialog')! .closest('dialog')!
await user.click(within(citations).getByRole('button', { name: 'Fermer' })) await user.click(within(citations).getByRole('button', { name: 'Fermer' }))
await waitFor(() => await waitFor(() => expect(trigger()).toHaveFocus())
expect(trigger()).toHaveAttribute('aria-expanded', 'false'),
)
}) })
it('a category has no vet flag; read-only hides the editing actions', async () => { it('a category has no vet flag; read-only hides the editing actions', async () => {
@@ -172,10 +172,11 @@ describe('opening', () => {
expect(screen.queryByRole('button', { name: 'Références' })).toBeNull() expect(screen.queryByRole('button', { name: 'Références' })).toBeNull()
expect(hasPanel()).toBe(false) expect(hasPanel()).toBe(false)
await select(user, /Node A/) await select(user, /Node A/)
expect(trigger()).toHaveAttribute('aria-expanded', 'false') expect(trigger()).toHaveAttribute('aria-haspopup', 'dialog')
expect(trigger()).toHaveAttribute('aria-controls', 'editor-citations-panel') expect(trigger()).not.toHaveAttribute('aria-expanded')
expect(trigger()).not.toHaveAttribute('aria-controls')
await user.click(trigger()) await user.click(trigger())
expect(trigger()).toHaveAttribute('aria-expanded', 'true') expect(trigger()).not.toHaveAttribute('aria-expanded')
await focusIs(closeButton) await focusIs(closeButton)
expect(heading()).toHaveAttribute('id', 'editor-citations-title') expect(heading()).toHaveAttribute('id', 'editor-citations-title')
expect(citationsDialog()).toHaveAttribute( expect(citationsDialog()).toHaveAttribute(
@@ -310,7 +311,6 @@ describe.each(MODES)('closing, %s', (_label, reduced) => {
fireEvent.click(backdrop()) fireEvent.click(backdrop())
await closed() await closed()
await focusIs(() => trigger()) await focusIs(() => trigger())
expect(trigger()).toHaveAttribute('aria-expanded', 'false')
}) })
it('the platform close request closes it with nothing focused (no key reaches the page)', async () => { it('the platform close request closes it with nothing focused (no key reaches the page)', async () => {
@@ -393,15 +393,13 @@ describe.each(MODES)('closing, %s', (_label, reduced) => {
}) })
describe('the exit', () => { describe('the exit', () => {
it('a dialog playing its exit is inert, its trigger reads « expanded » until it is gone', async () => { it('a dialog playing its exit is inert until it is gone', async () => {
const user = await mount() const user = await mount()
await openFromFinding(user) await openFromFinding(user)
expect(trigger()).toHaveAttribute('aria-expanded', 'true')
await user.click(closeButton()) await user.click(closeButton())
expect(hasPanel()).toBe(true) expect(hasPanel()).toBe(true)
expect(panel().closest('dialog')).toHaveAttribute('inert') expect(panel().closest('dialog')).toHaveAttribute('inert')
await closed() await closed()
expect(trigger()).toHaveAttribute('aria-expanded', 'false')
}) })
it('a second close during the exit finds no layer and does nothing', async () => { it('a second close during the exit finds no layer and does nothing', async () => {