Skip to content

Commit

Permalink
fix(RadioButton): fix a11y issues with RadioButtonGroup (#3276)
Browse files Browse the repository at this point in the history
* fix(RadioButton): fix a11y violation on Radio Button pages

* fix(ComponentDemo): update knob container code

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
Co-authored-by: Alison Joseph <alison.joseph@us.ibm.com>
  • Loading branch information
3 people authored Nov 28, 2022
1 parent 945df50 commit 0b3df87
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 34 deletions.
6 changes: 4 additions & 2 deletions src/components/ComponentDemo/ComponentDemo.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -233,14 +233,16 @@

// custom classnames are being applied to both fieldset and label
// https://github.com/carbon-design-system/carbon/issues/4572
fieldset.form-group {
fieldset.form-group,
fieldset[class*='--radio-button-group'] {
padding: 1rem;
padding-top: 0;
margin-bottom: 0;
border-bottom: 1px solid $ui-03;
}

fieldset.form-group:last-of-type {
fieldset.form-group:last-of-type,
fieldset[class*='--radio-button-group']:last-of-type {
border-bottom: 0;
}

Expand Down
40 changes: 18 additions & 22 deletions src/components/ComponentDemo/KnobContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,7 @@ const Component = ({
<div
role="group"
aria-labelledby={componentGroupId}
className={componentKnobWrapper}
>
className={componentKnobWrapper}>
{booleanKnobs.length > 0 && (
<FormGroup className={formGroup} legendText="Modifiers">
{booleanKnobs.map(([name, info]) => (
Expand Down Expand Up @@ -228,22 +227,21 @@ const Knob = ({
}

return (
<FormGroup className={formGroup} legendText={name}>
<RadioButtonGroup
onChange={(val) => updateKnob(val)}
defaultSelected={defaultSelected}
name={name}
orientation="vertical"
>
{values.map(({ value }) => (
<RadioButton
key={`${inputId}-${value}`}
value={value}
labelText={value.replace(/'/g, '')}
/>
))}
</RadioButtonGroup>
</FormGroup>
<RadioButtonGroup
className={formGroup}
legendText={name}
onChange={(val) => updateKnob(val)}
defaultSelected={defaultSelected}
name={name}
orientation="vertical">
{values.map(({ value }) => (
<RadioButton
key={`${inputId}-${value}`}
value={value}
labelText={value.replace(/'/g, '')}
/>
))}
</RadioButtonGroup>
);
}
return '';
Expand Down Expand Up @@ -291,15 +289,13 @@ const KnobContainer = ({ knobs, code, setCode, initialCode, variantId }) => {
<Form
className={cx(knobContainer, {
[knobContainerCollapsed]: isMobile && isKnobContainerCollapsed,
})}
>
})}>
{isMobile && (
<div className={iconButtonRow}>
<button
className={iconButton}
type="button"
onClick={() => setIsKnobContainerCollapsed(true)}
>
onClick={() => setIsKnobContainerCollapsed(true)}>
<Close size={20} />
</button>
</div>
Expand Down
6 changes: 1 addition & 5 deletions src/pages/components/radio-button/code.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,9 @@ usage documentation, see the Storybooks for each framework below.
}}
>
{`
<FormGroup
legendText="Radio button heading"
>
<RadioButtonGroup
defaultSelected="default-selected"
legend="Group Legend"
legendText="Radio button heading"
name="radio-button-group"
valueSelected="default-selected"
>
Expand All @@ -109,7 +106,6 @@ usage documentation, see the Storybooks for each framework below.
value="disabled"
/>
</RadioButtonGroup>
</FormGroup>
`}
</ComponentVariant>
</ComponentDemo>
6 changes: 1 addition & 5 deletions src/pages/components/radio-button/usage.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,9 @@ checkboxes allow the user to select multiple items.
}}
>
{`
<FormGroup
legendText="Radio button heading"
>
<RadioButtonGroup
defaultSelected="default-selected"
legend="Group Legend"
legendText="Radio button heading"
name="radio-button-group"
valueSelected="default-selected"
>
Expand All @@ -122,7 +119,6 @@ checkboxes allow the user to select multiple items.
value="disabled"
/>
</RadioButtonGroup>
</FormGroup>
`}
</ComponentVariant>
</ComponentDemo>
Expand Down

1 comment on commit 0b3df87

@vercel
Copy link

@vercel vercel bot commented on 0b3df87 Nov 28, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.