How to use the reakit-utils/hasFocusWithin.hasFocusWithin function in reakit-utils

To help you get started, we’ve selected a few reakit-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 reakit / reakit / packages / reakit / src / Tabbable / Tabbable.ts View on Github external
(event: React.MouseEvent) => {
        if (options.disabled) {
          event.stopPropagation();
          event.preventDefault();
          return;
        }

        const self = event.currentTarget as HTMLElement;
        const target = event.target as HTMLElement;

        if (isSafariOrFirefoxOnMac && isButton(self) && self.contains(target)) {
          event.preventDefault();
          const isFocusControl =
            isFocusable(target) || target instanceof HTMLLabelElement;
          if (!hasFocusWithin(self) || self === target || !isFocusControl) {
            self.focus();
          }
        }

        if (htmlOnMouseDown) {
          htmlOnMouseDown(event);
        }
      },
      [options.disabled, htmlOnMouseDown]
github reakit / reakit / packages / reakit / src / Rover / Rover.ts View on Github external
React.useEffect(() => {
      if (!ref.current) {
        warning(
          true,
          "[reakit/Rover]",
          "Can't focus rover component because `ref` wasn't passed to component.",
          "See https://reakit.io/docs/rover"
        );
        return;
      }
      if (options.unstable_moves && focused && !hasFocusWithin(ref.current)) {
        ref.current.focus();
      }
    }, [focused, options.unstable_moves]);