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

BlockControls, InspectorControls: remove useSlot, unify behavior on bad group #50198

Merged
merged 1 commit into from
May 2, 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
12 changes: 8 additions & 4 deletions packages/block-editor/src/components/block-controls/slot.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
ToolbarGroup,
__experimentalUseSlotFills as useSlotFills,
} from '@wordpress/components';
import warning from '@wordpress/warning';

/**
* Internal dependencies
Expand All @@ -15,11 +16,14 @@ import groups from './groups';

export default function BlockControlsSlot( { group = 'default', ...props } ) {
const accessibleToolbarState = useContext( ToolbarContext );
const Slot = groups[ group ].Slot;
const fills = useSlotFills( Slot.__unstableName );
const hasFills = Boolean( fills && fills.length );
const Slot = groups[ group ]?.Slot;
const fills = useSlotFills( Slot?.__unstableName );
if ( ! Slot ) {
warning( `Unknown BlockControls group "${ group }" provided.` );
return null;
}

if ( ! hasFills ) {
if ( ! fills?.length ) {
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
__experimentalToolbarContext as ToolbarContext,
ToolbarGroup,
} from '@wordpress/components';
import warning from '@wordpress/warning';

/**
* Internal dependencies
Expand All @@ -14,7 +15,11 @@ import groups from './groups';

export default function BlockControlsSlot( { group = 'default', ...props } ) {
const accessibleToolbarState = useContext( ToolbarContext );
const Slot = groups[ group ].Slot;
const Slot = groups[ group ]?.Slot;
if ( ! Slot ) {
warning( `Unknown BlockControls group "${ group }" provided.` );
return null;
}

if ( group === 'default' ) {
return <Slot { ...props } fillProps={ accessibleToolbarState } />;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export default function InspectorControlsFill( {
const isDisplayed = useDisplayBlockControls();
const Fill = groups[ group ]?.Fill;
if ( ! Fill ) {
warning( `Unknown InspectorControl group "${ group }" provided.` );
warning( `Unknown InspectorControls group "${ group }" provided.` );
return null;
}
if ( ! isDisplayed ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export default function InspectorControlsFill( {

const Fill = groups[ group ]?.Fill;
if ( ! Fill ) {
warning( `Unknown InspectorControl group "${ group }" provided.` );
warning( `Unknown InspectorControls group "${ group }" provided.` );
return null;
}
if ( ! isDisplayed ) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
/**
* WordPress dependencies
*/
import {
__experimentalUseSlot as useSlot,
__experimentalUseSlotFills as useSlotFills,
} from '@wordpress/components';
import { __experimentalUseSlotFills as useSlotFills } from '@wordpress/components';
import warning from '@wordpress/warning';
import deprecated from '@wordpress/deprecated';

Expand Down Expand Up @@ -33,15 +30,13 @@ export default function InspectorControlsSlot( {
group = __experimentalGroup;
}
const Slot = groups[ group ]?.Slot;
const slot = useSlot( Slot?.__unstableName );
const fills = useSlotFills( Slot?.__unstableName );
if ( ! Slot || ! slot ) {
warning( `Unknown InspectorControl group "${ group }" provided.` );
if ( ! Slot ) {
warning( `Unknown InspectorControls group "${ group }" provided.` );
return null;
}

const hasFills = Boolean( fills && fills.length );
if ( ! hasFills ) {
if ( ! fills?.length ) {
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export default function InspectorControlsSlot( {
}
const Slot = groups[ group ]?.Slot;
if ( ! Slot ) {
warning( `Unknown InspectorControl group "${ group }" provided.` );
warning( `Unknown InspectorControls group "${ group }" provided.` );
return null;
}

Expand Down