Skip to content

Commit

Permalink
Sidebar Tabs: Refine use of inspector tabs and disable filters for Na…
Browse files Browse the repository at this point in the history
…v blocks (#46346)
  • Loading branch information
aaronrobertshaw authored Dec 7, 2022
1 parent ea615e0 commit d5dcbd1
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 5 deletions.
4 changes: 2 additions & 2 deletions packages/block-editor/src/components/block-inspector/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ const BlockInspector = ( { showNoBlockSelectedMessage = true } ) => {
}, [] );

const availableTabs = useInspectorControlsTabs( blockType?.name );
const showTabs = availableTabs.length > 1;
const showTabs = availableTabs?.length > 1;

if ( count > 1 ) {
return (
Expand Down Expand Up @@ -241,7 +241,7 @@ const BlockInspector = ( { showNoBlockSelectedMessage = true } ) => {

const BlockInspectorSingleBlock = ( { clientId, blockName } ) => {
const availableTabs = useInspectorControlsTabs( blockName );
const showTabs = availableTabs.length > 1;
const showTabs = availableTabs?.length > 1;

const hasBlockStyles = useSelect(
( select ) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import { InspectorAdvancedControls } from '../inspector-controls';
import { TAB_LIST_VIEW, TAB_SETTINGS, TAB_STYLES } from './utils';
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.
Expand Down Expand Up @@ -83,5 +85,5 @@ export default function useInspectorControlsTabs( blockName ) {

const showTabs = getShowTabs( blockName, tabSettings );

return showTabs ? tabs : [];
return showTabs ? tabs : EMPTY_ARRAY;
}
11 changes: 10 additions & 1 deletion packages/block-library/src/navigation-link/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,16 @@ function register_block_core_navigation_link() {
add_action( 'init', 'register_block_core_navigation_link' );

/**
* Disables the display of tabs for the Navigation Link block.
* Disables the display of block inspector tabs for the Navigation Link block.
*
* This is only a temporary measure until we have a TabPanel and mechanism that
* will allow the Navigation Link to programmatically select a tab when edited
* via a specific context.
*
* See:
* - https://github.com/WordPress/gutenberg/issues/45951
* - https://github.com/WordPress/gutenberg/pull/46321
* - https://github.com/WordPress/gutenberg/pull/46271
*
* @param array $settings Default editor settings.
* @return array Filtered editor settings.
Expand Down
11 changes: 10 additions & 1 deletion packages/block-library/src/navigation-submenu/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,16 @@ function register_block_core_navigation_submenu() {
add_action( 'init', 'register_block_core_navigation_submenu' );

/**
* Disables the display of tabs for the Navigation Submenu block.
* Disables display of block inspector tabs for the Navigation Submenu block.
*
* This is only a temporary measure until we have a TabPanel and mechanism that
* will allow the Navigation Submenu to programmatically select a tab when
* edited via a specific context.
*
* See:
* - https://github.com/WordPress/gutenberg/issues/45951
* - https://github.com/WordPress/gutenberg/pull/46321
* - https://github.com/WordPress/gutenberg/pull/46271
*
* @param array $settings Default editor settings.
* @return array Filtered editor settings.
Expand Down

0 comments on commit d5dcbd1

Please sign in to comment.