fix(editor): gesture line alerts, focus after « Défaire », hit area
Final review M-3, M-4, M-5, M-8. - M-3: the line and the strip render a refusal's role="alert" beside their always-mounted role="status" region, never inside it; every shown message carries a serial that keys its pill, so a repeated identical refusal is a new pill and is announced again. - M-4: after the line's « Défaire » the focus goes to the canvas box. - M-5: « Défaire » gets a transparent ::before, 44 px tall below xl (36 px from xl), within the row's reserved 44 px: the pill keeps its 36 px. The A14 e2e checks the hit area at 1024, 1180, 1280 px. - M-8: the « swallows the click on a marker » test fired a click the canvas ignores since T2; the inert click is dropped, the title says what the taps prove. Tests rewritten: « the message sits on its own row »: role="status" on the row → a role="status" region inside the row, empty at rest. « a mouse tap deselects … swallows the click »: the final fireEvent.click on the marker removed (inert), its isDeselected assertion kept after the second tap.
This commit is contained in:
1 parent
e299c3d4f6
commit
13e2503e6a
5 files changed
+143
-28
No files matched your search
@@ -416,6 +416,30 @@ test.describe('editor annotations (A3)', () => {
|
||||
.first()
|
||||
.evaluate((span) => span.scrollWidth > span.clientWidth)
|
||||
expect(cut, 'the message is cut short').toBe(false)
|
||||
// M-5: « Défaire » answers 44 px tall below xl (36 px from xl), the pill unchanged.
|
||||
const reach = width < 1280 ? 44 : 36
|
||||
const hit = await line(page)
|
||||
.getByRole('button', { name: dict['editor.history.undo_title'] })
|
||||
.evaluate(
|
||||
(button, half) => {
|
||||
const box = button.getBoundingClientRect()
|
||||
const x = box.left + box.width / 2
|
||||
const mid = box.top + box.height / 2
|
||||
const at = (dy: number) => document.elementFromPoint(x, mid + dy)
|
||||
const pill = button.closest('[data-testid="gesture-message"]')!
|
||||
return {
|
||||
top: at(-half) === button,
|
||||
bottom: at(half) === button,
|
||||
pill: pill.getBoundingClientRect().height,
|
||||
}
|
||||
},
|
||||
reach / 2 - 1,
|
||||
)
|
||||
expect(hit, `a ${reach} px hit area at ${width} px`).toEqual({
|
||||
top: true,
|
||||
bottom: true,
|
||||
pill: 36,
|
||||
})
|
||||
// Its expiry, 6 s later.
|
||||
await expectNoShift(page, async () => {
|
||||
await page.clock.fastForward(6_100)
|
||||
|
||||
@@ -42,12 +42,12 @@ export default function EditStrip({
|
||||
className="flex h-16 items-center gap-3 overflow-hidden rounded-xl border border-[var(--color-border)] bg-[var(--color-surface)] px-3"
|
||||
>
|
||||
<Lead lead={lead} />
|
||||
<div
|
||||
data-testid="edit-strip-notice"
|
||||
role="status"
|
||||
className="min-w-0 flex-1"
|
||||
>
|
||||
{notice && <Notice notice={notice} />}
|
||||
<div data-testid="edit-strip-notice" className="min-w-0 flex-1">
|
||||
{/* M-3: the polite region always mounted; an alert beside it, never inside. */}
|
||||
<div role="status">
|
||||
{notice && !alerts(notice) && <Notice notice={notice} />}
|
||||
</div>
|
||||
{notice && alerts(notice) && <Notice notice={notice} />}
|
||||
</div>
|
||||
<div key={commandsKey} className="flex shrink-0 items-center gap-2 p-1">
|
||||
{commands}
|
||||
@@ -91,11 +91,14 @@ function Lead({ lead }: { lead: StripLead }) {
|
||||
)
|
||||
}
|
||||
|
||||
/** A refusal not already announced by the gesture line. */
|
||||
const alerts = (notice: StripNotice) => notice.tone === 'error' && !notice.quiet
|
||||
|
||||
function Notice({ notice }: { notice: StripNotice }) {
|
||||
const error = notice.tone === 'error'
|
||||
return (
|
||||
<p
|
||||
role={error && !notice.quiet ? 'alert' : undefined}
|
||||
role={alerts(notice) ? 'alert' : undefined}
|
||||
aria-hidden={notice.quiet || undefined}
|
||||
className={`flex min-w-0 items-start gap-1 text-xs ${
|
||||
error
|
||||
|
||||
@@ -1,28 +1,45 @@
|
||||
import type { ReactNode } from 'react'
|
||||
import { useEditorReadOnly } from '@/editor/editingContext'
|
||||
import type { GestureMessages } from '@/editor/annotations/useGestureMessage'
|
||||
import { visibleElement } from '@/editor/focusRequest'
|
||||
import type {
|
||||
GestureMessage as Shown,
|
||||
GestureMessages,
|
||||
} from '@/editor/annotations/useGestureMessage'
|
||||
import { canUndo, useEditorStore } from '@/editor/state/editorStore'
|
||||
import {
|
||||
cancelPending,
|
||||
useAnnotationWork,
|
||||
} from '@/editor/annotations/workStore'
|
||||
import { CANVAS_BOX } from '@/editor/useEditorNavigation'
|
||||
import { useT } from '@/i18n/useT'
|
||||
|
||||
const PILL =
|
||||
'inline-flex h-9 max-w-full items-center gap-2 rounded-md px-3 text-sm'
|
||||
|
||||
/**
|
||||
* « Défaire » keeps the pill's height: a transparent box around its text gives the 44 px
|
||||
* hit area below `xl` (36 px from `xl`), inside the row's reserved 44 px (M-5).
|
||||
*/
|
||||
const UNDO =
|
||||
'relative shrink-0 font-semibold underline-offset-2 hover:underline ' +
|
||||
"before:absolute before:-inset-x-2 before:-inset-y-3 before:content-[''] " +
|
||||
'xl:before:-inset-y-2'
|
||||
|
||||
/** The header's undo (T15): the same store step, under the same conditions (R-13 first). */
|
||||
function undoLast(readOnly: boolean): void {
|
||||
const store = useEditorStore.getState()
|
||||
if (readOnly || cancelPending()) return
|
||||
if (canUndo(store)) store.undoStep()
|
||||
if (readOnly || cancelPending() || !canUndo(store)) return
|
||||
store.undoStep()
|
||||
// M-4: the undo closes the pill under the focus; the drawing takes it (WCAG 2.4.3).
|
||||
visibleElement(CANVAS_BOX)?.focus()
|
||||
}
|
||||
|
||||
/**
|
||||
* Under the drawing (A14, R-2): the add buttons, then the message on a row of its own, the
|
||||
* drawing column's full width, one line truncated. The row is always there at a fixed
|
||||
* height, so a message showing or leaving moves nothing. The status region (polite) is
|
||||
* always mounted; a refusal is an alert of its own (its full text is also in the strip).
|
||||
* always mounted and holds the other messages; a refusal is an alert of its own beside
|
||||
* it, never inside it (M-3; its full text is also in the strip).
|
||||
*/
|
||||
export default function GestureMessage({
|
||||
messages,
|
||||
@@ -31,52 +48,65 @@ export default function GestureMessage({
|
||||
messages: GestureMessages
|
||||
children: ReactNode
|
||||
}) {
|
||||
const { message } = messages
|
||||
const error = message?.tone === 'error'
|
||||
return (
|
||||
<>
|
||||
{children}
|
||||
<div
|
||||
data-testid="gesture-line"
|
||||
role="status"
|
||||
className="flex h-11 items-center justify-end overflow-hidden px-1"
|
||||
>
|
||||
<Message messages={messages} />
|
||||
<div role="status" className="flex min-w-0 justify-end">
|
||||
{message && !error && (
|
||||
<Message key={message.serial} messages={messages} shown={message} />
|
||||
)}
|
||||
</div>
|
||||
{message && error && (
|
||||
<Message key={message.serial} messages={messages} shown={message} />
|
||||
)}
|
||||
</div>
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
||||
function Message({ messages }: { messages: GestureMessages }) {
|
||||
/**
|
||||
* One pill. Each message is another pill (keyed by its serial): a wider one replacing it
|
||||
* moves no box (A14), and a repeated refusal is announced again (M-3).
|
||||
*/
|
||||
function Message({
|
||||
messages,
|
||||
shown,
|
||||
}: {
|
||||
messages: GestureMessages
|
||||
shown: Shown
|
||||
}) {
|
||||
const t = useT()
|
||||
const readOnly = useEditorReadOnly()
|
||||
// A12: « Défaire » is hidden during a creation; the message itself stays.
|
||||
const creating = useAnnotationWork((s) => s.creation !== null)
|
||||
const { message, hold } = messages
|
||||
if (!message) return null
|
||||
const error = message.tone === 'error'
|
||||
const { stamp } = message
|
||||
const error = shown.tone === 'error'
|
||||
return (
|
||||
<p
|
||||
// Another message is another pill: a wider one replacing it moves no box (A14).
|
||||
key={`${message.text}|${stamp.undo}|${stamp.redo}|${stamp.text.length}`}
|
||||
data-testid="gesture-message"
|
||||
role={error ? 'alert' : undefined}
|
||||
{...hold}
|
||||
{...messages.hold}
|
||||
className={`${PILL} ${
|
||||
error
|
||||
? 'bg-[var(--color-danger-strong)] text-white'
|
||||
: 'bg-[var(--color-ink)] text-[var(--color-bg)]'
|
||||
}`}
|
||||
>
|
||||
<span className="truncate" title={message.text}>
|
||||
{message.text}
|
||||
<span className="truncate" title={shown.text}>
|
||||
{shown.text}
|
||||
</span>
|
||||
{message.undo && !error && !creating && (
|
||||
{shown.undo && !error && !creating && (
|
||||
<>
|
||||
<span aria-hidden="true">·</span>
|
||||
<button
|
||||
type="button"
|
||||
aria-label={t('editor.history.undo_title')}
|
||||
className="shrink-0 font-semibold underline-offset-2 hover:underline"
|
||||
className={UNDO}
|
||||
onClick={() => undoLast(readOnly)}
|
||||
>
|
||||
{t('editor.history.undo')}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import {
|
||||
useCallback,
|
||||
useEffect,
|
||||
useRef,
|
||||
useState,
|
||||
type FocusEvent,
|
||||
type PointerEvent,
|
||||
@@ -26,6 +27,11 @@ export interface GestureMessage {
|
||||
undo: boolean
|
||||
hint: boolean
|
||||
stamp: Stamp
|
||||
/**
|
||||
* Counts every message shown: a repeated identical refusal changes no document, yet it
|
||||
* is a new pill and is announced again (M-3).
|
||||
*/
|
||||
serial: number
|
||||
/** The place the core refused, drawn in red dashes while the refusal shows. */
|
||||
place: Geometry | null
|
||||
}
|
||||
@@ -103,6 +109,7 @@ export function useGestureMessage() {
|
||||
[],
|
||||
)
|
||||
useCloseOnChange(close)
|
||||
const serial = useRef(0)
|
||||
useEffect(() => {
|
||||
if (!message || held) return
|
||||
const timer = setTimeout(
|
||||
@@ -118,6 +125,7 @@ export function useGestureMessage() {
|
||||
undo,
|
||||
hint: false,
|
||||
stamp: currentStamp(),
|
||||
serial: ++serial.current,
|
||||
place: place ?? null,
|
||||
})
|
||||
const hint = (text: string) => {
|
||||
@@ -128,6 +136,7 @@ export function useGestureMessage() {
|
||||
undo: false,
|
||||
hint: true,
|
||||
stamp: currentStamp(),
|
||||
serial: ++serial.current,
|
||||
place: null,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -1552,13 +1552,14 @@ describe('a tap on the drawing (D6b)', () => {
|
||||
expect(isDeselected()).toBe(false)
|
||||
})
|
||||
|
||||
it('a mouse tap deselects at the pointer-up and swallows the click on a marker', async () => {
|
||||
// Final review M-8: since T2 a `click` on the canvas does nothing, so the click this test
|
||||
// fired on a marker could not change the outcome; it is gone, the taps are the test.
|
||||
it('a mouse tap deselects at the pointer-up; another tap on the empty drawing keeps it so', async () => {
|
||||
await selected({ text: insert(text(), named('anno-b', 90, 90, 3)) })
|
||||
tap(rect(), { upOn: rect() })
|
||||
expect(isDeselected()).toBe(true)
|
||||
fireEvent.pointerDown(rect(), { ...init(), clientX: 10, clientY: 10 })
|
||||
fireEvent.pointerUp(rect(), { ...init(), clientX: 10, clientY: 10 })
|
||||
fireEvent.click(marker('anno-b'))
|
||||
expect(isDeselected()).toBe(true)
|
||||
})
|
||||
|
||||
@@ -1841,7 +1842,55 @@ describe('the strip', () => {
|
||||
const add = screen.getByRole('button', { name: 'Ajouter un point' })
|
||||
expect(line()).not.toContainElement(add)
|
||||
expect(line()).toHaveClass('h-11', 'overflow-hidden')
|
||||
expect(line()).toHaveAttribute('role', 'status')
|
||||
// M-3: the polite region is inside the row, always mounted, empty at rest.
|
||||
expect(within(line()).getByRole('status')).toBeEmptyDOMElement()
|
||||
})
|
||||
|
||||
it('M-3: a refusal is an alert outside any status region, in the line and the strip', async () => {
|
||||
await mount()
|
||||
await selectFromList()
|
||||
drag(marker('anno-a'), [98, 50])
|
||||
const alert = within(line()).getByRole('alert')
|
||||
expect(alert.closest('[role="status"]')).toBeNull()
|
||||
render(
|
||||
<EditStrip
|
||||
lead={{ title: 'T', detail: 'Zone', icon: 'zone' }}
|
||||
notice={{ tone: 'error', text: 'Problème' }}
|
||||
commands={null}
|
||||
/>,
|
||||
)
|
||||
const strip = screen.getAllByTestId('edit-strip-notice').at(-1)!
|
||||
const issue = within(strip).getByRole('alert')
|
||||
expect(issue.closest('[role="status"]')).toBeNull()
|
||||
expect(within(strip).getByRole('status')).toBeEmptyDOMElement()
|
||||
})
|
||||
|
||||
it('M-3: the same refusal twice is a new pill, announced again', async () => {
|
||||
await mount()
|
||||
await selectFromList()
|
||||
drag(marker('anno-a'), [98, 50])
|
||||
const first = within(line()).getByRole('alert')
|
||||
drag(marker('anno-a'), [98, 50])
|
||||
const second = within(line()).getByRole('alert')
|
||||
expect(second).toHaveTextContent(first.textContent!)
|
||||
expect(second).not.toBe(first)
|
||||
})
|
||||
|
||||
it("M-4: after the line's « Défaire » the focus is on the drawing, not lost", async () => {
|
||||
await mount()
|
||||
await selectFromList()
|
||||
drag(marker('anno-a'), [60, 40])
|
||||
const undo = within(line()).getByRole('button', {
|
||||
name: 'Défaire la dernière modification',
|
||||
})
|
||||
await userEvent.setup().click(undo)
|
||||
expect(line()).not.toHaveTextContent('Point déplacé')
|
||||
expect(document.activeElement).toBe(
|
||||
document.querySelector(
|
||||
'[data-place="annotations.drawing"] [role="group"][tabindex="0"]',
|
||||
),
|
||||
)
|
||||
expect(document.activeElement).not.toBe(document.body)
|
||||
})
|
||||
|
||||
it('an undo then a redo never brings the message back', async () => {
|
||||
|
||||
Reference in new issue
Block a user