-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Navigation: Add ariaLabel block support #54418
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@carolinan This works great up until you add a standard navigation block. Once that happens, the custom aria-label
goes away. Not sure why that is happening.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I somehow managed to mess up the block code in testing. This works with a custom ariaLabel
block attribute and it also works along side a navigation block with a menu pulled from Core.
Tagging @getdave so he is aware.
I think this looks good.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This works as expected and the code is simple.
I just added a minor note, but it's not a blocker - just personal preference for code readability.
Co-authored-by: Ari Stathopoulos <[email protected]>
@aristath Nice suggestion. Didn't know |
@alexstine yeah, it was added in PHP 7, and since that is now the lowest version of PHP that WP supports, we can safely use it in the project 👍 |
What?
This PR enables the
ariaLabel
block support for the navigation block. This allows developers to manually add an aria-label to the<nav>
element when they are using placeholder links and not an existing menu.Why?
In Twenty Twenty-Four, the footer design has a 3 column menu, each column uses its own navigation block.
Each navigation block has placeholder links in the markup. To improve the accessibility, the three
<nav>
elements need to be differentiated and identifiable: they need an aria-label.See WordPress/twentytwentyfour#345
How?
Enables the ariaLabel block support in block.json.
Adds a condition that populates a variable in the index.php file with the ariaLabel attribute, if it is set.
This allows developers to include the aria-label in the following format:
"ariaLabel":"Custom label here"
And when the user updates the navigation block to use a menu the correct aria-label, the menu name, will be used because it will override the manually entered value.
Testing Instructions
Please add the example code above to your theme. Either to a block theme template,
or copy and paste the code into the code editor in a post or page.
View the navigation on the front of the website, view the HTML source, and confirm if the label is printed correctly.
Next, please test that the aria-label still works correctly for a regular navigation block with a menu assigned to it:
Add a new navigation block, create a menu, note the name of the menu in the Advanced panel, save, and view the navigation on the front. View the HTML source, and confirm if the label is printed correctly.