ToggleGroupControl: Fix accessible association of help text#76740
ToggleGroupControl: Fix accessible association of help text#76740
help text#76740Conversation
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
|
Size Change: -18 B (0%) Total Size: 7.66 MB
ℹ️ View Unchanged
|
|
Flaky tests detected in 6c2d26c. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/23363853538
|
What?
Fix the
helpprop onToggleGroupControlso that it is programmatically associated with the control viaaria-describedby. Also refactor the component to useuseBaseControlPropsmore fully, delegating label and help rendering toBaseControl.Why?
The
helptext was being rendered visually but had no accessible association with the radiogroup (or button group, in theisDeselectablecase). Screen reader users would not hear the help text when interacting with the control.The component was also hand-rolling its
hideLabelFromVisionlogic and not using theidfromuseBaseControlProps, duplicating whatBaseControlalready provides.How?
useBaseControlPropswithid,help,label, andhideLabelFromVision, and spread the returned props ontoBaseControland the inner control.idand addsaria-describedbyto the radiogroup/button group.BaseControlnow handles label rendering (including thehideLabelFromVisioncase), removing the need for the manualVisualLabelWrapperandBaseControl.VisualLabelusage.VisualLabelWrapperstyled component (and thestyledimport from Emotion).Testing Instructions
Automated
New unit tests cover:
hideLabelFromVisionis truehelptext is associated with theradiogroupviaaria-describedbyhelptext is associated with thegroupviaaria-describedbywhenisDeselectableManual
ToggleGroupControlstory in Storybook.helpprop to some text.aria-describedbypointing to the help text element.Use of AI Tools
Cursor with Claude was used to author this PR.