question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support custom legend id in fieldset for FormGroup and RadioButtonGroup React components

See original GitHub issue

Summary

For both the FormGroup and RadioButtonGroup React components, we need a way to supply a custom id to the legend, and it must correspond to the aria-labelledby attribute of the fieldset.

Justification

We have use cases in IBM Cloud UI which need this support to fully support screen readers.

“Must have” functionality

We have use cases in IBM Cloud UI where a settings dropdown menu is used in an extended version of the Carbon DataTable component. The settings menu has sections of radio buttons, check boxes, and a button.

We have fieldsets inside the settings menu, which need explicit hook up for the fieldset’s legend as its label, in order for screen readers to work properly.

We do this in 2 parts:

  • add an id to the legend
  • add aria-labelledby=[the unique legend id]

Currently, we can supply arbitrary prop to FormGroup, which is populated to the fieldset, but there is no way to supply custom attributes to legend (hence we cannot specify an id for the legend). As for RadioButtonGroup, there is no way to supply any custom attributes to fieldset or legend at all.

We need a way to supply and id to the legend, and it must correspond to the aria-labelledby attribute of the fieldset, for example:

image

Specific timeline issues / requests

We need this ASAP to close a11y issues around screen readers support.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
holmanszecommented, Jun 30, 2021

@emyarod - so the lengendId, if provided, corresponds to the legend’s id and fieldset’s aria-labelledby, correct? If yes it is perfect.

My only concern around autogenerating the id (as opposed to providing custom ones) is ensuring uniqueness of ids when there are multiple fieldset/legend on the page. The component itself doesn’t have the knowledge of the existence of other instances on the same page. If we expose custom id via prop, it is consumer’s responsibility to ensure uniqueness, which is possible because the consumer knows the instances of fieldset/legend on the page and can provide unique ids accordingly.

0reactions
emyarodcommented, Jun 30, 2021

@joshblack @holmansze I can autogenerate the id by default but the question is around exposing a prop to modify that id or if it’s controlled by the aria-labelledby prop. I added the legendId prop since it felt intuitive compared to providing an aria-labelledby without also setting the object label (like providing for on an input with no corresponding label). I don’t have a preference either way but interested in hearing more

Read more comments on GitHub >

github_iconTop Results From Across the Web

Redux Form, Radio Button Fields, how to support variable ...
What's strange is if I update: value={jobTitle.id} to value="anything" then the radio buttons can be selected. I'm not seeing anything in the ...
Read more >
Legend on form radio button group not accessible to screen ...
Describe the bug. The label for a b-form-group containing a b-form-radio-group is not accessible to the ChromeVox screen reader. Instead of ...
Read more >
Grouping Controls | Web Accessibility Initiative (WAI) - W3C
The legend for a group of controls can also highlight common attributes of all controls, ... Radio button groups should always be grouped...
Read more >
Form - Ant Design
High performance Form component with data scope management. Including data collection, verification, and styles.
Read more >
<fieldset>: The Field Set element - HTML - MDN Web Docs
The HTML element is used to group several controls as well as labels ( ) within a web form.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found