Skip to content

Commit

Permalink
Fix: Add isNavigationBlock utility to identify navigation blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
yogeshbhutkar committed Jan 14, 2025
1 parent aa38b22 commit 575cbaa
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
store as blocksStore,
isReusableBlock,
isTemplatePart,
isNavigationBlock,
__experimentalGetBlockLabel as getBlockLabel,
} from '@wordpress/blocks';
import { __ } from '@wordpress/i18n';
Expand Down Expand Up @@ -83,7 +84,9 @@ export default function useBlockDisplayInformation( clientId ) {
const attributes = getBlockAttributes( clientId );
const match = getActiveBlockVariation( blockName, attributes );
const isSynced =
isReusableBlock( blockType ) || isTemplatePart( blockType );
isReusableBlock( blockType ) ||
isTemplatePart( blockType ) ||
isNavigationBlock( blockType );
const syncedTitle = isSynced
? getBlockLabel( blockType, attributes )
: undefined;
Expand Down
12 changes: 12 additions & 0 deletions packages/blocks/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,18 @@ _Returns_

- `boolean`: True if a block contains at least one child blocks with inserter support and false otherwise.

### isNavigationBlock

Determines whether or not the given block is a navigation block. This is a special block type that is used to represent a navigation menu.

_Parameters_

- _blockOrType_ `Object`: Block or Block Type to test.

_Returns_

- `boolean`: Whether the given block is a navigation block.

### isReusableBlock

Determines whether or not the given block is a reusable block. This is a special block type that is used to point to a global block stored via the API.
Expand Down
1 change: 1 addition & 0 deletions packages/blocks/src/api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ export {
getBlockVariations,
isReusableBlock,
isTemplatePart,
isNavigationBlock,
getChildBlockNames,
hasChildBlocks,
hasChildBlocksWithInserterSupport,
Expand Down
12 changes: 12 additions & 0 deletions packages/blocks/src/api/registration.js
Original file line number Diff line number Diff line change
Expand Up @@ -579,6 +579,18 @@ export function isTemplatePart( blockOrType ) {
return blockOrType?.name === 'core/template-part';
}

/**
* Determines whether or not the given block is a navigation block. This is a
* special block type that is used to represent a navigation menu.
*
* @param {Object} blockOrType Block or Block Type to test.
*
* @return {boolean} Whether the given block is a navigation block.
*/
export function isNavigationBlock( blockOrType ) {
return blockOrType?.name === 'core/navigation';
}

/**
* Returns an array with the child blocks of a given block.
*
Expand Down

0 comments on commit 575cbaa

Please sign in to comment.