Skip to content
Closed
Show file tree
Hide file tree
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
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
5 changes: 5 additions & 0 deletions schemas/json/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,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
},
"reusable": {
"description": "A block may want to disable the ability of being converted into a reusable block. By default all blocks can be converted to a reusable block. If supports reusable is set to false, the option to convert the block into a reusable block will not appear.",
"type": "boolean",
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