Skip to content

Commit

Permalink
Block Inspector: Make Settings tab the default (#47592)
Browse files Browse the repository at this point in the history
* Block Inspector: Make Settings tab the default

* Fix e2es after default tab change
  • Loading branch information
aaronrobertshaw authored Feb 1, 2023
1 parent bed9351 commit 2718f97
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export default function InspectorControlsTabs( {
} ) {
// The tabs panel will mount before fills are rendered to the list view
// slot. This means the list view tab isn't initially included in the
// available tabs so the panel defaults selection to the styles tab
// available tabs so the panel defaults selection to the settings tab
// which at the time is the first tab. This check allows blocks known to
// include the list view tab to set it as the tab selected by default.
const initialTabName = ! useIsListViewTabDisabled( blockName )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,7 @@ export default function useInspectorControlsTabs( blockName ) {
// List View Tab: If there are any fills for the list group add that tab.
const listViewDisabled = useIsListViewTabDisabled( blockName );
const listFills = useSlotFills( listGroup.Slot.__unstableName );

if ( ! listViewDisabled && !! listFills && listFills.length ) {
tabs.push( TAB_LIST_VIEW );
}
const hasListFills = ! listViewDisabled && !! listFills && listFills.length;

// Styles Tab: Add this tab if there are any fills for block supports
// e.g. border, color, spacing, typography, etc.
Expand All @@ -59,12 +56,9 @@ export default function useInspectorControlsTabs( blockName ) {
...( useSlotFills( stylesGroup.Slot.__unstableName ) || [] ),
...( useSlotFills( typographyGroup.Slot.__unstableName ) || [] ),
];
const hasStyleFills = styleFills.length;

if ( styleFills.length ) {
tabs.push( TAB_STYLES );
}

// Settings Tab: If we don't already have multiple tabs to display
// Settings Tab: If we don't 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.
Expand All @@ -74,13 +68,23 @@ export default function useInspectorControlsTabs( blockName ) {
const settingsFills = [
...( useSlotFills( defaultGroup.Slot.__unstableName ) || [] ),
...( useSlotFills( positionGroup.Slot.__unstableName ) || [] ),
...( tabs.length > 1 ? advancedFills : [] ),
...( hasListFills && hasStyleFills > 1 ? advancedFills : [] ),
];

// Add the tabs in the order that they will default to if available.
// List View > Settings > Styles.
if ( hasListFills ) {
tabs.push( TAB_LIST_VIEW );
}

if ( settingsFills.length ) {
tabs.push( TAB_SETTINGS );
}

if ( hasStyleFills ) {
tabs.push( TAB_STYLES );
}

const tabSettings = useSelect( ( select ) => {
return select( blockEditorStore ).getSettings().blockInspectorTabs;
}, [] );
Expand Down
2 changes: 2 additions & 0 deletions packages/e2e-tests/specs/editor/blocks/cover.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
insertBlock,
createNewPost,
openDocumentSettingsSidebar,
switchBlockInspectorTab,
transformBlockTo,
} from '@wordpress/e2e-test-utils';

Expand Down Expand Up @@ -134,6 +135,7 @@ describe( 'Cover', () => {
'.block-editor-list-view-block__contents-container a'
);

switchBlockInspectorTab( 'Styles' );
const heightInputHandle = await page.waitForSelector(
'input[id*="block-cover-height-input"]'
);
Expand Down
16 changes: 16 additions & 0 deletions test/e2e/specs/editor/blocks/buttons.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,10 @@ test.describe( 'Buttons', () => {
await page.keyboard.type( 'Content' );
await editor.openDocumentSettingsSidebar();

// Switch to the Styles tab.
await page.click(
`role=region[name="Editor settings"i] >> role=tab[name="Styles"i]`
);
await page.click(
'role=region[name="Editor settings"i] >> role=button[name="Text"i]'
);
Expand All @@ -179,6 +183,10 @@ test.describe( 'Buttons', () => {
await page.keyboard.type( 'Content' );
await editor.openDocumentSettingsSidebar();

// Switch to the Styles tab.
await page.click(
`role=region[name="Editor settings"i] >> role=tab[name="Styles"i]`
);
await page.click(
'role=region[name="Editor settings"i] >> role=button[name="Text"i]'
);
Expand Down Expand Up @@ -210,6 +218,10 @@ test.describe( 'Buttons', () => {
await page.keyboard.type( 'Content' );
await editor.openDocumentSettingsSidebar();

// Switch to the Styles tab.
await page.click(
`role=region[name="Editor settings"i] >> role=tab[name="Styles"i]`
);
await page.click(
'role=region[name="Editor settings"i] >> role=button[name="Background"i]'
);
Expand All @@ -235,6 +247,10 @@ test.describe( 'Buttons', () => {
await page.keyboard.type( 'Content' );
await editor.openDocumentSettingsSidebar();

// Switch to the Styles tab.
await page.click(
`role=region[name="Editor settings"i] >> role=tab[name="Styles"i]`
);
await page.click(
'role=region[name="Editor settings"i] >> role=button[name="Background"i]'
);
Expand Down

1 comment on commit 2718f97

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Flaky tests detected in 2718f97.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/4061078108
📝 Reported issues:

Please sign in to comment.