How to use the reakit-utils/closest.closest 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 / Menu / __utils / useShortcuts.ts View on Github external
const onKeyDown = (event: KeyboardEvent) => {
      if (event.metaKey || event.altKey || event.shiftKey || event.ctrlKey) {
        return;
      }
      const target = event.target as HTMLElement;
      const role = target.getAttribute("role");
      const targetIsMenu = target === menu;
      const targetIsMenuItem =
        role &&
        role.indexOf("menuitem") >= 0 &&
        closest(target, "[role=menu],[role=menubar]") === menu;

      if (!targetIsMenu && !targetIsMenuItem) return;

      if (/^[a-z0-9_-]$/i.test(event.key)) {
        event.stopPropagation();
        event.preventDefault();
        setKeys(k => `${k}${event.key}`);
      }
    };
github reakit / reakit / packages / reakit / src / Dialog / __utils / usePortalRef.ts View on Github external
React.useEffect(() => {
    const dialog = dialogRef.current;
    if (!dialog || !options.visible) return;
    portalRef.current = closest(dialog, Portal.__selector) as HTMLElement;
  }, [dialogRef, options.visible]);