svogg-components 0.5.4

focusTrap

typescript
import { focusTrap } from 'svogg-components';

Utility for trapping focus within an element. Good for e.g. drawers and modals. On mount, focuses the first focusable element by default.


Try moving focus by tabbing inside of the card in the demo and see how focus never breaks out of the element.

Keyboard navigation

  1. Tab
    1. Moves focus to next focusable child element.
    2. If the last focusable element has focus, moves focus to the first focusable child element.
  2. Shift + Tab
    1. Moves focus to previous focusable child element.
    2. If the first focusable element has focus, moves focus to the last focusable child element.