-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Composite: stabilize new ariakit implementation (#63564)
* Point legacy exports directly to the source (instead of folder root) * Swap default folder export to new version * Apply compound component naming * Export new version from the package * Update (fix) private APIs exports * Update composite implementation to use new compound naming * Update references to Composite inside components package * Update Storybook entry points for both legacy and current * Fix Storybook generated docs * Add todo * Remove unncecessary code * CHANGELOG * README * Add JSDocs to Composite exports * Move current implementation out of `current` folder * Fix import in the legacy implementation * Update docs manifest * Fix type in Storybook example * Add JSDocs for Storybook docs * Apply Overloaded naming convention * Update README * Fix typo * Update legacy storybook title/id, make sure JSDocs refer to unstable version * Derive types instead of importing them directly from ariakit * Add JSDoc snippet for stable component * Remove unnecessary JSDoc code * Remove unnecessary display name * Assign display names via Object.assign to comply with TS and get correct results in Storybook * Update subcomponent TS ignore comment to align with other components * Remove unnecessary store prop in circular option picker Composite.Item should pick up the store from context without explicit prop * Add first-party types, rewrite components with one unique forwardRef call * Use the newly added types instead of using the Parameters<> util * Fix Storybook story type * Remove unnecessary ts-expect-error * Use `CompositeStore` type directly * Manual Storybook args table * Tweak display name fallback * README * Mark `store` prop on `Composite` as required --- Co-authored-by: ciampo <mciampini@git.wordpress.org> Co-authored-by: tyxla <tyxla@git.wordpress.org> Co-authored-by: mirka <0mirka00@git.wordpress.org>
- Loading branch information
Showing
22 changed files
with
700 additions
and
161 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,176 @@ | ||
# `Composite` | ||
|
||
`Composite` provides a single tab stop on the page and allows navigation through the focusable descendants with arrow keys. This abstract component is based on the [WAI-ARIA Composite Role](https://w3c.github.io/aria/#composite). | ||
|
||
See the [Ariakit docs for the `Composite` component](https://ariakit.org/components/composite). | ||
|
||
## Usage | ||
|
||
```jsx | ||
const store = useCompositeStore(); | ||
<Composite store={store}> | ||
<Composite.Group> | ||
<Composite.GroupLabel>Label</Composite.GroupLabel> | ||
<Composite.Item>Item 1</Composite.Item> | ||
<Composite.Item>Item 2</Composite.Item> | ||
</CompositeGroup> | ||
</Composite> | ||
``` | ||
|
||
## Hooks | ||
|
||
### `useCompositeStore` | ||
|
||
Creates a composite store. | ||
|
||
#### Props | ||
|
||
##### `activeId`: `string | null` | ||
|
||
The current active item id. The active item is the element within the composite widget that has either DOM or virtual focus. | ||
|
||
- Required: no | ||
|
||
##### `defaultActiveId`: `string | null` | ||
|
||
The composite item id that should be active by default when the composite widget is rendered. If `null`, the composite element itself will have focus and users will be able to navigate to it using arrow keys. If `undefined`, the first enabled item will be focused. | ||
|
||
- Required: no | ||
|
||
##### `setActiveId`: `((activeId: string | null | undefined) => void)` | ||
|
||
A callback that gets called when the activeId state changes. | ||
|
||
- Required: no | ||
|
||
##### `focusLoop`: `boolean | 'horizontal' | 'vertical' | 'both'` | ||
|
||
Determines how the focus behaves when the user reaches the end of the composite widget. | ||
|
||
- Required: no | ||
- Default: `false` | ||
|
||
##### `focusShift`: `boolean` | ||
|
||
Works only on two-dimensional composite widgets. If enabled, moving up or down when there's no next item or when the next item is disabled will shift to the item right before it. | ||
|
||
- Required: no | ||
- Default: `false` | ||
|
||
##### `focusWrap`: `boolean` | ||
|
||
Works only on two-dimensional composite widgets. If enabled, moving to the next item from the last one in a row or column will focus on the first item in the next row or column and vice-versa. | ||
|
||
- Required: no | ||
- Default: `false` | ||
|
||
##### `virtualFocus`: `boolean` | ||
|
||
If enabled, the composite element will act as an aria-activedescendant container instead of roving tabindex. DOM focus will remain on the composite element while its items receive virtual focus. In both scenarios, the item in focus will carry the data-active-item attribute. | ||
|
||
- Required: no | ||
- Default: `false` | ||
|
||
##### `orientation`: `'horizontal' | 'vertical' | 'both'` | ||
|
||
Defines the orientation of the composite widget. If the composite has a single row or column (one-dimensional), the orientation value determines which arrow keys can be used to move focus. It doesn't have any effect on two-dimensional composites. | ||
|
||
- Required: no | ||
- Default: `'both'` | ||
|
||
##### `rtl`: `boolean` | ||
|
||
Determines how the next and previous functions will behave. If rtl is set to true, they will be inverted. This only affects the composite widget behavior. You still need to set dir=`rtl` on HTML/CSS. | ||
|
||
- Required: no | ||
- Default: `false` | ||
|
||
## Components | ||
|
||
### `Composite` | ||
|
||
Renders a composite widget. | ||
|
||
#### Props | ||
|
||
##### `store`: `CompositeStore<CompositeStoreItem>` | ||
|
||
Object returned by the `useCompositeStore` hook. | ||
|
||
- Required: yes | ||
|
||
##### `render`: `RenderProp<React.HTMLAttributes<any> & { ref?: React.Ref<any> | undefined; }> | React.ReactElement<any, string | React.JSXElementConstructor<any>>` | ||
|
||
Allows the component to be rendered as a different HTML element or React component. The value can be a React element or a function that takes in the original component props and gives back a React element with the props merged. | ||
|
||
- Required: no | ||
|
||
##### `children`: `React.ReactNode` | ||
|
||
The contents of the component. | ||
|
||
- Required: no | ||
|
||
### `Composite.Group` | ||
|
||
Renders a group element for composite items. | ||
|
||
##### `render`: `RenderProp<React.HTMLAttributes<any> & { ref?: React.Ref<any> | undefined; }> | React.ReactElement<any, string | React.JSXElementConstructor<any>>` | ||
|
||
Allows the component to be rendered as a different HTML element or React component. The value can be a React element or a function that takes in the original component props and gives back a React element with the props merged. | ||
|
||
- Required: no | ||
|
||
##### `children`: `React.ReactNode` | ||
|
||
The contents of the component. | ||
|
||
- Required: no | ||
|
||
### `Composite.GroupLabel` | ||
|
||
Renders a label in a composite group. This component must be wrapped with `Composite.Group` so the `aria-labelledby` prop is properly set on the composite group element. | ||
|
||
##### `render`: `RenderProp<React.HTMLAttributes<any> & { ref?: React.Ref<any> | undefined; }> | React.ReactElement<any, string | React.JSXElementConstructor<any>>` | ||
|
||
Allows the component to be rendered as a different HTML element or React component. The value can be a React element or a function that takes in the original component props and gives back a React element with the props merged. | ||
|
||
- Required: no | ||
|
||
##### `children`: `React.ReactNode` | ||
|
||
The contents of the component. | ||
|
||
- Required: no | ||
|
||
### `Composite.Item` | ||
|
||
Renders a composite item. | ||
|
||
##### `render`: `RenderProp<React.HTMLAttributes<any> & { ref?: React.Ref<any> | undefined; }> | React.ReactElement<any, string | React.JSXElementConstructor<any>>` | ||
|
||
Allows the component to be rendered as a different HTML element or React component. The value can be a React element or a function that takes in the original component props and gives back a React element with the props merged. | ||
|
||
- Required: no | ||
|
||
##### `children`: `React.ReactNode` | ||
|
||
The contents of the component. | ||
|
||
- Required: no | ||
|
||
### `Composite.Row` | ||
|
||
Renders a composite row. Wrapping `Composite.Item` elements within `Composite.Row` will create a two-dimensional composite widget, such as a grid. | ||
|
||
##### `render`: `RenderProp<React.HTMLAttributes<any> & { ref?: React.Ref<any> | undefined; }> | React.ReactElement<any, string | React.JSXElementConstructor<any>>` | ||
|
||
Allows the component to be rendered as a different HTML element or React component. The value can be a React element or a function that takes in the original component props and gives back a React element with the props merged. | ||
|
||
- Required: no | ||
|
||
##### `children`: `React.ReactNode` | ||
|
||
The contents of the component. | ||
|
||
- Required: no |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.