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

Use Floating UI within the component instead of store #2279

Merged
merged 25 commits into from May 13, 2023

Conversation

diegohaz
Copy link
Member

@diegohaz diegohaz commented Apr 18, 2023

Closes #887
Closes #1595
Closes #2228

The primary purpose of this PR is to move the @floating-ui/dom dependency from the usePopoverStore hook to the Popover component so it can be lazy loaded.

In addition, we moved most of the Floating UI-related props to the Popover component, which was the original idea, but wasn't viable before without hacks. The only exception is the placement prop, to which we need access on components other than Popover.

This introduces breaking changes on Popover and derived components. Those are described in the changesets.


Finally, the Tooltip component has been updated, so it composes Hovercard now, which also benefited from the Popover changes. The specific Tooltip updates are related to the closed issues above.

@changeset-bot
Copy link

changeset-bot bot commented Apr 18, 2023

🦋 Changeset detected

Latest commit: 1df8142

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 4 packages
Name Type
@ariakit/core Minor
@ariakit/react-core Minor
@ariakit/react Minor
@ariakit/test Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@vercel
Copy link

vercel bot commented Apr 18, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
ariakit ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 12, 2023 2:13am
1 Ignored Deployment
Name Status Preview Comments Updated (UTC)
reakit ⬜️ Ignored (Inspect) May 12, 2023 2:13am

@codesandbox-ci
Copy link

codesandbox-ci bot commented Apr 18, 2023

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit 1df8142:

Sandbox Source
Ariakit Configuration
tooltip with described Issue #2228

