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 API: Improve ariaLabel block support #68764

Open
t-hamano opened this issue Jan 18, 2025 · 2 comments
Open

Block API: Improve ariaLabel block support #68764

t-hamano opened this issue Jan 18, 2025 · 2 comments
Labels
[Feature] Block API API that allows to express the block paradigm. [Type] Enhancement A suggestion for improvement.

Comments

@t-hamano
Copy link
Contributor

t-hamano commented Jan 18, 2025

Issues and PRs related to this discussion:

What problem does this address?

Adding ariaLabel block support to a block makes it possible to set the aria-label attribute internally - it does not expose a UI for setting this attribute.

This attribute can be injected into a block HTML or theme template like this:

<!-- wp:navigation {"ref":1,"ariaLabel":"My Navigation"} /-->

<!-- wp:navigation {"ariaLabel":"<?php esc_attr_e( 'Privacy', 'mny-theme' ); ?>"} -->
	<!-- wp:navigation-link {"label":"<?php esc_html_e( 'Privacy Policy', 'twentytwentyfour' ); ?>","url":"#"} /-->
	<!-- wp:navigation-link {"label":"<?php esc_html_e( 'Terms and Conditions', 'twentytwentyfour' ); ?>","url":"#"} /-->
	<!-- wp:navigation-link {"label":"<?php esc_html_e( 'Contact Us', 'twentytwentyfour' ); ?>","url":"#"} /-->
<!-- /wp:navigation -->

The schema for this support references the aria-label attribute on HTML elements, but dynamic blocks do not save HTML to the database, so when you edit and save the content or template, the aria-label value is lost because it cannot be referenced.

Especially for the Navigation block, i.e. nav element, the loss of aria-label attribute values ​​is a big problem. We need to find a way to solve this problem.

What is your proposed solution?

The three approaches I can think of are:

1. Add ariaLabel "attribute" in addition to block support

The ariaLabel block support respects existing attribute definitions. By explicitly defining the ariaLabel attribute in a dynamic block, the value will not be lost as it will be preserved as part of the comment delimiter (Related discussion).

2. Extend block support

Currently, the value type of this block support is a boolean value. We may be able to extend this to allow us to decide how we want to reference the value. Something like this:

{
	"name": "core/navigation",
	"supports": {
		"ariaLabel": "delimiter"
	}
}

This approach was also attempted with anchor support (You can see the series of efforts at #51402.).

3. Change the block support schema

We could also change the block support schema itself, which means we always store values ​​as part of the comment delimiter, rather than referencing the stored content.

This approach might require us to add a block deprecation to blocks that already have this block support, and it might affect developers who already use this block support.

In the past we've run into issues with broken blocks when changing the schema for anchor support. See #48232 for more details.

Other suggestions

Although not directly related to this support failure, it's also worth discussing whether we should expose a UI for editing the aria-label attribute by default.

cc @Mamaduka @fabiankaegy @afercia @carolinan @aaronrobertshaw @talldan

@t-hamano t-hamano added [Feature] Block API API that allows to express the block paradigm. [Type] Enhancement A suggestion for improvement. labels Jan 18, 2025
@fabiankaegy
Copy link
Member

Thanks for putting this together :)

The one thing I don't understand is why we need to store the aria-label attribute in the client side generated block markup at all? Why could we not handle it like other dynamic values and only store it in the HTML comment and then use the HTML_Tag_Processor on the render_block hook to dynamically inject it into the markup? 🤔

Regarding the block support becoming more granular. I think it would be nice to also have some options to enable / disable a UI for the setting. Today the UI is not coming from the block support which as far as I know is unique to this support. All others have an UI attached to the support.

@t-hamano
Copy link
Contributor Author

The one thing I don't understand is why we need to store the aria-label attribute in the client side generated block markup at all?

Oh, I missed that. There are challenges to overcome, but I think it's definitely possible. I've added a "3. Change the block support schema" section to this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Block API API that allows to express the block paradigm. [Type] Enhancement A suggestion for improvement.
Projects
None yet
Development

No branches or pull requests

2 participants