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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
b4047b2
Use Floating UI within the component instead of store
diegohaz Apr 18, 2023
b4ec67b
Rewrite renderCallback into updatePosition
diegohaz Apr 18, 2023
969d757
Fix some examples
diegohaz Apr 18, 2023
2ce7ece
WIP
diegohaz Apr 19, 2023
e0c02cf
Fix tests on React 18
diegohaz Apr 20, 2023
6bacc4a
Try to fix e2e tests
diegohaz Apr 20, 2023
04e681d
Fix React 17 tests
diegohaz Apr 20, 2023
91d13e7
Add mobile tests
diegohaz Apr 21, 2023
3995d25
WIP
diegohaz Apr 21, 2023
99a40f9
Merge branch 'main' into floating-ui-on-popover-component
diegohaz Apr 21, 2023
3428658
Merge branch 'main' into floating-ui-on-popover-component
diegohaz Apr 21, 2023
63707e7
Merge branch 'main' into floating-ui-on-popover-component
diegohaz May 2, 2023
8d4b87a
Merge branch 'main' into floating-ui-on-popover-component
diegohaz May 7, 2023
cd5a8d8
Merge branch 'main' into floating-ui-on-popover-component
diegohaz May 8, 2023
73a0867
Merge branch 'main' into floating-ui-on-popover-component
diegohaz May 8, 2023
7462831
Merge branch 'main' into floating-ui-on-popover-component
diegohaz May 8, 2023
e2036b1
Merge branch 'main' into floating-ui-on-popover-component
diegohaz May 11, 2023
63c4a22
Fix portal
diegohaz May 11, 2023
ce76dee
WIP
diegohaz May 11, 2023
6ca5c28
WIP
diegohaz May 11, 2023
9bdca15
Add tooltip-label example
diegohaz May 11, 2023
874c938
Add skipTimeout prop to useTooltipStore
diegohaz May 12, 2023
741f052
Updates
diegohaz May 12, 2023
c42d5a8
Add changesets
diegohaz May 12, 2023
1df8142
Update dependencies
diegohaz May 12, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
57 changes: 57 additions & 0 deletions .changeset/__breaking-1.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
---
"@ariakit/core": minor
"@ariakit/react-core": minor
"@ariakit/react": minor
---

