Skip to content
Merged
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
17 changes: 12 additions & 5 deletions packages/block-library/src/table-of-contents/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
store as blockEditorStore,
useBlockProps,
} from '@wordpress/block-editor';
import { createBlock, store as blocksStore } from '@wordpress/blocks';
import { createBlock } from '@wordpress/blocks';
import {
PanelBody,
Placeholder,
Expand Down Expand Up @@ -57,9 +57,16 @@ export default function TableOfContentsEdit( {
const blockProps = useBlockProps();
const disabledRef = useDisabled();

const listBlockExists = useSelect(
( select ) => !! select( blocksStore ).getBlockType( 'core/list' ),
[]
const canInsertList = useSelect(
( select ) => {
const { getBlockRootClientId, canInsertBlockType } = select(
blockEditorStore
);
const rootClientId = getBlockRootClientId( clientId );

return canInsertBlockType( 'core/list', rootClientId );
},
[ clientId ]
);

const {
Expand Down Expand Up @@ -222,7 +229,7 @@ export default function TableOfContentsEdit( {

const headingTree = linearToNestedHeadingList( headings );

const toolbarControls = listBlockExists && (
const toolbarControls = canInsertList && (
<BlockControls>
<ToolbarGroup>
<ToolbarButton
Expand Down