Skip to content
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

fix(radiobuttongroup): accessibility #17885

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6591,6 +6591,9 @@ Map {
"helperText": Object {
"type": "node",
},
"hideLegendText": Object {
"type": "bool",
},
"invalid": Object {
"type": "bool",
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ Playground.args = {
invalidText: 'Invalid selection',
warn: false,
warnText: 'Please notice the warning',
hideLegendText: false,
};

Playground.argTypes = {
Expand Down Expand Up @@ -272,6 +273,13 @@ Playground.argTypes = {
type: 'text',
},
},
hideLegendText: {
description:
'Specify whether the `legendText` should be hidden, or not. Provide a `legendText` to meet accessibility standards if `hideLegendText` is true',
control: {
type: 'boolean',
},
},
orientation: {
description: 'Provide how radio buttons should be displayed',
control: 'select',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ export interface RadioButtonGroupProps
*/
helperText?: ReactNode;

/**
* Specify whether the `legendText` should be hidden, or not. Provide a `legendText` to meet accessibility standards if `hideLegendText` is true
*/
hideLegendText?: boolean;

/**
* Specify whether the control is currently invalid
*/
Expand Down Expand Up @@ -135,6 +140,7 @@ const RadioButtonGroup = React.forwardRef(
defaultSelected,
disabled,
helperText,
hideLegendText = false,
invalid = false,
invalidText,
labelPosition = 'right',
Expand Down Expand Up @@ -247,6 +253,10 @@ const RadioButtonGroup = React.forwardRef(
});
}

const legendTextClasses = classNames(`${prefix}--label`, {
[`${prefix}--visually-hidden`]: hideLegendText,
});

return (
<div className={wrapperClasses} ref={mergeRefs(divRef, ref)}>
<fieldset
Expand All @@ -256,7 +266,7 @@ const RadioButtonGroup = React.forwardRef(
aria-describedby={showHelper && helperText ? helperId : undefined}
{...rest}>
{legendText && (
<Legend className={`${prefix}--label`}>
<Legend className={legendTextClasses}>
{legendText}
{normalizedSlug}
</Legend>
Expand Down Expand Up @@ -313,6 +323,11 @@ RadioButtonGroup.propTypes = {
*/
helperText: PropTypes.node,

/**
* Specify whether the `legendText` should be hidden, or not. Provide a `legendText` to meet accessibility standards if `hideLegendText` is true
*/
hideLegendText: PropTypes.bool,

/**
* Specify whether the control is currently invalid
*/
Expand Down
Loading