Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Move creation of ToolsPanel to within fills
Creating the ToolsPanel for block supports around the slot resulted in the slot adding an extra div within the ToolsPanel breaking its layout. This div is needed for the slot's ref to be applied allowing virtual bubbling.  This change effectively moves the ToolsPanel inside that. It also avoids needing to retrieve ToolsPanelContext and recreating the context provider.
  • Loading branch information
aaronrobertshaw committed Nov 29, 2021
commit 9015c8765ea01664687383d4dfae815a8b78f152

This file was deleted.

28 changes: 12 additions & 16 deletions packages/block-editor/src/components/inspector-controls/fill.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,13 @@
/**
* External dependencies
*/
import { isEmpty } from 'lodash';

/**
* WordPress dependencies
*/
import {
__experimentalStyleProvider as StyleProvider,
__experimentalToolsPanelContext as ToolsPanelContext,
} from '@wordpress/components';
import { __experimentalStyleProvider as StyleProvider } from '@wordpress/components';
import warning from '@wordpress/warning';

/**
* Internal dependencies
*/
import BlockSupportToolsPanel from './block-support-tools-panel';
import useDisplayBlockControls from '../use-display-block-controls';
import groups from './groups';

Expand All @@ -36,15 +29,18 @@ export default function InspectorControlsFill( {
<StyleProvider document={ document }>
<Fill>
{ ( fillProps ) => {
// Children passed to InspectorControlsFill will not have
// access to any React Context whose Provider is part of
// the InspectorControlsSlot tree. So we re-create the
// Provider in this subtree.
const value = ! isEmpty( fillProps ) ? fillProps : null;
// Check if the fills here represent the contents of a
// block support panel and require a wrapping ToolsPanel.
const { label } = fillProps;

if ( ! label ) {
return children;
}

return (
<ToolsPanelContext.Provider value={ value }>
<BlockSupportToolsPanel label={ label }>
{ children }
</ToolsPanelContext.Provider>
</BlockSupportToolsPanel>
);
} }
</Fill>
Expand Down
17 changes: 8 additions & 9 deletions packages/block-editor/src/components/inspector-controls/slot.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ import warning from '@wordpress/warning';
/**
* Internal dependencies
*/
import BlockSupportToolsPanel from './block-support-tools-panel';
import BlockSupportSlotContainer from './block-support-slot-container';
import groups from './groups';

export default function InspectorControlsSlot( {
Expand All @@ -30,14 +28,15 @@ export default function InspectorControlsSlot( {
}

if ( label ) {
// Slots for block support panels will include a label for the panel
// header. This is passed through the fillProps to indicate when the
// fills require a wrapping ToolsPanel.
return (
<BlockSupportToolsPanel group={ group } label={ label }>
<BlockSupportSlotContainer
{ ...props }
bubblesVirtually={ bubblesVirtually }
Slot={ Slot }
/>
</BlockSupportToolsPanel>
<Slot
{ ...props }
bubblesVirtually={ bubblesVirtually }
fillProps={ { label } }
/>
);
}

Expand Down