werkbank
    Preparing search index...

    Function useFocusTrap

    • Traps focus within a specified element.

      Type Parameters

      • T extends HTMLElement

        The HTML element type.

      Parameters

      • trapFocus: boolean

        If the focus trap should be active or not

      Returns RefObject<T | null>

      This hook ensures that focus remains within the given element when navigating with the keyboard (Tab/Shift+Tab). It also restores focus to the last focused element within the trap if focus is lost.

      const ref = useFocusTrap(true);
      return <div ref={ref}>...</div>;