Skip to content

Commit

Permalink
Remove invisible InputGroup and Radio labels from code since pare…
Browse files Browse the repository at this point in the history
…nt `<fieldset>`s still have accessible `<legend>`
  • Loading branch information
adamkudrna committed Sep 27, 2023
1 parent 23b6e14 commit 2e8b1ac
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 31 deletions.
19 changes: 9 additions & 10 deletions src/components/InputGroup/InputGroup.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,16 +69,15 @@ export const InputGroup = ({
>
{label}
</legend>
<div
aria-hidden
className={classNames(
styles.label,
!isLabelVisible && styles.isLabelHidden,
)}
id={id && `${id}__displayLabel`}
>
{label}
</div>
{isLabelVisible && (
<div
aria-hidden
className={styles.label}
id={id && `${id}__displayLabel`}
>
{label}
</div>
)}
<div className={styles.field}>
<div
className={styles.inputGroup}
Expand Down
5 changes: 0 additions & 5 deletions src/components/InputGroup/InputGroup.scss
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,6 @@
@include variants.validation(warning);
}

// Invisible label
.isLabelHidden {
@include accessibility.hide-text();
}

// Layouts
.isRootLayoutVertical,
.isRootLayoutHorizontal {
Expand Down
19 changes: 9 additions & 10 deletions src/components/Radio/Radio.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,15 @@ export const Radio = ({
>
{label}
</legend>
<div
aria-hidden
className={classNames(
styles.label,
!isLabelVisible && styles.isLabelHidden,
)}
id={id && `${id}__displayLabel`}
>
{label}
</div>
{isLabelVisible && (
<div
aria-hidden
className={styles.label}
id={id && `${id}__displayLabel`}
>
{label}
</div>
)}
<div className={styles.field}>
<div className={styles.options}>
{
Expand Down
5 changes: 0 additions & 5 deletions src/components/Radio/Radio.scss
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,6 @@
@include variants.validation(warning);
}

// Invisible label
.isLabelHidden {
@include accessibility.hide-text();
}

// Layouts
.isRootLayoutVertical,
.isRootLayoutHorizontal {
Expand Down
2 changes: 1 addition & 1 deletion tests/propTests/isLabelVisibleTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export const isLabelVisibleTest = (HtmlTag = 'label') => (
},
(rootElement) => {
if (HtmlTag === 'legend') {
expect(within(rootElement).getByTestId('id__displayLabel')).toHaveClass('isLabelHidden');
expect(within(rootElement).queryByTestId('id__displayLabel')).not.toBeInTheDocument();
} else {
expect(within(rootElement).getByText('label')).toHaveClass('isLabelHidden');
}
Expand Down

0 comments on commit 2e8b1ac

Please sign in to comment.