Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 9 additions & 23 deletions packages/block-library/src/tab-panel/tab-toolbar-controls.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ export default function TabToolbarControls( { tabsClientId } ) {
insertBlock,
removeBlock,
updateBlockAttributes,
selectBlock,
__unstableMarkNextChangeAsNotPersistent,
} = useDispatch( blockEditorStore );

Expand All @@ -33,7 +32,6 @@ export default function TabToolbarControls( { tabsClientId } ) {
activeTabPanelClientId,
tabCount,
editorActiveTabIndex,
tabListClientId,
} = useSelect(
( select ) => {
if ( ! tabsClientId ) {
Expand All @@ -42,7 +40,6 @@ export default function TabToolbarControls( { tabsClientId } ) {
activeTabPanelClientId: null,
tabCount: 0,
editorActiveTabIndex: 0,
tabListClientId: null,
};
}
const { getBlocks, getBlockAttributes } =
Expand All @@ -56,9 +53,6 @@ export default function TabToolbarControls( { tabsClientId } ) {
const tabPanels = innerBlocks.find(
( block ) => block.name === 'core/tab-panels'
);
const tabList = innerBlocks.find(
( block ) => block.name === 'core/tab-list'
);
const tabPanelBlocks = tabPanels?.innerBlocks || [];
const activeTabPanel = tabPanelBlocks[ activeIndex ];

Expand All @@ -67,7 +61,6 @@ export default function TabToolbarControls( { tabsClientId } ) {
activeTabPanelClientId: activeTabPanel?.clientId || null,
tabCount: tabPanelBlocks.length,
editorActiveTabIndex: activeIndex,
tabListClientId: tabList?.clientId || null,
};
},
[ tabsClientId ]
Expand All @@ -78,22 +71,21 @@ export default function TabToolbarControls( { tabsClientId } ) {
return;
}

const newTabPanelBlock = createBlock( 'core/tab-panel', {
label: __( 'Tab' ),
} );
insertBlock( newTabPanelBlock, undefined, tabPanelsClientId, false );
insertBlock(
createBlock( 'core/tab-panel', {
label: __( 'Tab' ),
} ),
undefined,
tabPanelsClientId,
false
);

// Switch editor active tab to the new tab.
const newIndex = tabCount;
__unstableMarkNextChangeAsNotPersistent();
updateBlockAttributes( tabsClientId, {
editorActiveTabIndex: newIndex,
} );

// Select the tab-list block so focus stays in the menu area.
if ( tabListClientId ) {
selectBlock( tabListClientId );
}
};

const removeTab = () => {
Expand All @@ -107,18 +99,12 @@ export default function TabToolbarControls( { tabsClientId } ) {
? tabCount - 2
: editorActiveTabIndex;

// Switch editor to next active tab and remove the current one.
__unstableMarkNextChangeAsNotPersistent();
updateBlockAttributes( tabsClientId, {
editorActiveTabIndex: newActiveIndex,
} );

// Remove the tab panel.
removeBlock( activeTabPanelClientId, false );

// Select the tab-list so focus moves to the new active tab button.
if ( tabListClientId ) {
selectBlock( tabListClientId );
}
};

const isRemoveDisabled = tabCount <= 1 || ! activeTabPanelClientId;
Expand Down
Loading