Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix iframe will take away the focus #31

Merged
merged 9 commits into from
Aug 4, 2022
Merged

fix iframe will take away the focus #31

merged 9 commits into from
Aug 4, 2022

Conversation

DiamondThree
Copy link
Contributor

No description provided.

@DiamondThree DiamondThree temporarily deployed to development August 2, 2022 08:20 Inactive
@DiamondThree DiamondThree requested a review from alt1o August 2, 2022 08:26
@DiamondThree DiamondThree temporarily deployed to development August 2, 2022 09:00 Inactive
@DiamondThree DiamondThree temporarily deployed to development August 3, 2022 07:30 Inactive
@lawvs
Copy link
Member

lawvs commented Aug 3, 2022

Hey, I make a simple LazyIframe implement, what do you think?

const LazyIframe = ({
  src,
  delay = 3000,
  fallback,
}: {
  src: string;
  delay?: number;
  fallback?: ReactElement;
}) => {
  const [show, setShow] = useState(false);
  const timer = useRef<number>();

  useEffect(() => {
    // Hide iframe when the src changed
    setShow(false);
  }, [src]);

  const onLoad = () => {
    clearTimeout(timer.current);
    timer.current = setTimeout(() => {
      // Prevent iframe scrolling parent container
      // Remove the delay after the issue is resolved
      // See W3C https://github.com/w3c/csswg-drafts/issues/7134
      // See https://forum.figma.com/t/prevent-figmas-embed-code-from-automatically-scrolling-to-it-on-page-load/26029/6
      setShow(true);
    }, delay);
  };

  return (
    <>
      <iframe
        src={src}
        style={{ display: show ? "block" : "none" }}
        onLoad={onLoad}
      />
      {!show && fallback}
    </>
  );
};

// Usage

<IframeContainer
  onMouseDown={(e) => {
    e.preventDefault();
    e.stopPropagation();
  }}
>
  <LazyIframe src={src} />
</IframeContainer>;

@DiamondThree DiamondThree temporarily deployed to development August 4, 2022 07:26 Inactive
@DiamondThree DiamondThree temporarily deployed to development August 4, 2022 11:01 Inactive
@DiamondThree DiamondThree temporarily deployed to development August 4, 2022 11:01 Inactive
@DiamondThree DiamondThree temporarily deployed to development August 4, 2022 11:10 Inactive
@DiamondThree DiamondThree temporarily deployed to development August 4, 2022 11:10 Inactive
@DiamondThree DiamondThree merged commit 75ebb6a into master Aug 4, 2022
@DiamondThree DiamondThree deleted the bugfix/iframe branch August 4, 2022 14:03
lawvs pushed a commit that referenced this pull request Oct 25, 2022
feat: modify theme mode switch style
@cloudflare-pages
Copy link

Deploying with  Cloudflare Pages  Cloudflare Pages

Latest commit: 19fcdb0
Status:🚫  Build failed.

View logs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants