From 7980013f3580fe08d925dfa1a0a38b2f37acc749 Mon Sep 17 00:00:00 2001 From: Aaron Robertshaw <60436221+aaronrobertshaw@users.noreply.github.com> Date: Mon, 30 Jan 2023 12:26:30 +0800 Subject: [PATCH] Block Inspector: Avoid advanced panel only settings tab (#47474) --- .../use-inspector-controls-tabs.js | 11 ++++++++--- test/e2e/specs/editor/blocks/table.spec.js | 15 ++++++--------- .../site-editor/push-to-global-styles.spec.js | 10 +--------- 3 files changed, 15 insertions(+), 21 deletions(-) diff --git a/packages/block-editor/src/components/inspector-controls-tabs/use-inspector-controls-tabs.js b/packages/block-editor/src/components/inspector-controls-tabs/use-inspector-controls-tabs.js index 6567750689303..42b0474af1b0e 100644 --- a/packages/block-editor/src/components/inspector-controls-tabs/use-inspector-controls-tabs.js +++ b/packages/block-editor/src/components/inspector-controls-tabs/use-inspector-controls-tabs.js @@ -62,12 +62,17 @@ export default function useInspectorControlsTabs( blockName ) { tabs.push( TAB_STYLES ); } - // Settings Tab: If there are any fills for the general InspectorControls - // or Advanced Controls slot, then add this tab. + // Settings Tab: If we don't already have multiple tabs to display + // (i.e. both list view and styles), check only the default and position + // InspectorControls slots. If we have multiple tabs, we'll need to check + // the advanced controls slot as well to ensure they are rendered. + const advancedFills = + useSlotFills( InspectorAdvancedControls.slotName ) || []; + const settingsFills = [ ...( useSlotFills( defaultGroup.Slot.__unstableName ) || [] ), ...( useSlotFills( positionGroup.Slot.__unstableName ) || [] ), - ...( useSlotFills( InspectorAdvancedControls.slotName ) || [] ), + ...( tabs.length > 1 ? advancedFills : [] ), ]; if ( settingsFills.length ) { diff --git a/test/e2e/specs/editor/blocks/table.spec.js b/test/e2e/specs/editor/blocks/table.spec.js index 6ce830a847e1f..d206089e3f4e3 100644 --- a/test/e2e/specs/editor/blocks/table.spec.js +++ b/test/e2e/specs/editor/blocks/table.spec.js @@ -77,9 +77,6 @@ test.describe( 'Table', () => { } ) => { await editor.insertBlock( { name: 'core/table' } ); await editor.openDocumentSettingsSidebar(); - await page.click( - `role=region[name="Editor settings"i] >> role=tab[name="Settings"i]` - ); const headerSwitch = page.locator( 'role=checkbox[name="Header section"i]' @@ -96,6 +93,9 @@ test.describe( 'Table', () => { await page.click( 'role=button[name="Create Table"i]' ); // Expect the header and footer switches to be present now that the table has been created. + await page.click( + `role=region[name="Editor settings"i] >> role=tab[name="Settings"i]` + ); await expect( headerSwitch ).toBeVisible(); await expect( footerSwitch ).toBeVisible(); @@ -135,9 +135,6 @@ test.describe( 'Table', () => { } ) => { await editor.insertBlock( { name: 'core/table' } ); await editor.openDocumentSettingsSidebar(); - await page.click( - `role=region[name="Editor settings"i] >> role=tab[name="Settings"i]` - ); // Create the table. await page.click( 'role=button[name="Create Table"i]' ); @@ -211,14 +208,14 @@ test.describe( 'Table', () => { } ) => { await editor.insertBlock( { name: 'core/table' } ); await editor.openDocumentSettingsSidebar(); - await page.click( - `role=region[name="Editor settings"i] >> role=tab[name="Settings"i]` - ); // Create the table. await page.click( 'role=button[name="Create Table"i]' ); // Enable fixed width as it exacerbates the amount of empty space around the RichText. + await page.click( + `role=region[name="Editor settings"i] >> role=tab[name="Settings"i]` + ); await page .locator( 'role=checkbox[name="Fixed width table cells"i]' ) .check(); diff --git a/test/e2e/specs/site-editor/push-to-global-styles.spec.js b/test/e2e/specs/site-editor/push-to-global-styles.spec.js index b3863ca67d026..d51ce41dc3ea8 100644 --- a/test/e2e/specs/site-editor/push-to-global-styles.spec.js +++ b/test/e2e/specs/site-editor/push-to-global-styles.spec.js @@ -42,9 +42,8 @@ test.describe( 'Push to Global Styles button', () => { page.getByRole( 'button', { name: 'Uppercase' } ) ).toHaveAttribute( 'aria-pressed', 'false' ); - // Go to block settings, select inner tab, and open the Advanced panel + // Go to block settings and open the Advanced panel await page.getByRole( 'button', { name: 'Settings' } ).click(); - await page.getByRole( 'tab', { name: 'Settings' } ).click(); await page.getByRole( 'button', { name: 'Advanced' } ).click(); // Push button should be disabled @@ -54,16 +53,9 @@ test.describe( 'Push to Global Styles button', () => { } ) ).toBeDisabled(); - // Switch back to the Styles inspector tab to check typography style - await page.getByRole( 'tab', { name: 'Styles' } ).click(); - // Make the Heading block uppercase await page.getByRole( 'button', { name: 'Uppercase' } ).click(); - // Switch back to the Settings inspector tab to check for enabled button - await page.getByRole( 'tab', { name: 'Settings' } ).click(); - await page.getByRole( 'button', { name: 'Advanced' } ).click(); - // Push button should now be enabled await expect( page.getByRole( 'button', {