Skip to content

Commit 8300d15

Browse files
fix(forms): Added role="switch" to Toggle component, per APG Switch Pattern (#2043)
1 parent 073474d commit 8300d15

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

packages/forms/src/elements/Toggle.spec.tsx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,16 @@ describe('Toggle', () => {
2323
expect(toggle).toHaveAttribute('type', 'checkbox');
2424
});
2525

26+
it('is rendered with the switch role', () => {
27+
const { queryByRole } = render(
28+
<Field>
29+
<Toggle data-test-id="toggle" />
30+
</Field>
31+
);
32+
33+
expect(queryByRole('switch')).toBeInTheDocument();
34+
});
35+
2636
it('passes ref to underlying DOM element', () => {
2737
const ref = React.createRef<HTMLInputElement>();
2838
const { getByTestId } = render(

packages/forms/src/elements/Toggle.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ export const Toggle = React.forwardRef<HTMLInputElement, IToggleProps>(
2424
let combinedProps = {
2525
$isCompact: fieldsetContext ? fieldsetContext.isCompact : isCompact,
2626
ref,
27-
...other
27+
...other,
28+
role: 'switch'
2829
} as any;
2930

3031
if (fieldContext) {

0 commit comments

Comments
 (0)