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

Ensure moving focus within a Portal component, does not close the Popover component #2492

Merged
merged 12 commits into from
May 19, 2023

Commits on May 12, 2023

  1. abstract resolving root containers to hook

    This way we can reuse it in other components when needed.
    RobinMalfait committed May 12, 2023
    Configuration menu
    Copy the full SHA
    26cd5e1 View commit details
    Browse the repository at this point in the history

Commits on May 15, 2023

  1. 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.
    RobinMalfait committed May 15, 2023
    Configuration menu
    Copy the full SHA
    f965772 View commit details
    Browse the repository at this point in the history
  2. 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.
    RobinMalfait committed May 15, 2023
    Configuration menu
    Copy the full SHA
    a764fb3 View commit details
    Browse the repository at this point in the history
  3. 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`.
    RobinMalfait committed May 15, 2023
    Configuration menu
    Copy the full SHA
    e58c7d2 View commit details
    Browse the repository at this point in the history
  4. cleanup useRootContainers hook

    This will allow you to pass in portal elements as well. + cleanup of
    the resolving of all DOM nodes.
    RobinMalfait committed May 15, 2023
    Configuration menu
    Copy the full SHA
    bb468cc View commit details
    Browse the repository at this point in the history
  5. Configuration menu
    Copy the full SHA
    68a9f05 View commit details
    Browse the repository at this point in the history
  6. expose contains function from useRootContainers

    Shorthand to check if any of the root containers contains the given
    element.
    RobinMalfait committed May 15, 2023
    Configuration menu
    Copy the full SHA
    9a23cc5 View commit details
    Browse the repository at this point in the history
  7. Configuration menu
    Copy the full SHA
    d7ad2f4 View commit details
    Browse the repository at this point in the history
  8. update changelog

    RobinMalfait committed May 15, 2023
    Configuration menu
    Copy the full SHA
    5ceed37 View commit details
    Browse the repository at this point in the history

Commits on May 16, 2023

  1. re-order use-outside-click logic

    To make it similar between React & Vue
    RobinMalfait committed May 16, 2023
    Configuration menu
    Copy the full SHA
    fb01556 View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    cb9b6e4 View commit details
    Browse the repository at this point in the history

Commits on May 19, 2023

  1. Configuration menu
    Copy the full SHA
    f46368a View commit details
    Browse the repository at this point in the history