Skip to content

Commit

Permalink
disable rich text if attribute not part of bindings
Browse files Browse the repository at this point in the history
  • Loading branch information
glendaviesnz committed Feb 12, 2024
1 parent 5939c41 commit 945c859
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion packages/block-editor/src/components/rich-text/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,13 +146,27 @@ export function RichTextWrapper(
isSelected = selectionStart.clientId === clientId;
}

// Disable Rich Text editing if block bindings specify that.
// Disable Rich Text editing if block bindings specify that, or if there are block bindings
// but rich text attribute is not included in the bindings.
let shouldDisableEditing = false;
if ( blockBindings && blockName in BLOCK_BINDINGS_ALLOWED_BLOCKS ) {
const blockTypeAttributes = getBlockType( blockName ).attributes;

for ( const [ attributeName, attributeValue ] of Object.entries(
blockTypeAttributes
) ) {
if (
attributeValue.source === 'rich-text' &&
! Object.keys( blockBindings ).includes( attributeName )
) {
shouldDisableEditing = true;
}
}

const { getBlockBindingsSource } = unlock(
select( blockEditorStore )
);

for ( const [ attribute, args ] of Object.entries(
blockBindings
) ) {
Expand Down

0 comments on commit 945c859

Please sign in to comment.