Skip to content

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

Closed as not planned
@Swiftwork

Description

@Swiftwork

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions