#51299 closed defect (bug) (fixed)
Remove the title attribute from Walker_Nav_Menu
Reported by: | Hareesh Pillai | Owned by: | joedolson |
---|---|---|---|
Milestone: | 6.7 | Priority: | normal |
Severity: | normal | Version: | |
Component: | Menus | Keywords: | title-attribute has-patch commit |
Focuses: | accessibility | Cc: |
Description
As highlighted in one of the comments for the Accessibility Team’s goals for WordPress 5.6 and beyond
post, the title attribute has to be removed from nav walker menus. This creates repetitive screen reader announcements for some screen reader/browser combinations.
Attachments (3)
Change History (35)
This ticket was mentioned in Slack in #accessibility by afercia. View the logs.
4 years ago
#3
@
4 years ago
- Milestone changed from Awaiting Review to 5.6
- Owner set to Hareesh Pillai
- Status changed from new to assigned
@
4 years ago
Title attribute not displayed anymore but keep the variable for backward compatibility
#4
@
4 years ago
- Keywords has-patch added; needs-patch removed
In 51299.diff, we're not displaying title
attribute anymore, but we keep the (emptied) variable for backward compatibility.
Any thoughts on this approach, @afercia or @SergeyBiryukov?
#5
follow-up:
↓ 6
@
4 years ago
Thanks for the patch! Some thoughts:
- From a technical point of view, if the
$title
variable is not used anywhere else in the class and is not passed to any filters, I don't think it makes sense to keep it. I see it being passed to thenav_menu_item_title
filter, but the result of that is no longer used anywhere after this patch. - I think this will have big front-end implications for a lot of websites. For example, https://wordpress.org/ has these title attributes on some menu items. With this change, would they be gone?
- Documentation: "Documentation, tutorials, best practices."
- Forums: "Support and discussion forums."
- Five for the Future: "How five percent is powering the next generation of the web"
- Would this make the "Title Attribute" input on the Menus screen completely unused?
- How would developers be able to restore previous behavior?
#6
in reply to:
↑ 5
@
4 years ago
I'd agree there are backwards compatibility concerns here.
So far, in the last years the accessibility team made an effort to remove as many title attributes as possible from files in the wp-admin
directory. As mentioned on the tracking ticket #24766, that brought down the occurrences of title attributes in the wp-admin
codebase from 157 in 37 files to 16 occurrences. We can't just remove them.
It would be nice if WordPress would have a well established deprecation policy for this kind of things. Given the lack of it, I'd tend to think there's the need to explore a way to make these changes in a non-breaking way.
I'm not sure a new theme-support item would be the best option, as it would restrict important accessibility improvements only to the themes that declare support for that option. Also, I've seen plugins (incorrectly) using title attributes for all sort of things, for example image gallery plugins. It would be great to explore new ideas to make the removal of title attributes not break anything. Any suggestions welcome :)
However, when it comes to title attributes in the wp-includes
directory, things are pretty different. Most of these title attributes are used in functions meant to be used in the front end.
Replying to SergeyBiryukov:
- I think this will have big front-end implications for a lot of websites. For example, https://wordpress.org/ has these title attributes on some menu items. With this change, would they be gone?
- Documentation: "Documentation, tutorials, best practices."
- Forums: "Support and discussion forums."
- Five for the Future: "How five percent is powering the next generation of the web"
For the specific case of wp.org, in https://meta.trac.wordpress.org/ticket/4091 the accessibility team asked to remove the title attributes from the menu and that was done for the top level items. It appears the sub-items were missed :)
This ticket was mentioned in Slack in #accessibility by afercia. View the logs.
4 years ago
#8
@
4 years ago
- Keywords needs-dev-note added
Per @audrasjb in Slack conversation:
This change will probably deserve a small dev note, too
#9
@
4 years ago
For backward compatibility, I think a filter would fit better than using theme-support. If there is a reason to keep title attributes, that should carry over when switching themes.
Suggested behavior:
If the filter would return false,
- no title attributes output and
- the menus admin page does not show the input field for editing titles.
If the filter is true (and/or customized), the nav menu would include the attributes
- when provided and
- when they do not match the link text (automatically removing when redundant).
Adding the filter would only make sense if false is default, though. (If you know you don't want the attributes included, you can empty the input for each list item already.)
Another possibility is following @williampatton's idea for deprecation in themes, so the change is established as opt-in for one release and then the default is switched in the next.
This ticket was mentioned in Slack in #accessibility by audrasjb. View the logs.
4 years ago
#11
@
4 years ago
- Milestone changed from 5.6 to Future Release
Moving to Future release as this ticket still needs some discussion.
@sabernhardt ’s approach looks good to me by the way.
#12
@
4 years ago
- Keywords has-patch removed
Removing has-patch
as the implementation may change once an implementation direction is decided upon.
#13
@
4 years ago
- Keywords needs-dev-note removed
Removing needs-dev-note as this ticket isn't milestoned for a specific release yet nor any change has been committed yet.
#14
@
3 years ago
- Keywords needs-patch added
I'm not sure now whether adding a filter is worth much. With or without that, we can avoid showing/speaking exactly the same information as the link text in the title attribute.
So 51299.1.diff takes care of removing redundant tooltips. The $title
variable needed to be moved earlier.
#16
@
3 years ago
In 51299.2.diff, only the_title
filter is moved before $atts
array. Also, the condition for removing superfluous title attributes is grouped with the existing conditional statement to avoid comparing against an empty string.
This ticket was mentioned in Slack in #accessibility by joedolson. View the logs.
5 months ago
#18
@
5 months ago
- Milestone changed from Future Release to 6.7
- Owner changed from Hareesh Pillai to joedolson
- Status changed from assigned to accepted
This ticket was mentioned in Slack in #accessibility by joedolson. View the logs.
4 months ago
This ticket was mentioned in PR #7413 on WordPress/wordpress-develop by @sabernhardt.
3 months ago
#20
Removes redundant tooltips from Walker_Nav_Menu::start_el()
This ticket was mentioned in Slack in #accessibility by joedolson. View the logs.
2 months ago
@sabernhardt commented on PR #7413:
2 months ago
#22
51299.2.diff compared the title attribute against the item title, filtered only by the_title
. If I had a good reason to compare before nav_menu_item_title
three years ago, I did not explain it on the ticket, and I do not understand that decision today.
This PR now checks the title attribute after both the_title
and nav_menu_item_title
filters, and it still removes redundant tooltips before the nav_menu_link_attributes
hook.
@joedolson commented on PR #7413:
2 months ago
#23
The value that is rendered is the version that's passed through both filters, and if we want to prevent duplicate values, we should generally pass through both filters.
However, Twenty Seventeen inserts an icon using the nav_menu_item_title
filter. Other plugins and themes may do similar things. That will result in a difference in value, even though the accessible name may be unchanged.
Because of that, I'm wondering if we actually want to get those as two separate variables and compare against both of them, ignoring the title attribute if it matches either value.
@sabernhardt commented on PR #7413:
2 months ago
#24
Twenty Seventeen inserts an icon using the
nav_menu_item_title
filter.
That might be why I moved the comparison earlier in 51299.2.diff.
I'm wondering if we actually want to get those as two separate variables and compare against both of them, ignoring the title attribute if it matches either value.
Maybe. Switching trim()
to wp_strip_all_tags()
could be another option.
#25
@
2 months ago
Test Report
Patch tested: https://github.com/WordPress/wordpress-develop/pull/7413
Environment
- WordPress Playground
- WordPress: 6.7-alpha-20240923.060126
- Browser: Chrome (127.0.6533.119)
- Theme: Twenty Twenty-One
- Active Plugins:
- None
Actual Results
- ✅ Issue resolved with patch.
Supplemental Artifacts
@joedolson commented on PR #7413:
2 months ago
#26
wp_strip_all_tags()
would work for the twenty seventeen example, but there are potentially other cases it wouldn't work for. I'm imagining cases where people are inserting file extensions, screen reader text strings, where they're changing link texts dynamically based on the current user or logged in state, etc.
I think that the most valid use case of this attribute is where it definitely provides something other than the link text, and that shouldn't generally overlap with text that might be shown visually. I'd rather err in the direction of removing more title attributes than less.
#27
@
2 months ago
Tested, and this works as expected. Show a title attribute if it is unique, but omits it if it is a match, and also accounts for filtered values that may result in a mismatch in some cases, but still match others. There may be cases where this will remove title attributes that are intended, but those cases will be rare - and I think that's acceptable given the long-stated intention of removing title attributes as much as possible.
#30
@
2 months ago
Note: there is a comment above requesting a dev note, but that was based on an earlier version of the patch that removed all support for title
attributes. This reduced scope patch only omits title attributes with duplicate values, and I'm not sure that really requires a dev note.
@joedolson commented on PR #7413:
2 months ago
#31
In r59177
This ticket was discussed during today's accessibility bug-scrub: agreed to move it to the 5.6 milestone.