Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/components/Chip/Chip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,8 @@ const Chip = ({
disabled = false,
background,
'aria-label': ariaLabel,
'aria-checked': ariaChecked,
accessibilityState,
role = 'button',
closeIconAccessibilityLabel = 'Close',
closeIconTestID,
Expand Down Expand Up @@ -378,6 +380,8 @@ const Chip = ({
delayLongPress={delayLongPress}
disabled={disabled}
aria-label={ariaLabel}
aria-checked={ariaChecked ?? accessibilityState?.checked}
accessibilityState={accessibilityState}
role={role}
aria-selected={selected}
aria-disabled={disabled}
Expand Down
26 changes: 26 additions & 0 deletions src/components/__tests__/Chip.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -434,4 +434,30 @@ describe('with reduce motion', () => {
expect(elevationTransitionDuration()).toBe(pressed);
}
);

it('forwards aria-checked and accessibilityState to the interactive node', async () => {
await render(
<Chip
selected
role="checkbox"
aria-checked={true}
accessibilityState={{ checked: true }}
testID="chip"
>
Checked Chip
</Chip>
);

expect(screen.getByRole('checkbox', { checked: true })).toBeOnTheScreen();
});

it('derives aria-checked from accessibilityState.checked when aria-checked is omitted', async () => {
await render(
<Chip role="radio" accessibilityState={{ checked: false }} testID="chip">
Unchecked Chip
</Chip>
);

expect(screen.getByRole('radio', { checked: false })).toBeOnTheScreen();
});
});
Loading