mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-27 07:07:31 +00:00
fix(ui): the context menu answers the keyboard and closes when the page moves
The shared context menu closed only on a click elsewhere: Escape did nothing, the arrow keys did nothing, and a scroll left the fixed menu hanging over content that had moved on. It now takes focus on its first item, moves with the arrow keys, and closes on Escape, scroll and resize. rules-of-hooks is an error again; its one hit was a test helper named like a hook.
This commit is contained in:
@@ -114,4 +114,24 @@ describe('ContextMenu', () => {
|
||||
expect(menu.style.left).toBe('192px')
|
||||
expect(menu.style.top).toBe('172px')
|
||||
})
|
||||
|
||||
it('FE-W4CTX-011: Escape, a scroll and a resize close it', () => {
|
||||
const onClose = vi.fn()
|
||||
render(<ContextMenu menu={{ x: 0, y: 0, items: [{ label: 'Open' }] }} onClose={onClose} />)
|
||||
fireEvent.keyDown(document, { key: 'Escape' })
|
||||
fireEvent.scroll(window)
|
||||
fireEvent(window, new Event('resize'))
|
||||
expect(onClose).toHaveBeenCalledTimes(3)
|
||||
})
|
||||
|
||||
it('FE-W4CTX-012: focus starts on the first usable item and the arrow keys move it, wrapping', () => {
|
||||
render(<ContextMenu menu={{ x: 0, y: 0, items: [{ label: 'Off', disabled: true }, { label: 'Open' }, { label: 'Rename' }] }} onClose={() => {}} />)
|
||||
expect(screen.getByRole('button', { name: 'Open' })).toHaveFocus()
|
||||
fireEvent.keyDown(screen.getByRole('button', { name: 'Open' }), { key: 'ArrowDown' })
|
||||
expect(screen.getByRole('button', { name: 'Rename' })).toHaveFocus()
|
||||
fireEvent.keyDown(screen.getByRole('button', { name: 'Rename' }), { key: 'ArrowDown' })
|
||||
expect(screen.getByRole('button', { name: 'Open' })).toHaveFocus()
|
||||
fireEvent.keyDown(screen.getByRole('button', { name: 'Open' }), { key: 'ArrowUp' })
|
||||
expect(screen.getByRole('button', { name: 'Rename' })).toHaveFocus()
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user