Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
9 changes: 8 additions & 1 deletion packages/block-editor/src/components/rich-text/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -253,8 +253,15 @@ export function RichTextWrapper(
blockContext,
]
);
const isInsidePatternOverrides = !! blockContext?.[ 'pattern/overrides' ];
const hasOverrideEnabled =
blockBindings?.__default?.source === 'core/pattern-overrides';

const shouldDisableEditing = readOnly || disableBoundBlock;
const shouldDisableForPattern =
isInsidePatternOverrides && ! hasOverrideEnabled;

const shouldDisableEditing =
readOnly || disableBoundBlock || shouldDisableForPattern;

const { getSelectionStart, getSelectionEnd, getBlockRootClientId } =
useSelect( blockEditorStore );
Expand Down
61 changes: 61 additions & 0 deletions test/e2e/specs/editor/various/pattern-overrides.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -789,6 +789,67 @@ test.describe( 'Pattern Overrides', () => {
await expect( buttonLink ).toHaveAttribute( 'rel', /^\s*nofollow\s*$/ );
} );

test( 'should disable editing for pattern blocks without overrides enabled, even when mixed with bound attributes', async ( {
page,
admin,
requestUtils,
editor,
} ) => {
const { id } = await requestUtils.createBlock( {
title: 'Pattern',
content: `<!-- wp:paragraph {"metadata":{"name":"Post Meta Binding","bindings":{"__default":{"source":"core/pattern-overrides"}}}} -->
<p>Edit me</p>
<!-- /wp:paragraph -->
<!-- wp:buttons -->
<div class="wp-block-buttons"><!-- wp:button {"metadata":{"name":"Read Only Button","bindings":{"url":{"source":"core/post-meta","args":{"key":"Post Meta Binding"}}}}} -->
<div class="wp-block-button"><a class="wp-block-button__link wp-element-button">Read Only Button Text</a></div>
<!-- /wp:button --></div>
<!-- /wp:buttons -->`,
status: 'publish',
} );

await admin.createNewPost();
await editor.insertBlock( {
name: 'core/block',
attributes: { ref: id },
} );

const patternBlock = editor.canvas.getByRole( 'document', {
name: 'Block: Pattern',
} );

await expect( patternBlock.getByText( 'Edit me' ) ).toBeVisible();
await expect(
patternBlock.getByText( 'Read Only Button Text' )
).toBeVisible();

const editableParagraph = patternBlock
.getByRole( 'document', {
name: 'Block: Paragraph',
includeHidden: true,
} )
.filter( { hasText: 'Edit me' } );
const nonEditableButton = patternBlock
.getByRole( 'document', {
name: 'Block: Button',
exact: true,
includeHidden: true,
} )
.filter( { hasText: 'Read Only Button Text' } );

await editableParagraph.click();
await editableParagraph.focus();
await page.keyboard.type( ' - Edited' );
await expect( editableParagraph ).toHaveText( 'Edit me - Edited' );

// Button with only URL binding (no pattern overrides) should not have editable text.
await nonEditableButton.click();
const initialText = await nonEditableButton.textContent();
await page.keyboard.type( 'Edited' );
const finalText = await nonEditableButton.textContent();
expect( initialText ).toBe( finalText );
} );

test( 'resets overrides after clicking the reset button', async ( {
page,
admin,
Expand Down
Loading