NotionX / NotionX/react-notion-x

TypeForm Embed Grabs Focus

Open
#55 1 comment 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
5.4k
Forks
645
PR merge metrics
No merged PRs in 30d

Description

Here is a notion page I am testing with: 130868ef58d949f4add8cf1da983fc16

The page will jump down to give the typeform iframe focus once it loads.
Not sure what the best way to handle this is. Seems like there is no way we can take focus away from the iframe itself since it is controlled by typeform (maybe I'm wrong on this).

One solution I was playing around with was trying to give focus to another element after the iframe loads.

content = (
            <>
              <input style={{position: 'absolute', marginTop: -500}} ref={ref} />
              <iframe
                className='notion-asset-object-fit'
                style={assetStyle}
                src={src}
                title={`iframe ${block.type}`}
                frameBorder='0'
                // TODO: is this sandbox necessary?
                // sandbox='allow-scripts allow-popups allow-top-navigation-by-user-activation allow-forms allow-same-origin'
                allowFullScreen
                // this is important for perf but react's TS definitions don't seem to like it
                loading='lazy'
                onLoad={() => setTimeout(() => ref.current.focus(), 800)}
              />
            </>
          )

This is in components -> asset.tsx

But this is not a great solution because the focus time could depend on the load time or network.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in components/asset.tsx and reproduce the focus jump with the Notion page ID 130868ef58d949f4add8cf1da983fc16. Read the iframe onLoad handling and investigate behavior without relying on the fixed 800ms timeout. Done means the Typeform iframe no longer unexpectedly moves the page focus after loading.

Written by the indexing model from the issue text.

Assessment

Tech stack
react, typescript
Domain
frontend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.