Skip to content

Commit

Permalink
AlignmentMatrixControl: do not use Composite store (#64850)
Browse files Browse the repository at this point in the history
* AlignmentMatrixControl: do not use composite store

* CHANGELOG
  • Loading branch information
ciampo authored Sep 2, 2024
1 parent c0c870c commit ade6863
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
1 change: 1 addition & 0 deletions packages/components/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
- `TreeSelect`
- `UnitControl`
- `Modal`: Update animation effect ([#64580](https://github.com/WordPress/gutenberg/pull/64580)).
- `AlignmentMatrixControl`: do not use composite store directly ([#64850](https://github.com/WordPress/gutenberg/pull/64850)).

### Bug Fixes

Expand Down
19 changes: 11 additions & 8 deletions packages/components/src/alignment-matrix-control/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ import clsx from 'clsx';
*/
import { __, isRTL } from '@wordpress/i18n';
import { useInstanceId } from '@wordpress/compose';
import { useCallback } from '@wordpress/element';

/**
* Internal dependencies
*/
import Cell from './cell';
import { Composite } from '../composite';
import { useCompositeStore } from '../composite/store';
import { GridContainer, GridRow } from './styles';
import AlignmentMatrixControlIcon from './icon';
import { GRID, getItemId, getItemValue } from './utils';
Expand All @@ -37,23 +37,26 @@ function UnforwardedAlignmentMatrixControl( {
id
);

const compositeStore = useCompositeStore( {
defaultActiveId: getItemId( baseId, defaultValue ),
activeId: getItemId( baseId, value ),
setActiveId: ( nextActiveId ) => {
const setActiveId = useCallback<
NonNullable< React.ComponentProps< typeof Composite >[ 'setActiveId' ] >
>(
( nextActiveId ) => {
const nextValue = getItemValue( baseId, nextActiveId );
if ( nextValue ) {
onChange?.( nextValue );
}
},
rtl: isRTL(),
} );
[ baseId, onChange ]
);

const classes = clsx( 'component-alignment-matrix-control', className );

return (
<Composite
store={ compositeStore }
defaultActiveId={ getItemId( baseId, defaultValue ) }
activeId={ getItemId( baseId, value ) }
setActiveId={ setActiveId }
rtl={ isRTL() }
render={
<GridContainer
{ ...props }
Expand Down

0 comments on commit ade6863

Please sign in to comment.