Skip to content

Commit

Permalink
Block Patterns List: do not use Composite store
Browse files Browse the repository at this point in the history
  • Loading branch information
ciampo committed Sep 2, 2024
1 parent 825cdac commit 8d59f78
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions packages/block-editor/src/components/block-patterns-list/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,9 @@ import InserterDraggableBlocks from '../inserter-draggable-blocks';
import BlockPatternsPaging from '../block-patterns-paging';
import { INSERTER_PATTERN_TYPES } from '../inserter/block-patterns-tab/utils';

const {
CompositeV2: Composite,
CompositeItemV2: CompositeItem,
useCompositeStoreV2: useCompositeStore,
} = unlock( componentsPrivateApis );
const { CompositeV2: Composite, CompositeItemV2: CompositeItem } = unlock(
componentsPrivateApis
);

const WithToolTip = ( { showTooltip, title, children } ) => {
if ( showTooltip ) {
Expand Down Expand Up @@ -206,19 +204,23 @@ function BlockPatternsList(
},
ref
) {
const compositeStore = useCompositeStore( { orientation } );
const { setActiveId } = compositeStore;
const [ activeCompositeId, setActiveCompositeId ] = useState( undefined );

useEffect( () => {
// We reset the active composite item whenever the
// available patterns change, to make sure that
// focus is put back to the start.
setActiveId( undefined );
}, [ setActiveId, shownPatterns, blockPatterns ] );
// Reset the active composite item whenever the available patterns change,
// to make sure that Composite widget can receive focus correctly when its
// composite items change. The first composite item will receive focus.
const firstCompositeItemId = blockPatterns.find( ( pattern ) =>
shownPatterns.includes( pattern )
)?.name;
setActiveCompositeId( firstCompositeItemId );
}, [ shownPatterns, blockPatterns ] );

return (
<Composite
store={ compositeStore }
orientation={ orientation }
activeId={ activeCompositeId }
setActiveId={ setActiveCompositeId }
role="listbox"
className="block-editor-block-patterns-list"
aria-label={ label }
Expand Down

0 comments on commit 8d59f78

Please sign in to comment.