fix(editor): an overview row tap keeps the focus off body
This commit is contained in:
1 parent
0aa0f6bc62
commit
8b190b4e0d
4 files changed
+73
-16
No files matched your search
@@ -15,7 +15,7 @@ const ROW =
|
|||||||
/** What a row does: a click or Enter selects (A1); Enter on the selected row opens. */
|
/** What a row does: a click or Enter selects (A1); Enter on the selected row opens. */
|
||||||
interface RowActions {
|
interface RowActions {
|
||||||
selectedId: string | null
|
selectedId: string | null
|
||||||
onSelect: (id: string) => void
|
onSelect: (id: string, row: HTMLElement) => void
|
||||||
onOpen: (id: string) => void
|
onOpen: (id: string) => void
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -58,7 +58,9 @@ function Row({
|
|||||||
event.preventDefault()
|
event.preventDefault()
|
||||||
if (!event.repeat) actions.onOpen(annotation.id)
|
if (!event.repeat) actions.onOpen(annotation.id)
|
||||||
}}
|
}}
|
||||||
onClick={() => actions.onSelect(annotation.id)}
|
onClick={(event) =>
|
||||||
|
actions.onSelect(annotation.id, event.currentTarget)
|
||||||
|
}
|
||||||
className={ROW}
|
className={ROW}
|
||||||
>
|
>
|
||||||
<span className="min-w-0 truncate">
|
<span className="min-w-0 truncate">
|
||||||
|
|||||||
@@ -216,16 +216,21 @@ function useHeldHistoryMessage(
|
|||||||
const press = useAnnotationWork((s) => s.historyPress)
|
const press = useAnnotationWork((s) => s.historyPress)
|
||||||
const seen = useRef(press)
|
const seen = useRef(press)
|
||||||
const visible = usePlaceVisible()
|
const visible = usePlaceVisible()
|
||||||
|
// `show` and `t` are rebuilt per render: the effect reads the latest, runs on a new press.
|
||||||
|
const latest = useRef({ message, t, visible })
|
||||||
|
useEffect(() => {
|
||||||
|
latest.current = { message, t, visible }
|
||||||
|
})
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (press === seen.current) return
|
if (press === seen.current) return
|
||||||
seen.current = press
|
seen.current = press
|
||||||
if (press && visible) {
|
const now = latest.current
|
||||||
message.show(t(`editor.history.hold_${press.reason}`), {
|
if (press && now.visible) {
|
||||||
|
now.message.show(now.t(`editor.history.hold_${press.reason}`), {
|
||||||
undo: false,
|
undo: false,
|
||||||
tone: 'info',
|
tone: 'info',
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
// eslint-disable-next-line react-hooks/exhaustive-deps -- show is rebuilt per render
|
|
||||||
}, [press])
|
}, [press])
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -304,9 +309,9 @@ const guarded = (action: () => void) => () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A tool or a view chip, guarded as above. Pressed with the focus still on a handle (Safari
|
* A tool, a view chip or an overview row, guarded as above. Pressed with the focus still on a handle (Safari
|
||||||
* focuses no clicked button), the change unmounts that handle: the focus then lands on the
|
* focuses no clicked button), the change unmounts that handle: the focus then lands on the
|
||||||
* pressed button, where the keyboard's press leaves it, never on `body` (rev 4 M-4).
|
* pressed control, where the keyboard's press leaves it, never on `body` (rev 4 M-4).
|
||||||
*/
|
*/
|
||||||
function guardedPress(button: HTMLElement, action: () => void) {
|
function guardedPress(button: HTMLElement, action: () => void) {
|
||||||
if (!guardDrawing(action)) return
|
if (!guardDrawing(action)) return
|
||||||
@@ -497,12 +502,12 @@ function SidePanel({ scene }: { scene: Scene }) {
|
|||||||
onFilter={(term) => dispatch({ type: 'filter', term })}
|
onFilter={(term) => dispatch({ type: 'filter', term })}
|
||||||
// The column stays shown during a selection (A3): a row or a view that would drop
|
// The column stays shown during a selection (A3): a row or a view that would drop
|
||||||
// a started move or redraw asks first (R-12).
|
// a started move or redraw asks first (R-12).
|
||||||
onSelectView={(id) =>
|
onSelectView={(id, row) =>
|
||||||
guarded(() => dispatch({ type: 'view', viewId: id }))()
|
guardedPress(row, () => dispatch({ type: 'view', viewId: id }))
|
||||||
}
|
}
|
||||||
selectedId={scene.selected?.id ?? null}
|
selectedId={scene.selected?.id ?? null}
|
||||||
onSelectAnnotation={(id) =>
|
onSelectAnnotation={(id, row) =>
|
||||||
guarded(() => dispatch({ type: 'select', id }))()
|
guardedPress(row, () => dispatch({ type: 'select', id }))
|
||||||
}
|
}
|
||||||
onOpenAnnotation={(id) => scene.onOpen(id, 'drawing')}
|
onOpenAnnotation={(id) => scene.onOpen(id, 'drawing')}
|
||||||
onOpenSection={scene.onOpenSection}
|
onOpenSection={scene.onOpenSection}
|
||||||
|
|||||||
@@ -32,10 +32,11 @@ export interface OverviewPanelProps {
|
|||||||
/** The « Filtrer par nom » term, held by the parent so a selection does not lose it. */
|
/** The « Filtrer par nom » term, held by the parent so a selection does not lose it. */
|
||||||
filter: string
|
filter: string
|
||||||
onFilter: (term: string) => void
|
onFilter: (term: string) => void
|
||||||
onSelectView: (viewId: string) => void
|
/** `row` is the pressed row: the focus may land on it (Safari, see `guardedPress`). */
|
||||||
|
onSelectView: (viewId: string, row: HTMLElement) => void
|
||||||
/** The selection, marked in the list (A3). */
|
/** The selection, marked in the list (A3). */
|
||||||
selectedId: string | null
|
selectedId: string | null
|
||||||
onSelectAnnotation: (annotationId: string) => void
|
onSelectAnnotation: (annotationId: string, row: HTMLElement) => void
|
||||||
/** Enter on the selected row: its properties dialog (A1). */
|
/** Enter on the selected row: its properties dialog (A1). */
|
||||||
onOpenAnnotation: (annotationId: string) => void
|
onOpenAnnotation: (annotationId: string) => void
|
||||||
onOpenSection: (section: AnnotationSection, opener: HTMLElement) => void
|
onOpenSection: (section: AnnotationSection, opener: HTMLElement) => void
|
||||||
@@ -71,7 +72,7 @@ function ViewRow({
|
|||||||
view: SheetView
|
view: SheetView
|
||||||
current: boolean
|
current: boolean
|
||||||
count: number
|
count: number
|
||||||
onSelect: () => void
|
onSelect: (row: HTMLElement) => void
|
||||||
}) {
|
}) {
|
||||||
const t = useT()
|
const t = useT()
|
||||||
const plural = usePlural()
|
const plural = usePlural()
|
||||||
@@ -81,7 +82,7 @@ function ViewRow({
|
|||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
aria-current={current}
|
aria-current={current}
|
||||||
onClick={onSelect}
|
onClick={(event) => onSelect(event.currentTarget)}
|
||||||
className={`${ROW} ${current ? 'bg-[var(--color-surface-strong)]' : ''}`}
|
className={`${ROW} ${current ? 'bg-[var(--color-surface-strong)]' : ''}`}
|
||||||
>
|
>
|
||||||
<span className="min-w-0">
|
<span className="min-w-0">
|
||||||
@@ -121,7 +122,7 @@ function ViewsCard(props: OverviewPanelProps) {
|
|||||||
view={view}
|
view={view}
|
||||||
current={view.id === viewId}
|
current={view.id === viewId}
|
||||||
count={counts.annotationsByView.get(view.id) ?? 0}
|
count={counts.annotationsByView.get(view.id) ?? 0}
|
||||||
onSelect={() => onSelectView(view.id)}
|
onSelect={(row) => onSelectView(view.id, row)}
|
||||||
/>
|
/>
|
||||||
))}
|
))}
|
||||||
</ul>
|
</ul>
|
||||||
|
|||||||
@@ -1402,6 +1402,55 @@ describe('Safari: the focus after a press that commits a pending series', () =>
|
|||||||
expect(document.activeElement).toBe(chip)
|
expect(document.activeElement).toBe(chip)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('a press on another annotation row commits with the focus kept, then focuses the row', async () => {
|
||||||
|
// A point has no vertex handle: selecting it unmounts the focused vertex.
|
||||||
|
const other = insert(squareText(), point('y', 50, 50, 1))
|
||||||
|
await mount(other)
|
||||||
|
await select()
|
||||||
|
clickHandle('Sommet 1 de N', [20, 20])
|
||||||
|
act(() => vertex(1).focus())
|
||||||
|
fireEvent.keyDown(vertex(1), { key: 'ArrowRight' })
|
||||||
|
const held = vertex(1)
|
||||||
|
const seen = watchCommitFocus()
|
||||||
|
const list = screen.getByRole('list', { name: 'Annotations de la vue' })
|
||||||
|
const row = within(list)
|
||||||
|
.getAllByRole('button')
|
||||||
|
.find((button) => button.getAttribute('aria-current') !== 'true')!
|
||||||
|
fireEvent.click(row)
|
||||||
|
expect(pointsOf('z')![0]).toEqual([20.5, 20])
|
||||||
|
expect(seen[0]).toBe(held)
|
||||||
|
expect(row).toHaveAttribute('aria-current', 'true')
|
||||||
|
expect(document.activeElement).toBe(row)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('a press on a view row commits with the focus kept, then focuses the row', async () => {
|
||||||
|
const detail = insert(squareText(), {
|
||||||
|
kind: 'view',
|
||||||
|
value: {
|
||||||
|
kind: 'detail',
|
||||||
|
id: 'view-det',
|
||||||
|
name: { fr: 'Tête', en: 'Head' },
|
||||||
|
svg_asset_id: null,
|
||||||
|
view_box: { min_x: 10, min_y: 10, width: 80, height: 80 },
|
||||||
|
parent_view_id: 'view-main',
|
||||||
|
},
|
||||||
|
})
|
||||||
|
await mount(detail)
|
||||||
|
await select()
|
||||||
|
clickHandle('Sommet 1 de N', [20, 20])
|
||||||
|
act(() => vertex(1).focus())
|
||||||
|
fireEvent.keyDown(vertex(1), { key: 'ArrowRight' })
|
||||||
|
const held = vertex(1)
|
||||||
|
const seen = watchCommitFocus()
|
||||||
|
const card = screen.getByRole('region', { name: 'Vues' })
|
||||||
|
const row = within(card).getByRole('button', { name: /Tête/ })
|
||||||
|
fireEvent.click(row)
|
||||||
|
expect(pointsOf('z')![0]).toEqual([20.5, 20])
|
||||||
|
expect(seen[0]).toBe(held)
|
||||||
|
expect(row).toHaveAttribute('aria-current', 'true')
|
||||||
|
expect(document.activeElement).toBe(row)
|
||||||
|
})
|
||||||
|
|
||||||
it('« Déplacer le sommet » focuses the first arrow', async () => {
|
it('« Déplacer le sommet » focuses the first arrow', async () => {
|
||||||
await keyedVertex()
|
await keyedVertex()
|
||||||
fireEvent.click(screen.getByRole('button', { name: 'Déplacer le sommet' }))
|
fireEvent.click(screen.getByRole('button', { name: 'Déplacer le sommet' }))
|
||||||
|
|||||||
Reference in new issue
Block a user