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)
requests.forbid(actor.account.email, actor.account.password)
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(
citationsDialog(page).getByRole('heading', { level: 2 }),
).toHaveText(dict['editor.references.dialog_title'])
@@ -217,6 +218,30 @@ test.describe('references dialog, view mode', () => {
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 ({
page,
}) => {
@@ -380,7 +405,6 @@ for (const reduced of [false, true]) {
await openCitations(page, dict, 'Constat A')
await closeCitations(page, dict)
await expect(trigger(page)).toBeFocused()
await expect(trigger(page)).toHaveAttribute('aria-expanded', 'false')
await showCitations(page)
await page.keyboard.press('Escape')
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.
await tap(heads(page).first())
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.
await tap(
citationsDialog(page).getByRole('button', { name: dict['common.close'] }),
@@ -7,8 +7,6 @@ import { useT } from '@/i18n/useT'
interface CitationsProps {
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. */
onShowReferences: (opener: HTMLElement) => void
}
@@ -23,7 +21,6 @@ const RING =
function CitationsTrigger({
item,
count,
citationsOpen,
onShowReferences,
}: CitationsProps & { count: number }) {
const plural = usePlural()
@@ -31,8 +28,7 @@ function CitationsTrigger({
<button
type="button"
data-citations-trigger={JSON.stringify(item.key)}
aria-expanded={citationsOpen}
aria-controls="editor-citations-panel"
aria-haspopup="dialog"
onClick={(event) => onShowReferences(event.currentTarget)}
className={`${PILL} ${RING}`}
>
@@ -65,8 +65,6 @@ function ItemBody(props: ItemBodyProps) {
const { layer } = props
const t = useT()
const mode = useItemMode()
const citationsOpen =
!!layer.view && 'key' in layer.view && layer.view.citations
const showReferences = (opener: HTMLElement) =>
layer.openCitations(props.item.key, opener)
return (
@@ -78,14 +76,12 @@ function ItemBody(props: ItemBodyProps) {
guards={layer.guards}
onDone={mode.done}
onDiscardClose={() => layer.close(true)}
citationsOpen={citationsOpen}
onShowReferences={showReferences}
/>
) : (
<FindingView
item={props.item}
readOnly={props.readOnly}
citationsOpen={citationsOpen}
onEdit={mode.startEdit}
onDelete={() => props.onDelete(props.item)}
onShowReferences={showReferences}
@@ -77,8 +77,6 @@ export interface FindingEditFormProps {
onDone: (saved: boolean) => void
/** « Abandonner » after a close request: the draft goes, so does the dialog. */
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. */
onShowReferences: (opener: HTMLElement) => void
}
@@ -229,7 +227,6 @@ export default function FindingEditForm(props: FindingEditFormProps) {
)}
<CitationsHeader
item={props.item}
citationsOpen={props.citationsOpen}
onShowReferences={props.onShowReferences}
/>
{form.error && (
@@ -9,7 +9,6 @@ import { useT } from '@/i18n/useT'
export interface FindingViewProps {
item: FindingItem
readOnly: boolean
citationsOpen: boolean
onEdit: () => void
onDelete: () => 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.
*/
export default function FindingView(props: FindingViewProps) {
const { item, readOnly, citationsOpen } = props
const { item, readOnly } = props
const t = useT()
const edit = useEditCommand()
return (
@@ -75,11 +74,7 @@ export default function FindingView(props: FindingViewProps) {
))}
</div>
<Texts item={item} />
<CitationsHeader
item={item}
citationsOpen={citationsOpen}
onShowReferences={props.onShowReferences}
/>
<CitationsHeader item={item} onShowReferences={props.onShowReferences} />
<FindingActions
item={item}
readOnly={readOnly}
@@ -111,8 +111,6 @@ function EntryTile({
movable={false}
on={{
toggle: () => tiles.toggle(key),
// Never offered: a read-only tile has no « Modifier ».
edit: () => undefined,
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. */
export interface TileHandlers {
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. */
remove?: () => void
/** « 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 ». */
function TileActions({ props }: { props: TileProps }) {
const t = useT()
const { position, count, citers, readOnly, movable, on } = props
if (readOnly) return null
if (props.panel) return <PanelActions props={props} />
if (readOnly || !on.edit) return null
return (
<>
<div className="flex flex-wrap items-center gap-2">
@@ -126,7 +113,7 @@ function TileActions({ props }: { props: TileProps }) {
readOnly={false}
variant="secondary"
size="sm"
onClick={(event) => on.edit(event.currentTarget)}
onClick={(event) => on.edit?.(event.currentTarget)}
>
{t('editor.references.edit')}
</ActionButton>
@@ -113,7 +113,7 @@ type LeaveNav = Pick<
'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 {
return () => {
const { state, closeCitations, references } = latest.current
+1 -1
View File
@@ -85,7 +85,7 @@ export interface EditorPlaceProps {
focus?: FocusRequest
/** The finding dialog and the citations dialog over it (only Constats has them). */
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
/** Bumped by « Tout afficher »: the references library resets its search once per bump. */
libraryReset?: number
+3 -6
View File
@@ -731,17 +731,14 @@ describe('Constats tab', () => {
await user.click(items()[2])
const trigger = () =>
inFindingDialog().getByRole('button', { name: /^1 référence$/ })
expect(trigger()).toHaveAttribute('aria-expanded', 'false')
expect(trigger()).toHaveAttribute('aria-controls', 'editor-citations-panel')
expect(trigger()).toHaveAttribute('aria-haspopup', 'dialog')
expect(trigger()).not.toHaveAttribute('aria-expanded')
await user.click(trigger())
expect(trigger()).toHaveAttribute('aria-expanded', 'true')
const citations = screen
.getByTestId('editor-citations-panel')
.closest('dialog')!
await user.click(within(citations).getByRole('button', { name: 'Fermer' }))
await waitFor(() =>
expect(trigger()).toHaveAttribute('aria-expanded', 'false'),
)
await waitFor(() => expect(trigger()).toHaveFocus())
})
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(hasPanel()).toBe(false)
await select(user, /Node A/)
expect(trigger()).toHaveAttribute('aria-expanded', 'false')
expect(trigger()).toHaveAttribute('aria-controls', 'editor-citations-panel')
expect(trigger()).toHaveAttribute('aria-haspopup', 'dialog')
expect(trigger()).not.toHaveAttribute('aria-expanded')
expect(trigger()).not.toHaveAttribute('aria-controls')
await user.click(trigger())
expect(trigger()).toHaveAttribute('aria-expanded', 'true')
expect(trigger()).not.toHaveAttribute('aria-expanded')
await focusIs(closeButton)
expect(heading()).toHaveAttribute('id', 'editor-citations-title')
expect(citationsDialog()).toHaveAttribute(
@@ -310,7 +311,6 @@ describe.each(MODES)('closing, %s', (_label, reduced) => {
fireEvent.click(backdrop())
await closed()
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 () => {
@@ -393,15 +393,13 @@ describe.each(MODES)('closing, %s', (_label, reduced) => {
})
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()
await openFromFinding(user)
expect(trigger()).toHaveAttribute('aria-expanded', 'true')
await user.click(closeButton())
expect(hasPanel()).toBe(true)
expect(panel().closest('dialog')).toHaveAttribute('inert')
await closed()
expect(trigger()).toHaveAttribute('aria-expanded', 'false')
})
it('a second close during the exit finds no layer and does nothing', async () => {