Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sidebar Tabs: Stabilize the block inspector tabs experiment #47045

Merged
merged 14 commits into from
Jan 11, 2023
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -168,12 +168,6 @@ public function get_item_schema() {
'context' => array( 'mobile' ),
),

'__experimentalBlockInspectorTabs' => array(
'description' => __( 'Block inspector tab display overrides.', 'gutenberg' ),
'type' => 'object',
'context' => array( 'post-editor', 'site-editor', 'widgets-editor' ),
),

'__experimentalBlockInspectorAnimation' => array(
'description' => __( 'Whether to enable animation when showing and hiding the block inspector.', 'gutenberg' ),
'type' => 'object',
Expand Down Expand Up @@ -204,6 +198,12 @@ public function get_item_schema() {
'context' => array( 'post-editor', 'site-editor', 'widgets-editor' ),
),

'blockInspectorTabs' => array(
'description' => __( 'Block inspector tab display overrides.', 'gutenberg' ),
'type' => 'object',
'context' => array( 'post-editor', 'site-editor', 'widgets-editor' ),
),

'disableCustomColors' => array(
'description' => __( 'Disables custom colors.', 'gutenberg' ),
'type' => 'boolean',
Expand Down
3 changes: 0 additions & 3 deletions lib/experimental/editor-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,6 @@ function gutenberg_enable_experiments() {
if ( $gutenberg_experiments && array_key_exists( 'gutenberg-off-canvas-navigation-editor', $gutenberg_experiments ) ) {
wp_add_inline_script( 'wp-block-editor', 'window.__experimentalEnableOffCanvasNavigationEditor = true', 'before' );
}
if ( $gutenberg_experiments && array_key_exists( 'gutenberg-block-inspector-tabs', $gutenberg_experiments ) ) {
wp_add_inline_script( 'wp-block-editor', 'window.__experimentalEnableBlockInspectorTabs = true', 'before' );
}
if ( $gutenberg_experiments && array_key_exists( 'gutenberg-global-styles-custom-css', $gutenberg_experiments ) ) {
wp_add_inline_script( 'wp-block-editor', 'window.__experimentalEnableGlobalStylesCustomCSS = true', 'before' );
}
Expand Down
12 changes: 0 additions & 12 deletions lib/experiments-page.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,18 +77,6 @@ function gutenberg_initialize_experiments_settings() {
)
);

add_settings_field(
'gutenberg-block-inspector-tabs',
__( 'Block inspector tabs ', 'gutenberg' ),
'gutenberg_display_experiment_field',
'gutenberg-experiments',
'gutenberg_experiments_section',
array(
'label' => __( 'Test a new block inspector view splitting settings and appearance controls into tabs', 'gutenberg' ),
'id' => 'gutenberg-block-inspector-tabs',
)
);

add_settings_field(
'gutenberg-global-styles-custom-css',
__( 'Global styles custom css ', 'gutenberg' ),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,6 @@ import { store as blockEditorStore } from '../../store';
const EMPTY_ARRAY = [];

function getShowTabs( blockName, tabSettings = {} ) {
// Don't allow settings to force the display of tabs if the block inspector
// tabs experiment hasn't been opted into.
if ( ! window?.__experimentalEnableBlockInspectorTabs ) {
return false;
}

// Block specific setting takes precedence over generic default.
if ( tabSettings[ blockName ] !== undefined ) {
return tabSettings[ blockName ];
Expand Down Expand Up @@ -81,8 +75,7 @@ export default function useInspectorControlsTabs( blockName ) {
}

const tabSettings = useSelect( ( select ) => {
return select( blockEditorStore ).getSettings()
.__experimentalBlockInspectorTabs;
return select( blockEditorStore ).getSettings().blockInspectorTabs;
}, [] );

const showTabs = getShowTabs( blockName, tabSettings );
Expand Down
4 changes: 2 additions & 2 deletions packages/block-library/src/navigation-link/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -390,11 +390,11 @@ function register_block_core_navigation_link() {
function gutenberg_disable_tabs_for_navigation_link_block( $settings ) {
$current_tab_settings = _wp_array_get(
$settings,
array( '__experimentalBlockInspectorTabs' ),
array( 'blockInspectorTabs' ),
array()
);

$settings['__experimentalBlockInspectorTabs'] = array_merge(
$settings['blockInspectorTabs'] = array_merge(
$current_tab_settings,
array( 'core/navigation-link' => false )
);
Expand Down
4 changes: 2 additions & 2 deletions packages/block-library/src/navigation-submenu/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -308,11 +308,11 @@ function register_block_core_navigation_submenu() {
function gutenberg_disable_tabs_for_navigation_submenu_block( $settings ) {
$current_tab_settings = _wp_array_get(
$settings,
array( '__experimentalBlockInspectorTabs' ),
array( 'blockInspectorTabs' ),
array()
);

$settings['__experimentalBlockInspectorTabs'] = array_merge(
$settings['blockInspectorTabs'] = array_merge(
$current_tab_settings,
array( 'core/navigation-submenu' => false )
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ const DefaultControls = ( props ) => {
const MenuInspectorControls = ( props ) => {
const isOffCanvasNavigationEditorEnabled =
window?.__experimentalEnableOffCanvasNavigationEditor === true;
const menuControlsSlot = window?.__experimentalEnableBlockInspectorTabs
const menuControlsSlot = isOffCanvasNavigationEditorEnabled
? 'list'
: undefined;

Expand Down
2 changes: 2 additions & 0 deletions packages/e2e-test-utils-playwright/src/editor/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { selectBlocks } from './select-blocks';
import { setContent } from './set-content';
import { showBlockToolbar } from './show-block-toolbar';
import { saveSiteEditorEntities } from './site-editor';
import { switchBlockInspectorTab } from './switch-block-inspector-tab';
import { transformBlockTo } from './transform-block-to';

type EditorConstructorProps = {
Expand Down Expand Up @@ -67,5 +68,6 @@ export class Editor {
selectBlocks = selectBlocks.bind( this );
setContent = setContent.bind( this );
showBlockToolbar = showBlockToolbar.bind( this );
switchBlockInspectorTab = switchBlockInspectorTab.bind( this );
transformBlockTo = transformBlockTo.bind( this );
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/**
* Internal dependencies
*/
import type { Editor } from './index';
import { expect } from '../test';

/**
* Clicks on the block inspector tab button with the supplied label and waits
* for the tab switch.
*
* @param {Editor} this
* @param {string} label
*/
export async function switchBlockInspectorTab( this: Editor, label: string ) {
const inspectorTabButton = this.page.locator(
`role=region[name="Editor settings"i] >> role=tab[name="${ label }"i]`
);
const id = await inspectorTabButton.getAttribute( 'id' );

await inspectorTabButton.click();
await expect(
this.page.locator(
`role=region[name="Editor settings"i] >> div[role="tabpanel"][aria-labelledby="${ id }"]`
)
).toBeVisible();
aaronrobertshaw marked this conversation as resolved.
Show resolved Hide resolved
}
9 changes: 9 additions & 0 deletions packages/e2e-test-utils/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -797,6 +797,15 @@ _Parameters_
The block toolbar is not always visible while typing.
Call this function to reveal it.

### switchBlockInspectorTab

Clicks on the block inspector tab button with the supplied label and waits
for the tab switch.

_Parameters_

- _label_ `string`: Aria label to find tab button by.

### switchEditorModeTo

Switches editor mode.
Expand Down
1 change: 1 addition & 0 deletions packages/e2e-test-utils/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ export { selectBlockByClientId } from './select-block-by-client-id';
export { setBrowserViewport } from './set-browser-viewport';
export { setOption } from './set-option';
export { setPostContent } from './set-post-content';
export { switchBlockInspectorTab } from './switch-block-inspector-tab.js';
export { switchEditorModeTo } from './switch-editor-mode-to';
export { switchUserToAdmin } from './switch-user-to-admin';
export { switchUserToTest } from './switch-user-to-test';
Expand Down
19 changes: 19 additions & 0 deletions packages/e2e-test-utils/src/switch-block-inspector-tab.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/**
* Clicks on the block inspector tab button with the supplied label and waits
* for the tab switch.
*
* @param { string } label Aria label to find tab button by.
*/
export async function switchBlockInspectorTab( label ) {
const tabButton = await page.$(
`.block-editor-block-inspector__tabs button[aria-label="${ label }"]`
);

if ( tabButton ) {
aaronrobertshaw marked this conversation as resolved.
Show resolved Hide resolved
const id = await page.evaluate( ( tab ) => tab.id, tabButton );
await tabButton.click();
await page.waitForSelector(
`div[role="tabpanel"][aria-labelledby="${ id }"]`
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
pressKeyWithModifier,
openDocumentSettingsSidebar,
getListViewBlocks,
switchBlockInspectorTab,
} from '@wordpress/e2e-test-utils';

async function openListViewSidebar() {
Expand All @@ -20,6 +21,20 @@ async function tabToColumnsControl() {
let isColumnsControl = false;
do {
await page.keyboard.press( 'Tab' );

const isBlockInspectorTab = await page.evaluate( () => {
const activeElement = document.activeElement;
return (
activeElement.getAttribute( 'role' ) === 'tab' &&
activeElement.attributes.getNamedItem( 'aria-label' ).value ===
'Styles'
);
} );

if ( isBlockInspectorTab ) {
await page.keyboard.press( 'ArrowRight' );
}

isColumnsControl = await page.evaluate( () => {
const activeElement = document.activeElement;
return (
Expand Down Expand Up @@ -60,6 +75,7 @@ describe( 'Navigating the block hierarchy', () => {

// Tweak the columns count.
await openDocumentSettingsSidebar();
await switchBlockInspectorTab( 'Settings' );
await page.focus(
'.block-editor-block-inspector [aria-label="Columns"][type="number"]'
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,14 +135,14 @@ function useBlockEditorSettings( settings, hasTemplate ) {
Object.entries( settings ).filter( ( [ key ] ) =>
[
'__experimentalBlockDirectory',
'__experimentalBlockInspectorTabs',
'__experimentalDiscussionSettings',
'__experimentalFeatures',
'__experimentalPreferredStyleVariations',
'__experimentalSetIsInserterOpened',
'__unstableGalleryWithImageBlocks',
'alignWide',
'allowedBlockTypes',
'blockInspectorTabs',
'bodyPlaceholder',
'canLockBlocks',
'codeEditingEnabled',
Expand Down
4 changes: 3 additions & 1 deletion test/e2e/specs/editor/blocks/avatar.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ test.describe( 'Avatar', () => {
);

await expect( blockInspectorControls ).toBeVisible();
await editor.switchBlockInspectorTab( 'Settings' );

const userInput = page.locator(
'role=region[name="Editor settings"i] >> role=combobox[name="User"i]'
Expand All @@ -64,7 +65,8 @@ test.describe( 'Avatar', () => {

await newUser.click();

const newSrc = await avatarImage.getAttribute( 'src' );
const updatedAvatarImage = avatarBlock.locator( 'img' );
const newSrc = await updatedAvatarImage.getAttribute( 'src' );

expect( newSrc ).not.toBe( originalSrc );
} );
Expand Down
1 change: 1 addition & 0 deletions test/e2e/specs/editor/blocks/buttons.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ test.describe( 'Buttons', () => {
await editor.insertBlock( { name: 'core/buttons' } );
await page.keyboard.type( 'Content' );
await editor.openDocumentSettingsSidebar();
await editor.switchBlockInspectorTab( 'Settings' );
await page.click(
'role=group[name="Button width"i] >> role=button[name="25%"i]'
);
Expand Down
6 changes: 5 additions & 1 deletion test/e2e/specs/editor/blocks/table.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ test.describe( 'Table', () => {
} ) => {
await editor.insertBlock( { name: 'core/table' } );
await editor.openDocumentSettingsSidebar();
await editor.switchBlockInspectorTab( 'Settings' );

const headerSwitch = page.locator(
'role=checkbox[name="Header section"i]'
Expand Down Expand Up @@ -132,11 +133,13 @@ test.describe( 'Table', () => {
} ) => {
await editor.insertBlock( { name: 'core/table' } );
await editor.openDocumentSettingsSidebar();
await editor.switchBlockInspectorTab( 'Settings' );

// Create the table.
await page.click( 'role=button[name="Create Table"i]' );

// Toggle on the switches and add some content.
await editor.switchBlockInspectorTab( 'Settings' );
await page.locator( 'role=checkbox[name="Header section"i]' ).check();
await page.locator( 'role=checkbox[name="Footer section"i]' ).check();
await page.click( 'role=textbox[name="Body cell text"i] >> nth=0' );
Expand Down Expand Up @@ -202,11 +205,12 @@ test.describe( 'Table', () => {
} ) => {
await editor.insertBlock( { name: 'core/table' } );
await editor.openDocumentSettingsSidebar();
await editor.switchBlockInspectorTab( 'Settings' );

// Create the table.
await page.click( 'role=button[name="Create Table"i]' );

// Enable fixed width as it exascerbates the amount of empty space around the RichText.
// Enable fixed width as it exacerbates the amount of empty space around the RichText.
await page
.locator( 'role=checkbox[name="Fixed width table cells"i]' )
.check();
Expand Down
3 changes: 3 additions & 0 deletions test/e2e/specs/editor/plugins/hooks-api.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@ test.describe( 'Using Hooks API', () => {
} );

test( 'Should contain a reset block button on the sidebar', async ( {
editor,
page,
} ) => {
await page.click( 'role=button[name="Add default block"i]' );
await page.keyboard.type( 'First paragraph' );
await editor.switchBlockInspectorTab( 'Settings' );
await expect(
page.locator( 'role=button[name="Reset Block"i]' )
).toBeVisible();
Expand All @@ -38,6 +40,7 @@ test.describe( 'Using Hooks API', () => {
'role=document[name="Paragraph block"i]'
);
await expect( paragraphBlock ).toHaveText( 'First paragraph' );
await editor.switchBlockInspectorTab( 'Settings' );
await page.click( 'role=button[name="Reset Block"i]' );
expect( await editor.getEditedPostContent() ).toEqual( '' );
} );
Expand Down
10 changes: 9 additions & 1 deletion test/e2e/specs/site-editor/push-to-global-styles.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,9 @@ test.describe( 'Push to Global Styles button', () => {
page.getByRole( 'button', { name: 'Uppercase' } )
).toHaveAttribute( 'aria-pressed', 'false' );

// Go to block settings and open the Advanced panel
// Go to block settings, select inner tab, 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
Expand All @@ -63,9 +64,16 @@ 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', {
Expand Down