Skip to content

Commit

Permalink
Sidebar: Expand advanced panel if only item in settings tab
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronrobertshaw committed Nov 24, 2022
1 parent 08ae94c commit 6fd922d
Showing 1 changed file with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,18 @@ import {
default as InspectorControls,
InspectorAdvancedControls,
} from '../inspector-controls';
import InspectorControlsGroups from '../inspector-controls/groups';

const AdvancedControls = () => {
const fills = useSlotFills( InspectorAdvancedControls.slotName );
const hasFills = Boolean( fills && fills.length );

// Check fills in settings tab to determine initial open state for panel.
const tabsEnabled = window?.__experimentalEnableBlockInspectorTabs;
const { default: defaultGroup } = InspectorControlsGroups;
const settingFills = useSlotFills( defaultGroup.Slot.__unstableName ) || [];
const open = !! tabsEnabled && ! settingFills.length;

if ( ! hasFills ) {
return null;
}
Expand All @@ -27,7 +34,7 @@ const AdvancedControls = () => {
<PanelBody
className="block-editor-block-inspector__advanced"
title={ __( 'Advanced' ) }
initialOpen={ false }
initialOpen={ open }
>
<InspectorControls.Slot __experimentalGroup="advanced" />
</PanelBody>
Expand Down

0 comments on commit 6fd922d

Please sign in to comment.