-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Composite: stabilize new ariakit implementation #63564
Merged
Merged
Changes from all commits
Commits
Show all changes
39 commits
Select commit
Hold shift + click to select a range
c8567d7
Point legacy exports directly to the source (instead of folder root)
ciampo 9f65aaf
Swap default folder export to new version
ciampo 89f623c
Apply compound component naming
ciampo 0e0a729
Export new version from the package
ciampo bf8cf39
Update (fix) private APIs exports
ciampo 951b7c8
Update composite implementation to use new compound naming
ciampo 0da1b62
Update references to Composite inside components package
ciampo e737a18
Update Storybook entry points for both legacy and current
ciampo 5c65788
Fix Storybook generated docs
ciampo 051fb4a
Add todo
ciampo 45f8dcb
Remove unncecessary code
ciampo 8d57789
CHANGELOG
ciampo d706c5e
README
ciampo 0a68587
Add JSDocs to Composite exports
ciampo 1acf18d
Move current implementation out of `current` folder
ciampo a5b0ae4
Fix import in the legacy implementation
ciampo f648f69
Update docs manifest
ciampo deab309
Fix type in Storybook example
ciampo b9246dc
Add JSDocs for Storybook docs
ciampo 2bd8e5e
Apply Overloaded naming convention
ciampo 0df3c5a
Update README
ciampo 1ef744c
Fix typo
ciampo cc11ab4
Update legacy storybook title/id, make sure JSDocs refer to unstable …
ciampo ae1f17f
Derive types instead of importing them directly from ariakit
ciampo e1ba58d
Add JSDoc snippet for stable component
ciampo ea4461b
Remove unnecessary JSDoc code
ciampo f8d6d18
Remove unnecessary display name
ciampo 70bb89c
Assign display names via Object.assign to comply with TS and get corr…
ciampo d91a679
Update subcomponent TS ignore comment to align with other components
ciampo 68650df
Remove unnecessary store prop in circular option picker
ciampo 0b4cb3e
Add first-party types, rewrite components with one unique forwardRef …
ciampo 9bafd47
Use the newly added types instead of using the Parameters<> util
ciampo f511dc3
Fix Storybook story type
ciampo 09c07af
Remove unnecessary ts-expect-error
ciampo db9d27d
Use `CompositeStore` type directly
ciampo 918ae6a
Manual Storybook args table
ciampo 7586d54
Tweak display name fallback
ciampo 176314a
README
ciampo c41ff65
Mark `store` prop on `Composite` as required
ciampo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
ciampo marked this conversation as resolved.
Show resolved
Hide resolved
|
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). | ||
ciampo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
## 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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
This isn't needed because in theory
Composite.Item
should inherit the store from its parentComposite
. The only scenario in which it would break, is if the option and its parent component are rendered across a slot / fill.