Skip to content

[Portal] renders children on a detached DOM node causing measuring and autoFocus to fail #1809

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

Closed
Swiftwork opened this issue Jan 19, 2022 · 5 comments

Comments

@Swiftwork
Copy link
Contributor

Describe the bug
The current way the Portal is written, mounts its children on a detached node. This causes children that need to use autoFocus or measure themselves to fail.

To Reproduce
Steps to reproduce the behavior:

  1. Example below will not be able to auto focus the input.
export const TestDialog = () => {
  return (
    <Dialog2>
      <input autoFocus />
    </Dialog2>
  );
};
  1. Example below will be able to auto focus the input.
export const TestDialog = () => {
  const [mounted, setMounted] = useState(false);
  useEffect(() => {
    setMounted(true);
  }, []);
  return (
    <Dialog2>
      {mounted && <input autoFocus />}
    </Dialog2>
  );
};

Expected behavior
Possible change to the way children are rendered, taking into account the different drawbacks detailed here reactjs/react.dev#272 (comment) and an update to the documentation outlining which method has been chosen. Potentially introducing a prop if possible to switch between mounting styles.

Desktop (please complete the following information):

  • OS: All
  • Browser: All
  • Version: v34.2.0

Smartphone (please complete the following information):

  • Device: All
  • OS: All
  • Browser: All
  • Version: v34.2.0

Kind Regards
Erik Hughes

@Swiftwork Swiftwork changed the title [Portal] renders children in a detached node causing measuring and autoFocus to fail [Portal] renders children on a detached DOM node causing measuring and autoFocus to fail Jan 19, 2022
@lesliecdubs
Copy link
Member

👋🏻 Hi @Swiftwork, sorry for the late reply here and thanks for filing this!

I'm going to ask our accessibility team to take a look at this and advise on whether we want to implement it. @alliethu what do you think?

@github-actions
Copy link
Contributor

Hi! This issue has been marked as stale because it has been open with no activity for 180 days. You can comment on the issue or remove the stale label to keep it open. If you do nothing, this issue will be closed in 7 days.

@github-actions github-actions bot added the Stale label Oct 15, 2022
@Swiftwork
Copy link
Contributor Author

Not stale

@github-actions github-actions bot removed the Stale label Oct 15, 2022
@lesliecdubs
Copy link
Member

Sorry for the delay on this, @Swiftwork. Are you able to share any details about the desired behavior you're trying to accomplish in your application? It'd also be helpful if you could share a reproduction of the problem; you can fork this sandbox template if you'd like: https://codesandbox.io/s/primer-react-qyyepc. Thanks!

@github-actions
Copy link
Contributor

Hi! This issue has been marked as stale because it has been open with no activity for 180 days. You can comment on the issue or remove the stale label to keep it open. If you do nothing, this issue will be closed in 7 days.

@github-actions github-actions bot added the Stale label Apr 19, 2023
@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Apr 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants