Skip to main content

toHaveFocusLock()

Experimental

When an element creates a focus lock, the following should be true:

Tab: Moves focus to the next tabbable element inside the dialog. If focus is on the last tabbable element inside the dialog, moves focus to the first tabbable element inside the dialog.

Shift + Tab: Moves focus to the previous tabbable element inside the dialog. If focus is on the first tabbable element inside the dialog, moves focus to the last tabbable element inside the dialog.

Keyboard Trap

https://www.w3.org/TR/UNDERSTANDING-WCAG20/keyboard-operation-trapping.html

Usage

Syntax

import { render, screen } from '@testing-library/react'

test('dialog', () => {
render(
<div data-testid="trap">
<button id="1">1</button>
<button onKeyUp={...key up handler}>2</button>
</div>,
)

expect(screen.getByTestId('trap')).toHaveFocusLock()
})