Opened 2 weeks ago
Last modified 3 days ago
#62548 new defect (bug)
Move checkbox input outside of the wrapping `label` element.
Reported by: | kkmuffme | Owned by: | |
---|---|---|---|
Milestone: | 6.8 | Priority: | normal |
Severity: | trivial | Version: | |
Component: | Administration | Keywords: | has-patch |
Focuses: | accessibility | Cc: |
Description (last modified by )
[Edited to change the intent of the ticket. Original intent below.]
<label for="dashboard_right_now-hide"> <input class="hide-postbox-tog" name="dashboard_right_now-hide" type="checkbox" id="dashboard_right_now-hide" value="dashboard_right_now"/>At a Glance </label>
The for=
is redundant and can be removed, since the input is wrapped in the label
There are a couple other ones there with the same issue
Change History (8)
This ticket was mentioned in PR #7887 on WordPress/wordpress-develop by @benazeer.
2 weeks ago
#1
- Keywords has-patch added
@benazeer commented on PR #7887:
2 weeks ago
#2
I’m not entirely sure if it’s considered best practice to omit the for attribute from a <label> tag when it wraps an <input> element. While the association between the label and input is implicit in this case, I’d appreciate confirmation on whether this approach aligns with accessibility and coding standards.
If this is acceptable, you can proceed with this PR fix. Thank you!
#3
@
2 weeks ago
- Description modified (diff)
- Focuses accessibility added
As @afercia noted in ticket:47141#comment:1, the accessibility coding standards in 2018 said that the labels should not combine both methods.
Existing code uses a mixture of explicitly and implicitly labeled fields, but all new code must use an explicitly associated
<label>
element (using for/id attributes and not wrapping the form control).
[34991] removed the for
attribute in the implicitly associated hide-column-tog
checkbox labels with list tables, but other screen options still have the for
attribute:
- the
hide-postbox-tog
checkboxes on the Dashboard wp_welcome_panel-hide
on the Dashboardeditor-expand-toggle
in the Classic Editor
Removing the for
attributes from these implicitly labeled checkboxes would be simple. If switching to explicit association, the input/label pairs should still have a wrapper span
to make sure they stay together when they appear on multiple lines.
#4
@
13 days ago
If we change this, it should be to remove the wrapping label
, so that the only label relationship is the explicit one. This is a relatively low priority change, but in most cases not complex. However, removing wrapping label
elements can have significant impact on styling (e.g., if there's a flex or grid context involving that label), so they need to be handled carefully in individual cases.
But in no circumstances should we elect to remove the for
attributes so that we only use implicit labeling.
This ticket was mentioned in Slack in #accessibility by joedolson. View the logs.
6 days ago
#6
@
6 days ago
- Milestone changed from Awaiting Review to 6.8
This is referring to the Screen elements form in screen options. There's no impact on styles by moving the input
out of the wrapping label
, so we might as well do that.
#7
@
6 days ago
- Description modified (diff)
- Summary changed from Redundant "for" in wp-admin dashboard to Move checkbox input outside of the wrapping `label` element.
#8
@
3 days ago
Thank you for pointing that out.
Since there’s no impact on styles by moving the input out of the wrapping label, it makes sense to proceed with this change. This adjustment ensures better markup semantics without affecting the visual output.
I have updated this in recent commit in this PR https://github.com/WordPress/wordpress-develop/pull/7887
Let me know if there's anything else that needs attention.
Trac ticket: https://core.trac.wordpress.org/ticket/62548