Loop through focusable els inside a container. Bound to a keydown listener usually.

Parameters:
NameTypeDescription
eKeyboardEvent

The event object from the keyDown/keyUp listener using this.

triggerHTMLElement

The trigger that the user clicked to launch the element using focus loop.

containerHTMLElement

The container the trigger focused.

onEscapefunction

The function to call if the esc key is used.

Since
  • 1.0.0
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();

Requires