-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Comments
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 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. |
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. |
I discovered that the Using this logic, we may be able to make this support work for dynamic blocks as well, by injecting the Furthermore, this approach may also be applicable to anchor support: #51402 |
This comment made me realize that I was missing some server-side processing for the For example, adding this support in the Archives block would result in an error like this: API response: {
"code": "rest_invalid_param",
"message": "Invalid parameter(s): attributes",
"data": {
"status": 400,
"params": {
"attributes": "ariaLabel is not a valid property of Object."
},
"details": {
"attributes": {
"code": "rest_additional_properties_forbidden",
"message": "ariaLabel is not a valid property of Object.",
"data": null
}
}
}
} |
I tried to add server-side support in this branch, but ran into some issues with backwards compatibility. We need to support the This means that $wrapper_attributes = get_block_wrapper_attributes( array( 'aria-label' => $attributes['aria-label'] ) ); That said, this support wasn't perfect from the start, so we might not need to worry about these backwards compatibility issues. What do you think? |
The I think blocks had to explicitly pass |
Issues and PRs related to this discussion:
ariaLabel
block support to the Tag Cloud block)What problem does this address?
Adding
ariaLabel
block support to a block makes it possible to set thearia-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:
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:
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
The text was updated successfully, but these errors were encountered: