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
@@ -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,
|
||||
})
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user