Skip to content

Commit e248dd8

Browse files
feat: added role="switch" to Toggle component, per APG Switch Pattern
1 parent 073474d commit e248dd8

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
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: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ export const Toggle = React.forwardRef<HTMLInputElement, IToggleProps>(
2323

2424
let combinedProps = {
2525
$isCompact: fieldsetContext ? fieldsetContext.isCompact : isCompact,
26+
role: 'switch',
2627
ref,
2728
...other
2829
} as any;

0 commit comments

Comments
 (0)