fix(app): keep the access list open on a blur without target

This commit is contained in:
bchanot committed 2026-11-23 10:40:40 +01:00
1 parent 03b5041a53
commit 224d1051b2
2 files changed
+28 -2

No files matched your search

@@ -115,8 +115,10 @@ function MoreViews({ box, areaHeight, items, onActivate }: MoreProps) {
}, [open])
const onBlur = (event: FocusEvent) => {
// A null target is no exit: Safari gives a tapped button no focus. A press outside
// is closed by the document listener.
const next = event.relatedTarget
if (!(next instanceof Node && root.current?.contains(next))) setOpen(false)
if (next instanceof Node && !root.current?.contains(next)) setOpen(false)
}
const onKeyDown = (event: KeyboardEvent) => {
@@ -1,6 +1,6 @@
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
import { useRef } from 'react'
import { render, screen, within } from '@testing-library/react'
import { fireEvent, render, screen, within } from '@testing-library/react'
import userEvent from '@testing-library/user-event'
import ModalDialog from '@/components/ui/ModalDialog'
import AccessLabels from '@/components/canvas/AccessLabels'
@@ -251,6 +251,30 @@ describe('AccessLabels, « Autres vues »', () => {
expect(screen.queryAllByRole('listitem')).toHaveLength(0)
})
it('still activates an item after a blur without a related target', async () => {
overflowing()
const onActivate = vi.fn()
render(<Harness ids={['a1', 'a2', 'a3']} onActivate={onActivate} />)
const more = screen.getByRole('button', { name: 'Autres vues (3)' })
await userEvent.click(more)
fireEvent.blur(more, { relatedTarget: null })
await userEvent.click(within(screen.getAllByRole('listitem')[1]).getByRole('button'))
expect(onActivate).toHaveBeenCalledWith('a2', 'view-a2')
})
it('keeps the list open while the focus moves inside it', async () => {
overflowing()
render(<Harness ids={['a1', 'a2', 'a3']} />)
const more = screen.getByRole('button', { name: 'Autres vues (3)' })
await userEvent.click(more)
await userEvent.tab()
await userEvent.tab()
await userEvent.tab({ shift: true })
await userEvent.tab({ shift: true })
expect(more).toHaveFocus()
expect(screen.getAllByRole('listitem')).toHaveLength(3)
})
it('closes on a press outside', async () => {
overflowing()
render(<Harness ids={['a1', 'a2', 'a3']} />)