Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
can-disable-block-note-supports
  • Loading branch information
shimotmk committed Oct 17, 2025
commit 7b85ef4b3bd38bbcfc6f10d0aefb0b1eb13bda09
4 changes: 2 additions & 2 deletions docs/reference-guides/core-blocks.md
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ Use the classic WordPress editor. ([Source](https://github.com/WordPress/gutenbe

- **Name:** core/freeform
- **Category:** text
- **Supports:** ~~className~~, ~~customClassName~~, ~~reusable~~
- **Supports:** ~~className~~, ~~customClassName~~, ~~note~~, ~~reusable~~
- **Attributes:** content

## Gallery
Expand Down Expand Up @@ -512,7 +512,7 @@ Your site doesn’t include support for this block. ([Source](https://github.com

- **Name:** core/missing
- **Category:** text
- **Supports:** interactivity (clientNavigation), ~~className~~, ~~customClassName~~, ~~html~~, ~~inserter~~, ~~reusable~~
- **Supports:** interactivity (clientNavigation), ~~className~~, ~~customClassName~~, ~~html~~, ~~inserter~~, ~~note~~, ~~reusable~~
- **Attributes:** originalContent, originalName, originalUndelimitedContent

## More
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
getBlockType,
serialize,
store as blocksStore,
hasBlockSupport,
} from '@wordpress/blocks';
import { DropdownMenu, MenuGroup, MenuItem } from '@wordpress/components';
import { useDispatch, useSelect } from '@wordpress/data';
Expand Down Expand Up @@ -89,6 +90,7 @@ export function BlockSettingsDropdown( {
openedBlockSettingsMenu,
isContentOnly,
isZoomOut,
canNote,
} = useSelect(
( select ) => {
const {
Expand All @@ -108,6 +110,8 @@ export function BlockSettingsDropdown( {
getBlockRootClientId( firstBlockClientId );
const parentBlockName =
_firstParentClientId && getBlockName( _firstParentClientId );
const firstBlockName =
firstBlockClientId && getBlockName( firstBlockClientId );

return {
firstParentClientId: _firstParentClientId,
Expand All @@ -125,6 +129,7 @@ export function BlockSettingsDropdown( {
isContentOnly:
getBlockEditingMode( firstBlockClientId ) === 'contentOnly',
isZoomOut: _isZoomOut(),
canNote: hasBlockSupport( firstBlockName, 'note', true ),
};
},
[ firstBlockClientId ]
Expand Down Expand Up @@ -217,6 +222,8 @@ export function BlockSettingsDropdown( {
const shouldShowBlockParentMenuItem =
! parentBlockIsSelected && !! firstParentClientId;

const shouldShowNoteMenuItem = canNote && count === 1;

return (
<BlockActions
clientIds={ clientIds }
Expand Down Expand Up @@ -334,7 +341,7 @@ export function BlockSettingsDropdown( {
</MenuItem>
</>
) }
{ count === 1 && (
{ shouldShowNoteMenuItem && (
<CommentIconSlotFill.Slot
fillProps={ { onClose } }
/>
Expand Down
1 change: 1 addition & 0 deletions packages/block-library/src/freeform/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
}
},
"supports": {
"note": false,
"className": false,
"customClassName": false,
"reusable": false
Expand Down
1 change: 1 addition & 0 deletions packages/block-library/src/missing/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
}
},
"supports": {
"note": false,
"className": false,
"customClassName": false,
"inserter": false,
Expand Down
5 changes: 5 additions & 0 deletions schemas/json/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,11 @@
"type": "boolean",
"default": true
},
"note": {
"description": "By default, a block can have a note added to it by a user from the block 'Options' dropdown To disable this behavior, set note to false.",
"type": "boolean",
"default": true
},
"layout": {
"description": "This value only applies to blocks that are containers for inner blocks. If set to `true` the layout type will be `flow`. For other layout types it's necessary to set the `type` explicitly inside the `default` object.",
"oneOf": [
Expand Down
36 changes: 36 additions & 0 deletions test/e2e/specs/editor/various/block-comments.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -602,6 +602,42 @@ test.describe( 'Block Comments', () => {
} )
).toBeFocused();
} );

test( 'does not allow comments of blocks that do not support the feature', async ( {
editor,
page,
pageUtils,
} ) => {
await pageUtils.pressKeys( 'access+o' );

const listView = page.getByRole( 'treegrid', {
name: 'Block navigation structure',
} );

await editor.insertBlock( {
name: 'my-plugin/block-that-does-not-support-comments',
} );

// Select via keyboard.
await pageUtils.pressKeys( 'primary+a' );

const blockActionsTrigger = listView.getByRole( 'button', {
name: 'Options',
} );

await blockActionsTrigger.click();

const addNoteMenuItem = page
.getByRole( 'menu', {
name: 'Options',
} )
.getByRole( 'menuitem', {
name: 'Add note',
} );

// Expect the Add note menu item not to exist at all.
await expect( addNoteMenuItem ).toBeHidden();
} );
} );
} );

Expand Down
Loading