Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Block Bindings: Update label for bound paragraphs and headings #65114

Closed
wants to merge 7 commits into from
16 changes: 13 additions & 3 deletions packages/block-editor/src/hooks/use-bindings-attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ export function getBindableAttributes( blockName ) {
return BLOCK_BINDINGS_ALLOWED_BLOCKS[ blockName ];
}

export const withBlockBindingSupport = createHigherOrderComponent(
export const editWithBlockBindings = createHigherOrderComponent(
( BlockEdit ) => ( props ) => {
const registry = useRegistry();
const blockContext = useContext( BlockContext );
Expand Down Expand Up @@ -296,9 +296,18 @@ export const withBlockBindingSupport = createHigherOrderComponent(
</>
);
},
'withBlockBindingSupport'
'editWithBlockBindings'
);

function labelWithBlockBindings( settings ) {
return ( attributes, { context } ) => {
if ( attributes?.metadata?.bindings && context === 'accessibility' ) {
return 'Overriding label';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For now, I just check whether the paragraph is bound and, if so, return the label Paragraph with dynamic content.

Is Overriding label a leftover added for testing? In any case, it should be translatable.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the feedback! Rather than hardcoding this, I've now modified the PR so it reads the actual bindings values. I've updated the PR description accordingly.

}
return settings.__experimentalLabel?.( attributes, { context } );
};
}

/**
* Filters a registered block's settings to enhance a block's `edit` component
* to upgrade bound attributes.
Expand All @@ -314,7 +323,8 @@ function shimAttributeSource( settings, name ) {

return {
...settings,
edit: withBlockBindingSupport( settings.edit ),
edit: editWithBlockBindings( settings.edit ),
__experimentalLabel: labelWithBlockBindings( settings ),
};
}

Expand Down
Loading