diff --git a/packages/block-editor/src/components/block-pattern-setup/index.js b/packages/block-editor/src/components/block-pattern-setup/index.js
index 22d51466b3b6e..edd55e90dc3e2 100644
--- a/packages/block-editor/src/components/block-pattern-setup/index.js
+++ b/packages/block-editor/src/components/block-pattern-setup/index.js
@@ -5,9 +5,7 @@ import { useDispatch } from '@wordpress/data';
import { cloneBlock } from '@wordpress/blocks';
import {
VisuallyHidden,
- __unstableComposite as Composite,
- __unstableUseCompositeState as useCompositeState,
- __unstableCompositeItem as CompositeItem,
+ privateApis as componentsPrivateApis,
} from '@wordpress/components';
import { useState } from '@wordpress/element';
@@ -22,6 +20,13 @@ import BlockPreview from '../block-preview';
import SetupToolbar from './setup-toolbar';
import usePatternsSetup from './use-patterns-setup';
import { VIEWMODES } from './constants';
+import { unlock } from '../../lock-unlock';
+
+const {
+ CompositeV2: Composite,
+ CompositeItemV2: CompositeItem,
+ useCompositeStoreV2: useCompositeStore,
+} = unlock( componentsPrivateApis );
const SetupContent = ( {
viewMode,
@@ -30,8 +35,9 @@ const SetupContent = ( {
onBlockPatternSelect,
showTitles,
} ) => {
- const composite = useCompositeState();
+ const compositeStore = useCompositeStore();
const containerClass = 'block-editor-block-pattern-setup__container';
+
if ( viewMode === VIEWMODES.carousel ) {
const slideClass = new Map( [
[ activeSlide, 'active-slide' ],
@@ -41,23 +47,25 @@ const SetupContent = ( {
return (
-
+
{ patterns.map( ( pattern, index ) => (
) ) }
-
+
);
}
+
return (
) ) }
@@ -76,7 +83,7 @@ const SetupContent = ( {
);
};
-function BlockPattern( { pattern, onSelect, composite, showTitles } ) {
+function BlockPattern( { pattern, onSelect, showTitles } ) {
const baseClassName = 'block-editor-block-pattern-setup-list';
const { blocks, description, viewportWidth = 700 } = pattern;
const descriptionId = useInstanceId(
@@ -84,16 +91,19 @@ function BlockPattern( { pattern, onSelect, composite, showTitles } ) {
`${ baseClassName }__item-description`
);
return (
-
+
+ }
+ id={ `${ baseClassName }__pattern__${ pattern.name }` }
role="option"
- as="div"
- { ...composite }
- className={ `${ baseClassName }__item` }
onClick={ () => onSelect( blocks ) }
>
) }
-
+
);
}
@@ -178,10 +190,14 @@ const BlockPatternSetup = ( {
activeSlide={ activeSlide }
totalSlides={ patterns.length }
handleNext={ () => {
- setActiveSlide( ( active ) => active + 1 );
+ setActiveSlide( ( active ) =>
+ Math.min( active + 1, patterns.length - 1 )
+ );
} }
handlePrevious={ () => {
- setActiveSlide( ( active ) => active - 1 );
+ setActiveSlide( ( active ) =>
+ Math.max( active - 1, 0 )
+ );
} }
onBlockPatternSelect={ () => {
onPatternSelectCallback(
diff --git a/packages/block-editor/src/components/block-pattern-setup/setup-toolbar.js b/packages/block-editor/src/components/block-pattern-setup/setup-toolbar.js
index 69922f9560ab0..91b68456cda71 100644
--- a/packages/block-editor/src/components/block-pattern-setup/setup-toolbar.js
+++ b/packages/block-editor/src/components/block-pattern-setup/setup-toolbar.js
@@ -35,12 +35,14 @@ const CarouselNavigation = ( {
label={ __( 'Previous pattern' ) }
onClick={ handlePrevious }
disabled={ activeSlide === 0 }
+ __experimentalIsFocusable
/>
);
diff --git a/packages/block-editor/src/components/block-pattern-setup/style.scss b/packages/block-editor/src/components/block-pattern-setup/style.scss
index 792e6872a2d59..3474eed5be517 100644
--- a/packages/block-editor/src/components/block-pattern-setup/style.scss
+++ b/packages/block-editor/src/components/block-pattern-setup/style.scss
@@ -32,6 +32,8 @@
}
.block-editor-block-pattern-setup-list__item {
+ scroll-margin: 5px 0;
+
&:hover .block-editor-block-preview__container {
box-shadow: 0 0 0 2px var(--wp-admin-theme-color);
}
@@ -44,6 +46,7 @@
color: var(--wp-admin-theme-color);
}
}
+
.block-editor-block-pattern-setup-list__list-item {
break-inside: avoid-column;
margin-bottom: $grid-unit-30;
@@ -85,7 +88,7 @@
align-items: center;
justify-content: space-between;
border-top: 1px solid $gray-300;
- align-self: flex-end;
+ align-self: stretch;
.block-editor-block-pattern-setup__display-controls {
display: flex;