**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](https://github.com/ariakit/ariakit/pull/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.
12 changes: 12 additions & 0 deletions .changeset/curvy-taxis-shave-2.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
"@ariakit/react-core": patch
"@ariakit/react": patch
---

The `Tooltip` component now defaults to use `aria-describedby` instead of `aria-labelledby`. ([#2279](https://github.com/ariakit/ariakit/pull/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" });
```
8 changes: 8 additions & 0 deletions .changeset/curvy-taxis-shave.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
"@ariakit/react-core": patch
"@ariakit/react": patch
---

The `Tooltip` component now supports mouse events. ([#2279](https://github.com/ariakit/ariakit/pull/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).
6 changes: 6 additions & 0 deletions .changeset/mighty-cougars-rule.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@ariakit/react-core": patch
"@ariakit/react": patch
---

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](https://github.com/ariakit/ariakit/pull/2279))
4 changes: 2 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ jobs:

- name: Test
id: test
run: npm run test-chrome
run: npm run playwright -- --project chrome --project android

- name: Upload test results to GitHub
if: failure() && steps.test.outcome == 'failure'
Expand Down Expand Up @@ -341,7 +341,7 @@ jobs:

- name: Test
id: test
run: npm run playwright -- --project firefox --project safari
run: npm run playwright -- --project firefox --project safari --project ios

- name: Upload test results to GitHub
if: failure() && steps.test.outcome == 'failure'
Expand Down
13 changes: 7 additions & 6 deletions examples/combobox-animated/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@ import * as Ariakit from "@ariakit/react";
import "./style.css";

export default function Example() {
const combobox = Ariakit.useComboboxStore({
gutter: 4,
sameWidth: true,
animated: true,
});
const combobox = Ariakit.useComboboxStore({ animated: true });
return (
<div className="wrapper">
<label className="label">
Expand All @@ -17,7 +13,12 @@ export default function Example() {
className="combobox"
/>
</label>
<Ariakit.ComboboxPopover store={combobox} className="popover">
<Ariakit.ComboboxPopover
store={combobox}
gutter={4}
sameWidth
className="popover"
>
<Ariakit.ComboboxItem className="combobox-item" value="Apple">
🍎 Apple
</Ariakit.ComboboxItem>
Expand Down
9 changes: 7 additions & 2 deletions examples/combobox-cancel/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const list = [
];

export default function Example() {
const combobox = Ariakit.useComboboxStore({ gutter: 4, sameWidth: true });
const combobox = Ariakit.useComboboxStore();
return (
<div className="wrapper">
<label className="label">
Expand All @@ -30,7 +30,12 @@ export default function Example() {
/>
</div>
</label>
<Ariakit.ComboboxPopover store={combobox} className="popover">
<Ariakit.ComboboxPopover
store={combobox}
gutter={4}
sameWidth
className="popover"
>
{list.map((value) => (
<Ariakit.ComboboxItem
key={value}
Expand Down
9 changes: 7 additions & 2 deletions examples/combobox-disclosure/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as Ariakit from "@ariakit/react";
import "./style.css";

export default function Example() {
const combobox = Ariakit.useComboboxStore({ gutter: 4, sameWidth: true });
const combobox = Ariakit.useComboboxStore();
return (
<div className="wrapper">
<label className="label">
Expand All @@ -19,7 +19,12 @@ export default function Example() {
/>
</div>
</label>
<Ariakit.ComboboxPopover store={combobox} className="popover">
<Ariakit.ComboboxPopover
store={combobox}
gutter={4}
sameWidth
className="popover"
>
<Ariakit.ComboboxItem className="combobox-item" value="Pizza">
🍕 Pizza
</Ariakit.ComboboxItem>
Expand Down
9 changes: 7 additions & 2 deletions examples/combobox-group/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import food from "./food.js";
import "./style.css";

export default function Example() {
const combobox = Ariakit.useComboboxStore({ gutter: 4, sameWidth: true });
const combobox = Ariakit.useComboboxStore();
const value = combobox.useState("value");
const deferredValue = React.useDeferredValue(value);

Expand All @@ -27,7 +27,12 @@ export default function Example() {
autoSelect
/>
</label>
<Ariakit.ComboboxPopover store={combobox} className="popover">
<Ariakit.ComboboxPopover
store={combobox}
gutter={4}
sameWidth
className="popover"
>
{!!matches.length ? (
matches.map(([type, items], i) => (
<React.Fragment key={type}>
Expand Down
9 changes: 7 additions & 2 deletions examples/combobox-inline-autocomplete/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as Ariakit from "@ariakit/react";
import "./style.css";

export default function Example() {
const combobox = Ariakit.useComboboxStore({ gutter: 8, sameWidth: true });
const combobox = Ariakit.useComboboxStore();
return (
<div>
<label className="label">
Expand All @@ -14,7 +14,12 @@ export default function Example() {
autoComplete="inline"
/>
</label>
<Ariakit.ComboboxPopover store={combobox} className="popover">
<Ariakit.ComboboxPopover
store={combobox}
gutter={8}
sameWidth
className="popover"
>
<Ariakit.ComboboxItem className="combobox-item" value="Apple">
🍎 Apple
</Ariakit.ComboboxItem>
Expand Down
9 changes: 7 additions & 2 deletions examples/combobox-item-value/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import "./style.css";
const fruits = ["Apple", "Grape", "Orange", "Strawberry", "Watermelon"];

export default function Example() {
const combobox = Ariakit.useComboboxStore({ gutter: 8, sameWidth: true });
const combobox = Ariakit.useComboboxStore();
return (
<div className="wrapper">
<label className="label">
Expand All @@ -15,7 +15,12 @@ export default function Example() {
className="combobox"
/>
</label>
<Ariakit.ComboboxPopover store={combobox} className="popover">
<Ariakit.ComboboxPopover
store={combobox}
gutter={8}
sameWidth
className="popover"
>
{fruits.map((f) => (
<Ariakit.ComboboxItem key={f} value={f} className="combobox-item">
<Ariakit.ComboboxItemValue />
Expand Down
13 changes: 7 additions & 6 deletions examples/combobox-links/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,7 @@ const links = [
];

export default function Example() {
const combobox = Ariakit.useComboboxStore({
gutter: 4,
sameWidth: true,
});

const combobox = Ariakit.useComboboxStore();
const mounted = combobox.useState("mounted");
const value = combobox.useState("value");
const deferredValue = useDeferredValue(value);
Expand Down Expand Up @@ -72,7 +68,12 @@ export default function Example() {
/>
</label>
{mounted && (
<Ariakit.ComboboxPopover store={combobox} className="popover">
<Ariakit.ComboboxPopover
store={combobox}
gutter={4}
sameWidth
className="popover"
>
{matches.length ? (
matches.map(renderItem)
) : (
Expand Down
9 changes: 7 additions & 2 deletions examples/combobox-matches/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import list from "./list.js";
import "./style.css";

export default function Example() {
const combobox = Ariakit.useComboboxStore({ gutter: 8, sameWidth: true });
const combobox = Ariakit.useComboboxStore();
const value = combobox.useState("value");
const deferredValue = useDeferredValue(value);

Expand All @@ -24,7 +24,12 @@ export default function Example() {
className="combobox"
/>
</label>
<Ariakit.ComboboxPopover store={combobox} className="popover">
<Ariakit.ComboboxPopover
store={combobox}
gutter={8}
sameWidth
className="popover"
>
{matches.length ? (
matches.map((value) => (
<Ariakit.ComboboxItem
Expand Down
14 changes: 7 additions & 7 deletions examples/combobox-min-length/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,7 @@ import "./style.css";

export default function Example() {
const [open, setOpen] = useState(false);
const combobox = Ariakit.useComboboxStore({
open,
setOpen,
gutter: 8,
sameWidth: true,
});
const combobox = Ariakit.useComboboxStore({ open, setOpen });

const value = combobox.useState("value");

Expand All @@ -27,7 +22,12 @@ export default function Example() {
className="combobox"
/>
</label>
<Ariakit.ComboboxPopover store={combobox} className="popover">
<Ariakit.ComboboxPopover
store={combobox}
gutter={8}
sameWidth
className="popover"
>
<Ariakit.ComboboxItem className="combobox-item" value="Apple">
🍎 Apple
</Ariakit.ComboboxItem>
Expand Down
9 changes: 6 additions & 3 deletions examples/combobox-multiple/combobox-multiple.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ export const ComboboxMultiple = React.forwardRef<
// is on the combobox input, so we set `virtualFocus` to `false` to disable
// this behavior and put DOM focus on the items.
virtualFocus: false,
sameWidth: true,
gutter: 8,
defaultValue,
value,
setValue: onChange,
Expand Down Expand Up @@ -76,7 +74,12 @@ export const ComboboxMultiple = React.forwardRef<
) : (
element
)}
<Ariakit.ComboboxPopover store={combobox} className="popover">
<Ariakit.ComboboxPopover
store={combobox}
gutter={8}
sameWidth
className="popover"
>
{(popoverProps) => (
<Ariakit.SelectList
store={select}
Expand Down
15 changes: 7 additions & 8 deletions examples/combobox-textarea/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,7 @@ export default function Example() {
const [trigger, setTrigger] = React.useState<string | null>(null);
const [caretOffset, setCaretOffset] = React.useState<number | null>(null);

const combobox = Ariakit.useComboboxStore({
fitViewport: true,
getAnchorRect: () => {
const textarea = ref.current;
if (!textarea) return null;
return getAnchorRect(textarea);
},
});
const combobox = Ariakit.useComboboxStore();

const searchValue = combobox.useState("value");
const mounted = combobox.useState("mounted");
Expand Down Expand Up @@ -127,6 +120,12 @@ export default function Example() {
<Ariakit.ComboboxPopover
store={combobox}
hidden={!hasMatches}
fitViewport
getAnchorRect={() => {
const textarea = ref.current;
if (!textarea) return null;
return getAnchorRect(textarea);
}}
className="popover"
>
{matches.map((value) => (
Expand Down
9 changes: 7 additions & 2 deletions examples/combobox/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as Ariakit from "@ariakit/react";
import "./style.css";

export default function Example() {
const combobox = Ariakit.useComboboxStore({ gutter: 4, sameWidth: true });
const combobox = Ariakit.useComboboxStore();
return (
<div className="wrapper">
<label className="label">
Expand All @@ -13,7 +13,12 @@ export default function Example() {
className="combobox"
/>
</label>
<Ariakit.ComboboxPopover store={combobox} className="popover">
<Ariakit.ComboboxPopover
store={combobox}
gutter={4}
sameWidth
className="popover"
>
<Ariakit.ComboboxItem className="combobox-item" value="Apple">
🍎 Apple
</Ariakit.ComboboxItem>
Expand Down