diff --git a/packages/block-editor/src/components/inserter/menu.js b/packages/block-editor/src/components/inserter/menu.js
index 4f028eb69c6662..cd44b902f491a5 100644
--- a/packages/block-editor/src/components/inserter/menu.js
+++ b/packages/block-editor/src/components/inserter/menu.js
@@ -191,17 +191,13 @@ function InserterMenu(
]
);
- const getCurrentTab = useCallback(
- ( tab ) => {
- if ( tab.name === 'blocks' ) {
- return blocksTab;
- } else if ( tab.name === 'patterns' ) {
- return patternsTab;
- } else if ( tab.name === 'media' ) {
- return mediaTab;
- }
- },
- [ blocksTab, patternsTab, mediaTab ]
+ const inserterTabsContents = useMemo(
+ () => ( {
+ blocks: blocksTab,
+ patterns: patternsTab,
+ media: mediaTab,
+ } ),
+ [ blocksTab, mediaTab, patternsTab ]
);
const searchRef = useRef();
@@ -275,9 +271,8 @@ function InserterMenu(
showMedia={ showMedia }
prioritizePatterns={ prioritizePatterns }
onSelect={ handleSetSelectedTab }
- >
- { getCurrentTab }
-
+ tabsContents={ inserterTabsContents }
+ />
) }
{ ! delayedFilterValue && ! showAsTabs && (
diff --git a/packages/block-editor/src/components/inserter/style.scss b/packages/block-editor/src/components/inserter/style.scss
index 755445246e8596..97a3d877b7e72a 100644
--- a/packages/block-editor/src/components/inserter/style.scss
+++ b/packages/block-editor/src/components/inserter/style.scss
@@ -61,7 +61,7 @@ $block-inserter-tabs-height: 44px;
.block-editor-inserter__popover .block-editor-inserter__menu {
margin: -$grid-unit-15;
- .block-editor-inserter__tabs .components-tab-panel__tabs {
+ .block-editor-inserter__tabs div[role="tablist"] {
top: $grid-unit-10 + $grid-unit-20 + $grid-unit-60 - $grid-unit-15;
}
@@ -118,10 +118,10 @@ $block-inserter-tabs-height: 44px;
flex-direction: column;
overflow: hidden;
- .components-tab-panel__tabs {
+ div[role="tablist"] {
border-bottom: $border-width solid $gray-300;
- .components-tab-panel__tabs-item {
+ button[role="tab"] {
flex-grow: 1;
margin-bottom: -$border-width;
&[id$="reusable"] {
@@ -133,7 +133,7 @@ $block-inserter-tabs-height: 44px;
}
}
- .components-tab-panel__tab-content {
+ div[role="tabpanel"] {
display: flex;
flex-grow: 1;
flex-direction: column;
diff --git a/packages/block-editor/src/components/inserter/tabs.js b/packages/block-editor/src/components/inserter/tabs.js
index a75e0029ef4900..72b13425bbbe79 100644
--- a/packages/block-editor/src/components/inserter/tabs.js
+++ b/packages/block-editor/src/components/inserter/tabs.js
@@ -2,9 +2,16 @@
* WordPress dependencies
*/
import { useMemo } from '@wordpress/element';
-import { TabPanel } from '@wordpress/components';
+import { privateApis as componentsPrivateApis } from '@wordpress/components';
import { __ } from '@wordpress/i18n';
+/**
+ * Internal dependencies
+ */
+import { unlock } from '../../lock-unlock';
+
+const { Tabs } = unlock( componentsPrivateApis );
+
const blocksTab = {
name: 'blocks',
/* translators: Blocks tab title in the block inserter. */
@@ -23,11 +30,11 @@ const mediaTab = {
};
function InserterTabs( {
- children,
showPatterns = false,
showMedia = false,
onSelect,
prioritizePatterns,
+ tabsContents,
} ) {
const tabs = useMemo( () => {
const tempTabs = [];
@@ -45,13 +52,26 @@ function InserterTabs( {
}, [ prioritizePatterns, showPatterns, showMedia ] );
return (
-
- { children }
-
+
+
+
+ { tabs.map( ( tab ) => (
+
+ { tab.title }
+
+ ) ) }
+
+ { tabs.map( ( tab ) => (
+
+ { tabsContents[ tab.name ] }
+
+ ) ) }
+
+
);
}
diff --git a/packages/e2e-test-utils/src/inserter.js b/packages/e2e-test-utils/src/inserter.js
index ebbda244d18564..a2c73abe666552 100644
--- a/packages/e2e-test-utils/src/inserter.js
+++ b/packages/e2e-test-utils/src/inserter.js
@@ -86,7 +86,10 @@ export async function selectGlobalInserterTab( label ) {
}
const activeTab = await page.waitForSelector(
- '.block-editor-inserter__tabs button.is-active'
+ // Targeting a class name is necessary here, because there are likely
+ // two implementations of the `Tabs` component visible to this test, and
+ // we want to confirm that it's waiting for the correct one.
+ '.block-editor-inserter__tabs [role="tab"][aria-selected="true"]'
);
const activeTabLabel = await page.evaluate(