Skip to content

Commit

Permalink
fix(CheckBox): Hide SVGs from screen readers by adding `aria-hidden="…
Browse files Browse the repository at this point in the history
…true"` to the `span` element that wraps the SVGs. (#1513)

Co-authored-by: Nikita Orliak <[email protected]>
  • Loading branch information
nikitaorliak-cengage and Nikita Orliak authored Oct 25, 2024
1 parent 9a85ec1 commit a95d26c
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/a11y-checkbox-hide-svg-from-screen-readers.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'react-magma-dom': patch
---

fix(CheckBox): Hide SVGs from screen readers by adding `aria-hidden="true"` to the `span` element that wraps the SVGs.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,14 @@ describe('Checkbox', () => {
expect(checkbox).not.toHaveAttribute('autoFocus');
});

it('should render the checkbox with aria-hidden', () => {
const { container } = render(<Checkbox />);

const span = container.querySelector('span');

expect(span).toHaveAttribute('aria-hidden', 'true');
});

it('should render a checkbox that is checked on render with defaultChecked', () => {
const label = 'test label';
const { getByLabelText } = render(
Expand Down
1 change: 1 addition & 0 deletions packages/react-magma-dom/src/components/Checkbox/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@ export const Checkbox = React.forwardRef<HTMLInputElement, CheckboxProps>(
style={inputStyle}
textPosition={textPosition}
theme={theme}
aria-hidden="true"
>
{isChecked ? (
<CheckBoxIcon size={theme.iconSizes.medium} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,14 @@ describe('Indeterminate Checkbox', () => {
expect(getByLabelText('Hello')).toBeInTheDocument();
});

it('should render the indeterminate checkbox with aria-hidden', () => {
const { container } = render(<IndeterminateCheckbox />);

const span = container.querySelector('span');

expect(span).toHaveAttribute('aria-hidden', 'true');
});

it('should give the checkbox an indeterminate value', () => {
const label = 'test label';
const { getByLabelText } = render(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ export const IndeterminateCheckbox = React.forwardRef<
isInverse={isInverse}
style={inputStyle}
theme={theme}
aria-hidden="true"
>
{isIndeterminate ? (
<IndeterminateCheckBoxIcon
Expand Down

2 comments on commit a95d26c

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

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

@github-actions
Copy link
Contributor

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.