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

Fix: Remove parent block selector while in Write mode #67395

Merged
Merged
Show file tree
Hide file tree
Changes from 2 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
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/**
* WordPress dependencies
*/
import { getBlockType, store as blocksStore } from '@wordpress/blocks';
import { ToolbarButton } from '@wordpress/components';
import { useSelect, useDispatch } from '@wordpress/data';
import { __, sprintf } from '@wordpress/i18n';
Expand All @@ -24,31 +23,18 @@ import { unlock } from '../../lock-unlock';
*/
export default function BlockParentSelector() {
const { selectBlock } = useDispatch( blockEditorStore );
const { parentClientId, isVisible } = useSelect( ( select ) => {
const { parentClientId } = useSelect( ( select ) => {
const {
getBlockName,
getBlockParents,
getSelectedBlockClientId,
getBlockEditingMode,
getParentSectionBlock,
} = unlock( select( blockEditorStore ) );
const { hasBlockSupport } = select( blocksStore );
const selectedBlockClientId = getSelectedBlockClientId();
const parentSection = getParentSectionBlock( selectedBlockClientId );
const parents = getBlockParents( selectedBlockClientId );
const _parentClientId = parentSection ?? parents[ parents.length - 1 ];
const parentBlockName = getBlockName( _parentClientId );
const _parentBlockType = getBlockType( parentBlockName );
return {
parentClientId: _parentClientId,
isVisible:
_parentClientId &&
getBlockEditingMode( _parentClientId ) !== 'disabled' &&
hasBlockSupport(
_parentBlockType,
'__experimentalParentSelector',
true
),
};
}, [] );
const blockInformation = useBlockDisplayInformation( parentClientId );
Expand All @@ -61,10 +47,6 @@ export default function BlockParentSelector() {
highlightParent: true,
} );

if ( ! isVisible ) {
return null;
}

return (
<div
className="block-editor-block-parent-selector"
Expand Down
2 changes: 2 additions & 0 deletions packages/block-editor/src/components/block-toolbar/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@ export function PrivateBlockToolbar( {
! _isZoomOut &&
parentBlockType &&
getBlockEditingMode( parentClientId ) !== 'disabled' &&
getBlockEditingMode( selectedBlockClientId ) !==
'contentOnly' &&
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit (non-blocking): the block editing mode for the selected one is already available here. See the editingMode variable above.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated in 8a0be0e.

hasBlockSupport(
parentBlockType,
'__experimentalParentSelector',
Expand Down
Loading