How to use the @chakra-ui/utils.isTabbable function in @chakra-ui/utils

To help you get started, weโ€™ve selected a few @chakra-ui/utils examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github chakra-ui / chakra-ui / packages / chakra-ui-hooks / src / useFocusOnHide.tsx View on Github external
React.useEffect(() => {
    const shouldFocus = options.autoFocus && !options.visible;
    if (!shouldFocus) return;

    const element = ref.current;

    // Hide was triggered by a click/focus on a tabbable element outside
    // the dialog or on another dialog. We won't change focus then.
    const preventFocus =
      document.activeElement &&
      element &&
      !element.contains(document.activeElement) &&
      isTabbable(document.activeElement);

    if (preventFocus) return;

    const focusEl = options.focusRef && options.focusRef.current;

    if (focusEl && previouslyVisible && !options.visible) {
      ensureFocus(focusEl);
    }
  }, [
    options.autoFocus,