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

Backport #65821 to 6.7 #65853

Merged
merged 1 commit into from
Oct 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/components/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
- `ToolsPanel`: atomic one-step state update when (un)registering panels ([#65564](https://github.com/WordPress/gutenberg/pull/65564)).
- `Navigator`: fix `isInitial` logic ([#65527](https://github.com/WordPress/gutenberg/pull/65527)).
- `ToggleGroupControl`: Fix arrow key navigation in RTL ([#65735](https://github.com/WordPress/gutenberg/pull/65735)).
- `Composite`: fix legacy support for the store prop ([#65821](https://github.com/WordPress/gutenberg/pull/65821)).
ciampo marked this conversation as resolved.
Show resolved Hide resolved

## 28.8.0 (2024-09-19)

Expand Down
12 changes: 7 additions & 5 deletions packages/components/src/composite/group-label.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,13 @@ export const CompositeGroupLabel = forwardRef<
WordPressComponentProps< CompositeGroupLabelProps, 'div', false >
>( function CompositeGroupLabel( props, ref ) {
const context = useCompositeContext();

// @ts-expect-error The store prop is undocumented and only used by the
// legacy compat layer. The `store` prop is documented, but its type is
// obfuscated to discourage its use outside of the component's internals.
const store = ( props.store ?? context.store ) as Ariakit.CompositeStore;

return (
<Ariakit.CompositeGroupLabel
store={ context.store as Ariakit.CompositeStore }
{ ...props }
ref={ ref }
/>
<Ariakit.CompositeGroupLabel store={ store } { ...props } ref={ ref } />
);
} );
14 changes: 7 additions & 7 deletions packages/components/src/composite/group.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ export const CompositeGroup = forwardRef<
WordPressComponentProps< CompositeGroupProps, 'div', false >
>( function CompositeGroup( props, ref ) {
const context = useCompositeContext();
return (
<Ariakit.CompositeGroup
store={ context.store as Ariakit.CompositeStore }
{ ...props }
ref={ ref }
/>
);

// @ts-expect-error The store prop is undocumented and only used by the
// legacy compat layer. The `store` prop is documented, but its type is
// obfuscated to discourage its use outside of the component's internals.
const store = ( props.store ?? context.store ) as Ariakit.CompositeStore;

return <Ariakit.CompositeGroup store={ store } { ...props } ref={ ref } />;
} );
14 changes: 7 additions & 7 deletions packages/components/src/composite/hover.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ export const CompositeHover = forwardRef<
WordPressComponentProps< CompositeHoverProps, 'div', false >
>( function CompositeHover( props, ref ) {
const context = useCompositeContext();
return (
<Ariakit.CompositeHover
store={ context.store as Ariakit.CompositeStore }
{ ...props }
ref={ ref }
/>
);

// @ts-expect-error The store prop is undocumented and only used by the
// legacy compat layer. The `store` prop is documented, but its type is
// obfuscated to discourage its use outside of the component's internals.
const store = ( props.store ?? context.store ) as Ariakit.CompositeStore;

return <Ariakit.CompositeGroup store={ store } { ...props } ref={ ref } />;
} );
7 changes: 6 additions & 1 deletion packages/components/src/composite/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,10 @@ export const Composite = Object.assign(
},
ref
) {
const store = Ariakit.useCompositeStore( {
// @ts-expect-error The store prop is undocumented and only used by the
// legacy compat layer.
const storeProp = props.store as Ariakit.CompositeStore;
const internalStore = Ariakit.useCompositeStore( {
activeId,
defaultActiveId,
setActiveId,
Expand All @@ -85,6 +88,8 @@ export const Composite = Object.assign(
rtl,
} );

const store = storeProp ?? internalStore;

const contextValue = useMemo(
() => ( {
store,
Expand Down
14 changes: 7 additions & 7 deletions packages/components/src/composite/item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ export const CompositeItem = forwardRef<
WordPressComponentProps< CompositeItemProps, 'button', false >
>( function CompositeItem( props, ref ) {
const context = useCompositeContext();
return (
<Ariakit.CompositeItem
store={ context.store as Ariakit.CompositeStore }
{ ...props }
ref={ ref }
/>
);

// @ts-expect-error The store prop is undocumented and only used by the
// legacy compat layer. The `store` prop is documented, but its type is
// obfuscated to discourage its use outside of the component's internals.
const store = ( props.store ?? context.store ) as Ariakit.CompositeStore;

return <Ariakit.CompositeItem store={ store } { ...props } ref={ ref } />;
} );
14 changes: 7 additions & 7 deletions packages/components/src/composite/row.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ export const CompositeRow = forwardRef<
WordPressComponentProps< CompositeRowProps, 'div', false >
>( function CompositeRow( props, ref ) {
const context = useCompositeContext();
return (
<Ariakit.CompositeRow
store={ context.store as Ariakit.CompositeStore }
{ ...props }
ref={ ref }
/>
);

// @ts-expect-error The store prop is undocumented and only used by the
// legacy compat layer. The `store` prop is documented, but its type is
// obfuscated to discourage its use outside of the component's internals.
const store = ( props.store ?? context.store ) as Ariakit.CompositeStore;

return <Ariakit.CompositeRow store={ store } { ...props } ref={ ref } />;
} );
14 changes: 7 additions & 7 deletions packages/components/src/composite/typeahead.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ export const CompositeTypeahead = forwardRef<
WordPressComponentProps< CompositeTypeaheadProps, 'div', false >
>( function CompositeTypeahead( props, ref ) {
const context = useCompositeContext();
return (
<Ariakit.CompositeTypeahead
store={ context.store as Ariakit.CompositeStore }
{ ...props }
ref={ ref }
/>
);

// @ts-expect-error The store prop is undocumented and only used by the
// legacy compat layer. The `store` prop is documented, but its type is
// obfuscated to discourage its use outside of the component's internals.
const store = ( props.store ?? context.store ) as Ariakit.CompositeStore;

return <Ariakit.CompositeRow store={ store } { ...props } ref={ ref } />;
} );
Loading