@diegohaz diegohaz marked this pull request as ready for review May 12, 2023 02:55
@diegohaz diegohaz merged commit 492cbdc into main May 13, 2023
14 checks passed
@diegohaz diegohaz deleted the floating-ui-on-popover-component branch May 13, 2023 06:36
@github-actions github-actions bot mentioned this pull request May 13, 2023
diegohaz pushed a commit that referenced this pull request May 13, 2023
This PR was opened by the [Changesets
release](https://github.com/changesets/action) GitHub action. When
you're ready to do a release, you can merge this and the packages will
be published to npm automatically. If you're not ready to do a release
yet, that's fine, whenever you add more changesets to main, this PR will
be updated.


# Releases
## @ariakit/core@0.2.0

### Minor Changes

- **BREAKING**: Moved props from the `usePopoverStore` hook to the
`Popover` component: `fixed`, `gutter`, `shift`, `flip`, `slide`,
`overlap`, `sameWidth`, `fitViewport`, `arrowPadding`,
`overflowPadding`, `getAnchorRect`, `renderCallback` (renamed to
`updatePosition`).
([#2279](#2279))

The exception is the `placement` prop that should still be passed to the
store.

    **Before**:

    ```jsx
    const popover = usePopoverStore({
      placement: "bottom",
      fixed: true,
      gutter: 8,
      shift: 8,
      flip: true,
      slide: true,
      overlap: true,
      sameWidth: true,
      fitViewport: true,
      arrowPadding: 8,
      overflowPadding: 8,
      getAnchorRect: (anchor) => anchor?.getBoundingClientRect(),
      renderCallback: (props) => props.defaultRenderCallback(),
    });

    <Popover store={popover} />;
    ```

    **After**:

    ```jsx
    const popover = usePopoverStore({ placement: "bottom" });

    <Popover
      store={popover}
      fixed
      gutter={8}
      shift={8}
      flip
      slide
      overlap
      sameWidth
      fitViewport
      arrowPadding={8}
      overflowPadding={8}
      getAnchorRect={(anchor) => anchor?.getBoundingClientRect()}
      updatePosition={(props) => props.updatePosition()}
    />;
    ```

This change affects all the hooks and components that use
`usePopoverStore` and `Popover` underneath: `useComboboxStore`,
`ComboboxPopover`, `useHovercardStore`, `Hovercard`, `useMenuStore`,
`Menu`, `useSelectStore`, `SelectPopover`, `useTooltipStore`, `Tooltip`.

With this change, the underlying `@floating-ui/dom` dependency has been
also moved to the `Popover` component, which means it can be lazy
loaded. See the [Lazy
Popover](https://ariakit.org/examples/popover-lazy) example.

## @ariakit/react@0.2.0

### Minor Changes

- **BREAKING**: Moved props from the `usePopoverStore` hook to the
`Popover` component: `fixed`, `gutter`, `shift`, `flip`, `slide`,
`overlap`, `sameWidth`, `fitViewport`, `arrowPadding`,
`overflowPadding`, `getAnchorRect`, `renderCallback` (renamed to
`updatePosition`).
([#2279](#2279))

The exception is the `placement` prop that should still be passed to the
store.

    **Before**:

    ```jsx
    const popover = usePopoverStore({
      placement: "bottom",
      fixed: true,
      gutter: 8,
      shift: 8,
      flip: true,
      slide: true,
      overlap: true,
      sameWidth: true,
      fitViewport: true,
      arrowPadding: 8,
      overflowPadding: 8,
      getAnchorRect: (anchor) => anchor?.getBoundingClientRect(),
      renderCallback: (props) => props.defaultRenderCallback(),
    });

    <Popover store={popover} />;
    ```

    **After**:

    ```jsx
    const popover = usePopoverStore({ placement: "bottom" });

    <Popover
      store={popover}
      fixed
      gutter={8}
      shift={8}
      flip
      slide
      overlap
      sameWidth
      fitViewport
      arrowPadding={8}
      overflowPadding={8}
      getAnchorRect={(anchor) => anchor?.getBoundingClientRect()}
      updatePosition={(props) => props.updatePosition()}
    />;
    ```

This change affects all the hooks and components that use
`usePopoverStore` and `Popover` underneath: `useComboboxStore`,
`ComboboxPopover`, `useHovercardStore`, `Hovercard`, `useMenuStore`,
`Menu`, `useSelectStore`, `SelectPopover`, `useTooltipStore`, `Tooltip`.

With this change, the underlying `@floating-ui/dom` dependency has been
also moved to the `Popover` component, which means it can be lazy
loaded. See the [Lazy
Popover](https://ariakit.org/examples/popover-lazy) example.

- **BREAKING**: The backdrop element on the `Dialog` component is now
rendered as a sibling rather than as a parent of the dialog. This should
make it easier to animate them separately.
([#2407](#2407))

This might be a breaking change if you're relying on their parent/child
relationship for styling purposes (for example, to position the dialog
in the center of the backdrop). If that's the case, you can apply the
following styles to the dialog to achieve the same effect:

    ```css
    .dialog {
      position: fixed;
      inset: 1rem;
      margin: auto;
      height: fit-content;
      max-height: calc(100vh - 2 * 1rem);
    }
    ```

These styles work even if the dialog is a child of the backdrop, so you
can use them regardless of whether you're upgrading to this version or
not.

### Patch Changes

- Deprecated the `backdropProps` prop on the `Dialog` component. Use the
`backdrop` prop instead.
([#2407](#2407))

- The `backdrop` prop on the `Dialog` component now accepts a JSX
element as its value.
([#2407](#2407))

- The `Dialog` component will now wait for being unmounted before
restoring the body scroll when the `hidden` prop is set to `false`. This
should prevent the body scroll from being restored too early when the
dialog is being animated out using third-party libraries like Framer
Motion. ([#2407](#2407))

- The `Tooltip` component now defaults to use `aria-describedby` instead
of `aria-labelledby`.
([#2279](#2279))

If you want to use the tooltip as a label for an anchor element, you can
use the `type` prop on `useTooltipStore`:

    ```jsx
    useTooltipStore({ type: "label" });
    ```

- The `Tooltip` component now supports mouse events.
([#2279](#2279))

It's now possible to hover over the tooltip without it disappearing,
which makes it compliant with [WCAG
1.4.13](https://www.w3.org/WAI/WCAG21/Understanding/content-on-hover-or-focus.html).

- Fixed infinite loop on `Portal` with the `preserveTabOrder` prop set
to `true` when the portalled element is placed right after its original
position in the React tree.
([#2279](#2279))

-   Updated dependencies: `@ariakit/react-core@0.2.0`.

## @ariakit/react-core@0.2.0

### Minor Changes

- **BREAKING**: Moved props from the `usePopoverStore` hook to the
`Popover` component: `fixed`, `gutter`, `shift`, `flip`, `slide`,
`overlap`, `sameWidth`, `fitViewport`, `arrowPadding`,
`overflowPadding`, `getAnchorRect`, `renderCallback` (renamed to
`updatePosition`).
([#2279](#2279))

The exception is the `placement` prop that should still be passed to the
store.

    **Before**:

    ```jsx
    const popover = usePopoverStore({
      placement: "bottom",
      fixed: true,
      gutter: 8,
      shift: 8,
      flip: true,
      slide: true,
      overlap: true,
      sameWidth: true,
      fitViewport: true,
      arrowPadding: 8,
      overflowPadding: 8,
      getAnchorRect: (anchor) => anchor?.getBoundingClientRect(),
      renderCallback: (props) => props.defaultRenderCallback(),
    });

    <Popover store={popover} />;
    ```

    **After**:

    ```jsx
    const popover = usePopoverStore({ placement: "bottom" });

    <Popover
      store={popover}
      fixed
      gutter={8}
      shift={8}
      flip
      slide
      overlap
      sameWidth
      fitViewport
      arrowPadding={8}
      overflowPadding={8}
      getAnchorRect={(anchor) => anchor?.getBoundingClientRect()}
      updatePosition={(props) => props.updatePosition()}
    />;
    ```

This change affects all the hooks and components that use
`usePopoverStore` and `Popover` underneath: `useComboboxStore`,
`ComboboxPopover`, `useHovercardStore`, `Hovercard`, `useMenuStore`,
`Menu`, `useSelectStore`, `SelectPopover`, `useTooltipStore`, `Tooltip`.

With this change, the underlying `@floating-ui/dom` dependency has been
also moved to the `Popover` component, which means it can be lazy
loaded. See the [Lazy
Popover](https://ariakit.org/examples/popover-lazy) example.

- **BREAKING**: The backdrop element on the `Dialog` component is now
rendered as a sibling rather than as a parent of the dialog. This should
make it easier to animate them separately.
([#2407](#2407))

This might be a breaking change if you're relying on their parent/child
relationship for styling purposes (for example, to position the dialog
in the center of the backdrop). If that's the case, you can apply the
following styles to the dialog to achieve the same effect:

    ```css
    .dialog {
      position: fixed;
      inset: 1rem;
      margin: auto;
      height: fit-content;
      max-height: calc(100vh - 2 * 1rem);
    }
    ```

These styles work even if the dialog is a child of the backdrop, so you
can use them regardless of whether you're upgrading to this version or
not.

### Patch Changes

- Deprecated the `backdropProps` prop on the `Dialog` component. Use the
`backdrop` prop instead.
([#2407](#2407))

- The `backdrop` prop on the `Dialog` component now accepts a JSX
element as its value.
([#2407](#2407))

- The `Dialog` component will now wait for being unmounted before
restoring the body scroll when the `hidden` prop is set to `false`. This
should prevent the body scroll from being restored too early when the
dialog is being animated out using third-party libraries like Framer
Motion. ([#2407](#2407))

- The `Tooltip` component now defaults to use `aria-describedby` instead
of `aria-labelledby`.
([#2279](#2279))

If you want to use the tooltip as a label for an anchor element, you can
use the `type` prop on `useTooltipStore`:

    ```jsx
    useTooltipStore({ type: "label" });
    ```

- The `Tooltip` component now supports mouse events.
([#2279](#2279))

It's now possible to hover over the tooltip without it disappearing,
which makes it compliant with [WCAG
1.4.13](https://www.w3.org/WAI/WCAG21/Understanding/content-on-hover-or-focus.html).

- Fixed infinite loop on `Portal` with the `preserveTabOrder` prop set
to `true` when the portalled element is placed right after its original
position in the React tree.
([#2279](#2279))

-   Updated dependencies: `@ariakit/core@0.2.0`.

## @ariakit/test@0.1.7

### Patch Changes

-   Updated dependencies: `@ariakit/core@0.2.0`.

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant