-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ensure moving focus within a
Portal
component, does not close the `…
…Popover` component (#2492) * abstract resolving root containers to hook This way we can reuse it in other components when needed. * allow registering a `Portal` component to a parent This allows us to find all the `Portal` components that are nested in a given component without manually adding refs to every `Portal` component itself. This will come in handy in the `Popover` component where we will allow focus in the child `Portal` components otherwise a focus outside of the `Popover` will close the it. In other components we often crawl the DOM directly using `[data-headlessui-portal]` data attributes, however this will fetch _all_ the `Portal` components, not the ones that started in the current component. * allow focus in portalled containers The `Popover` component will close by default if focus is moved outside of it. However, if you use a `Portal` comopnent inside the `Popover.Panel` then from a DOM perspective you are moving the focus outside of the `Popover.Panel`. This prevents the closing, and allows the focus into the `Portal`. It currently only allows for `Portal` components that originated from the `Popover` component. This means that if you open a `Dialog` component from within the `Popover` component, the `Dialog` already renders a `Portal` but since this is part of the `Dialog` and not the `Popover` it will close the `Popover` when focus is moved to the `Dialog` component. * ensure `useNestedPortals` register/unregister with the parent This ensures that if you have a structure like this: ```jsx <Dialog> {/* Renders a portal internally */} <Popover> <Portal> {/* First level */} <Popover.Panel> <Menu> <Portal> {/* Second level */} <Menu.Items> {/* ... */} </Menu.Items> </Portal> </Menu> </Popover.Panel> </Portal> </Popover> </Dialog> ``` That working with the `Menu` doesn't close the `Popover` or the `Dialog`. * cleanup `useRootContainers` hook This will allow you to pass in portal elements as well. + cleanup of the resolving of all DOM nodes. * handle nested portals in `Dialog` component * expose `contains` function from `useRootContainers` Shorthand to check if any of the root containers contains the given element. * add tests to verify that actions in `Portal` components won't close the `Popover` * update changelog * re-order use-outside-click logic To make it similar between React & Vue * inject the `PortalWrapper` context in the correct spot * ensure to forward the incoming `attrs`
- Loading branch information
1 parent
9dff545
commit 8adaeed
Showing
17 changed files
with
517 additions
and
124 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
8adaeed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
headlessui-vue – ./packages/playground-vue
headlessui-vue-tailwindlabs.vercel.app
headlessui-vue-git-main-tailwindlabs.vercel.app
headlessui-vue.vercel.app
8adaeed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
headlessui-react – ./packages/playground-react
headlessui-react-git-main-tailwindlabs.vercel.app
headlessui-react.vercel.app
headlessui-react-tailwindlabs.vercel.app