Skip to content

Commit

Permalink
Hide parent selector in widget area (#26011)
Browse files Browse the repository at this point in the history
* Hide parent selector in widget area

* Only hide when parent is widget-area

* Move to supports and rename it to experimental
  • Loading branch information
kevin940726 authored Oct 15, 2020
1 parent f5bca16 commit 0f978d2
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 15 deletions.
44 changes: 29 additions & 15 deletions packages/block-editor/src/components/block-parent-selector/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,35 @@ import BlockIcon from '../block-icon';
*/
export default function BlockParentSelector() {
const { selectBlock } = useDispatch( 'core/block-editor' );
const { parentBlockType, firstParentClientId } = useSelect( ( select ) => {
const {
getBlockName,
getBlockParents,
getSelectedBlockClientId,
} = select( 'core/block-editor' );
const selectedBlockClientId = getSelectedBlockClientId();
const parents = getBlockParents( selectedBlockClientId );
const _firstParentClientId = parents[ parents.length - 1 ];
const parentBlockName = getBlockName( _firstParentClientId );
return {
parentBlockType: getBlockType( parentBlockName ),
firstParentClientId: _firstParentClientId,
};
}, [] );
const { parentBlockType, firstParentClientId, shouldHide } = useSelect(
( select ) => {
const {
getBlockName,
getBlockParents,
getSelectedBlockClientId,
} = select( 'core/block-editor' );
const { hasBlockSupport } = select( 'core/blocks' );
const selectedBlockClientId = getSelectedBlockClientId();
const parents = getBlockParents( selectedBlockClientId );
const _firstParentClientId = parents[ parents.length - 1 ];
const parentBlockName = getBlockName( _firstParentClientId );
const _parentBlockType = getBlockType( parentBlockName );
return {
parentBlockType: _parentBlockType,
firstParentClientId: _firstParentClientId,
shouldHide: ! hasBlockSupport(
parentBlockType,
'__experimentalParentSelector',
true
),
};
},
[]
);

if ( shouldHide ) {
return null;
}

if ( firstParentClientId !== undefined ) {
return (
Expand Down
4 changes: 4 additions & 0 deletions packages/edit-widgets/src/blocks/widget-area/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,9 @@ export const settings = {
title: __( 'Widget Area' ),
description: __( 'A widget area container.' ),
__experimentalLabel: ( { name: label } ) => label,
supports: {
// Should show the parent selector for its children or not. Defaults to true.
__experimentalParentSelector: false,
},
edit,
};

0 comments on commit 0f978d2

Please sign in to comment.