loopFocus()function
loopFocus(element: Nullish<Element>, nextTarget: Nullish<Element>): void
| Param | Type | |
|---|---|---|
element | Nullish<Element> | The container to keep focus within. required |
nextTarget | Nullish<Element> | The element focus is moving to. required |
Loop focus inside an element so it can't escape — refocus the first focusable child when focus moves out.
- When
nextTargetfalls outsideelement, focus is pulled back to the first focusable element inside it (a simple focus trap).
Examples
loopFocus(dialog, document.activeElement);