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
17 changes: 17 additions & 0 deletions packages/react/components/indicator/__tests__/indicator.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,21 @@ describe('Indicator', () => {
expect(dot).toBeInTheDocument();
});
});

describe('Accessibility', () => {
it('labels the badge with the default variant', () => {
render(<Indicator />);
expect(screen.getByRole('status')).toHaveAttribute(
'aria-label',
'accent indicator'
);
});

it('treats a null variant as accent', () => {
render(<Indicator variant={null} />);
const badge = screen.getByRole('status');
expect(badge).toHaveAttribute('aria-label', 'accent indicator');
expect(badge).toHaveClass(styles['indicator-variant-accent']);
});
});
});
6 changes: 4 additions & 2 deletions packages/react/components/indicator/indicator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ export const Indicator = ({
'aria-label': ariaLabel,
...props
}: IndicatorProps) => {
const accessibilityLabel = ariaLabel || label || `${variant} indicator`;
const resolvedVariant = variant ?? 'accent';
const accessibilityLabel =
ariaLabel || label || `${resolvedVariant} indicator`;

return (
<div
Expand All @@ -55,7 +57,7 @@ export const Indicator = ({
>
{children}
<div
className={indicator({ variant, className })}
className={indicator({ variant: resolvedVariant, className })}
role='status'
aria-label={accessibilityLabel}
data-slot='indicator-badge'
Expand Down
Loading