How to use the @react-md/utils.useScrollLock 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 / documentation / src / components / Layout / Combined.tsx View on Github external
if (visible !== isDesktop) {
      setVisible(isDesktop);
    }
    // disabled since only want to update on media changes
    // eslint-disable-next-line react-hooks/exhaustive-deps
  }, [isDesktop, isTablet, isPhone]);

  useEffect(() => {
    if (visible && !inline) {
      setVisible(false);
    }
    // disabled since only want to run on pathname changes
    // eslint-disable-next-line react-hooks/exhaustive-deps
  }, [router.pathname]);

  useScrollLock(visible && isPhone);
  let title = propTitle;
  if (propTitle.includes(" - ")) {
    title = title.substring(title.indexOf(" - ") + 3);
    if (isPhone && !router.pathname.includes("/packages/")) {
      const i = title.lastIndexOf("- ");
      if (i !== -1) {
        title = title.substring(i + 2);
      }
    }
  }

  // this makes it so that the SkipToMainContent button can still
  // focus the `<main>` element, but the `<main>` will no longer be
  // focused if the user clicks inside. This is super nice since one
  // of my bigger patterns is to click somewhere then press tab to
  // focus a specific element. Without this fix, the first element in</main></main>
github mlaursen / react-md / packages / dialog / src / Dialog.tsx View on Github external
onKeyDown,
    ...props
  } = providedProps as WithDefaultProps;
  const { id } = props;
  const isNoneRole = role === "none";
  const isFullPage = type === "full-page";
  const isCentered = type === "centered";

  const { disableOverlay, disableEscapeClose } = useNestedDialogFixes({
    id,
    visible,
    disabled: disableNestedDialogFixes,
    disableEscapeClose: propDisableEscapeClose,
  });

  useScrollLock(visible &amp;&amp; !isNoneRole &amp;&amp; !disableScrollLock);

  let overlayEl: ReactNode = null;
  if (typeof propOverlay === "boolean" ? propOverlay : !isFullPage) {
    // do not add the portal props to the overlay element since the portalling
    // is handled in here. With how portals work, this would be rendered **after**
    // the dialog instead of before which breaks some dialog styles
    overlayEl = (
github mlaursen / react-md / packages / documentation / components / Layout / Combined.tsx View on Github external
if (visible !== isDesktop) {
      setVisible(isDesktop);
    }
    // disabled since only want to update on media changes
    // eslint-disable-next-line react-hooks/exhaustive-deps
  }, [isDesktop, isTablet, isPhone]);

  useEffect(() =&gt; {
    if (visible &amp;&amp; !inline) {
      setVisible(false);
    }
    // disabled since only want to run on pathname changes
    // eslint-disable-next-line react-hooks/exhaustive-deps
  }, [router.pathname]);

  useScrollLock(visible &amp;&amp; isPhone);
  let title = propTitle;
  if (propTitle.includes(" - ")) {
    title = title.substring(title.indexOf(" - ") + 3);
    if (isPhone &amp;&amp; !router.pathname.includes("/packages/")) {
      const i = title.lastIndexOf("- ");
      if (i !== -1) {
        title = title.substring(i + 2);
      }
    }
  }

  // this makes it so that the SkipToMainContent button can still
  // focus the `<main>` element, but the `<main>` will no longer be
  // focused if the user clicks inside. This is super nice since one
  // of my bigger patterns is to click somewhere then press tab to
  // focus a specific element. Without this fix, the first element in</main></main>