Loop through focusable els inside a container. Bound to a keydown listener usually.
Parameters:
Name | Type | Description |
---|---|---|
e | KeyboardEvent | The event object from the keyDown/keyUp listener using this. |
trigger | HTMLElement | The trigger that the user clicked to launch the element using focus loop. |
container | HTMLElement | The container the trigger focused. |
onEscape | function | The function to call if the esc key is used. |
- Since
- 1.0.0
- Source
Returns:
- Type:
- void
Example
import { focusLoop } from "@gravityforms/utils";
const exampleContainer = document.getElementById( 'example-container' );
const exampleTrigger = document.getElementById( 'example-trigger' );
closeExample = () => {
// close the container.
}
handleKeyEvents = ( e ) =>
focusLoop(
e,
exampleTrigger,
exampleContainer,
closeExample
);
bindEvents = () => {
exampleContainer.addEventListener( 'keydown', handleKeyEvents );
};
bindEvents();