How to use the @react-md/utils.useEventListener function in @react-md/utils

To help you get started, we’ve selected a few @react-md/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 mlaursen / react-md / packages / wia-aria / src / keyboard / KeyboardTracker.tsx View on Github external
}
  }

  function enableKeyboardMode() {
    if (!isKeyboardMode) {
      setKeyboardMode(true);
    }
  }

  useEventListener("mousedown", reset, {
    shouldUpdate: [focusedId === null, isKeyboardMode],
  });
  useEventListener("keydown", enableKeyboardMode, {
    shouldUpdate: [isKeyboardMode],
  });
  useEventListener(
    "focus",
    (event: FocusEvent) => {
      const target = event.target as Maybe;
      if (isKeyboardMode && target && target.id !== focusedId) {
        setFocusedId(target.id);
      }
    },
    {
      enabled: isKeyboardMode,
      capture: true,
      shouldUpdate: [isKeyboardMode, focusedId],
    }
  );

  useEventListener(
    "keyup",
github mlaursen / react-md / packages / wia-aria / src / keyboard / KeyboardTracker.tsx View on Github external
if (isKeyboardMode) {
      setKeyboardMode(false);
    }

    if (focusedId !== null) {
      setFocusedId(null);
    }
  }

  function enableKeyboardMode() {
    if (!isKeyboardMode) {
      setKeyboardMode(true);
    }
  }

  useEventListener("mousedown", reset, {
    shouldUpdate: [focusedId === null, isKeyboardMode],
  });
  useEventListener("keydown", enableKeyboardMode, {
    shouldUpdate: [isKeyboardMode],
  });
  useEventListener(
    "focus",
    (event: FocusEvent) => {
      const target = event.target as Maybe;
      if (isKeyboardMode && target && target.id !== focusedId) {
        setFocusedId(target.id);
      }
    },
    {
      enabled: isKeyboardMode,
      capture: true,
github mlaursen / react-md / packages / wia-aria / src / hooks / useKeyboardFocusEffect.ts View on Github external
}
      }
    }

    if (nextIndex !== -1) {
      event.preventDefault();
      const el = focusableElements[nextIndex];
      if (onFocus) {
        onFocus(el, nextIndex, focusableElements);
      } else {
        focusableElements[nextIndex].focus();
      }
    }
  }

  useEventListener("keydown", handleKeyDown, {
    capture: true,
    enabled: !disabled,
    shouldUpdate: [container, focusableElements],
  });
}
github mlaursen / react-md / packages / wia-aria / src / keyboard / KeyboardTracker.tsx View on Github external
useEventListener(
    "focus",
    (event: FocusEvent) => {
      const target = event.target as Maybe;
      if (isKeyboardMode && target && target.id !== focusedId) {
        setFocusedId(target.id);
      }
    },
    {
      enabled: isKeyboardMode,
      capture: true,
      shouldUpdate: [isKeyboardMode, focusedId],
    }
  );

  useEventListener(
    "keyup",
    (event: KeyboardEvent) => {
      const target = event.target as Maybe;
      if (
        !target ||
        (target as HTMLElement | Window) === window ||
        event.key !== "Tab"
      ) {
        return;
      } else if (!target.id) {
        if (
          target.tagName !== "A" &&
          !disableUntrackableWarning &&
          process.env.NODE_ENV !== "production" &&
          !DEBUG_SET.has(target)
        ) {
github mlaursen / react-md / packages / wia-aria / src / keyboard / KeyboardTracker.tsx View on Github external
if (focusedId !== null) {
      setFocusedId(null);
    }
  }

  function enableKeyboardMode() {
    if (!isKeyboardMode) {
      setKeyboardMode(true);
    }
  }

  useEventListener("mousedown", reset, {
    shouldUpdate: [focusedId === null, isKeyboardMode],
  });
  useEventListener("keydown", enableKeyboardMode, {
    shouldUpdate: [isKeyboardMode],
  });
  useEventListener(
    "focus",
    (event: FocusEvent) => {
      const target = event.target as Maybe;
      if (isKeyboardMode && target && target.id !== focusedId) {
        setFocusedId(target.id);
      }
    },
    {
      enabled: isKeyboardMode,
      capture: true,
      shouldUpdate: [isKeyboardMode, focusedId],
    }
  );