Skip to content

Commit

Permalink
Composite: fix legacy implementation passing store prop (#65821)
Browse files Browse the repository at this point in the history
* Composite: fix legacy implementation passing store prop

* Simplify code

* Improve comment

* Apply same fix to the top level Composite too

* CHANGELOG

---

Co-authored-by: ciampo <mciampini@git.wordpress.org>
Co-authored-by: tyxla <tyxla@git.wordpress.org>
  • Loading branch information
3 people committed Oct 3, 2024
1 parent 7d60169 commit b712fef
Show file tree
Hide file tree
Showing 8 changed files with 69 additions and 41 deletions.
21 changes: 21 additions & 0 deletions packages/components/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,27 @@
- `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)).
- `ToggleGroupControl`: indicator doesn't jump around when the layout around it changes ([#65175](https://github.com/WordPress/gutenberg/pull/65175)).
- `Composite`: fix legacy support for the store prop ([#65821](https://github.com/WordPress/gutenberg/pull/65821)).

### Deprecations

- `__experimentalBorderControl` can now be imported as a stable `BorderControl` ([#65475](https://github.com/WordPress/gutenberg/pull/65475)).
- `__experimentalBorderBoxControl` can now be imported as a stable `BorderBoxControl` ([#65586](https://github.com/WordPress/gutenberg/pull/65586)).
- `__experimentalNavigator*` components can now be imported as a stable `Navigator`. Similarly, the `__experimentalUseNavigator` hook can be imported as a stable `useNavigator` ([#65802](https://github.com/WordPress/gutenberg/pull/65802)).

### Enhancements

- `Tabs`: handle horizontal overflow and large tab lists gracefully ([#64371](https://github.com/WordPress/gutenberg/pull/64371)).
- `BorderControl`: promote to stable ([#65475](https://github.com/WordPress/gutenberg/pull/65475)).
- `BorderBoxControl`: promote to stable ([#65586](https://github.com/WordPress/gutenberg/pull/65586)).
- `MenuGroup`: Simplify the MenuGroup styles within dropdown menus. ([#65561](https://github.com/WordPress/gutenberg/pull/65561)).
- `DatePicker`: Use compact button size. ([#65653](https://github.com/WordPress/gutenberg/pull/65653)).
- `Navigator`: add support for exit animation ([#64777](https://github.com/WordPress/gutenberg/pull/64777)).
- `Guide`: Update finish button to use the new default size ([#65680](https://github.com/WordPress/gutenberg/pull/65680)).
- `BorderControl`: Use `__next40pxDefaultSize` prop for Reset button ([#65682](https://github.com/WordPress/gutenberg/pull/65682)).
- `Navigator`: stabilize APIs ([#64613](https://github.com/WordPress/gutenberg/pull/64613)).
- `ToggleGroupControl`: indicator animation is now more lightweight and performant ([#65175](https://github.com/WordPress/gutenberg/pull/65175)).

## 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 } />;
} );

0 comments on commit b712fef

Please sign in to comment.