-
Notifications
You must be signed in to change notification settings - Fork 390
fix(Spinner): define default aria-label via destructuring #12420
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,11 +1,21 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { render } from '@testing-library/react'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { render, screen } from '@testing-library/react'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { Spinner } from '../Spinner'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| test('simple spinner', () => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| const { asFragment } = render(<Spinner />); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| expect(asFragment()).toMatchSnapshot(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| test('uses default aria-label of "Contents" when none is provided', () => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| render(<Spinner />); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| expect(screen.getByRole('progressbar')).toHaveAttribute('aria-label', 'Contents'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| test('uses a custom aria-label when one is provided', () => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| render(<Spinner aria-label="Loading users" />); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| expect(screen.getByRole('progressbar')).toHaveAttribute('aria-label', 'Loading users'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as above here |
||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+9
to
+17
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add regression coverage for These tests cover default and custom label values, but they don’t lock the third behavior this PR depends on: when only Suggested test addition test('uses a custom aria-label when one is provided', () => {
render(<Spinner aria-label="Loading users" />);
expect(screen.getByRole('progressbar')).toHaveAttribute('aria-label', 'Loading users');
});
+
+test('keeps default aria-label when aria-labelledby is provided', () => {
+ render(<Spinner aria-labelledby="external-label" />);
+ const spinner = screen.getByRole('progressbar');
+ expect(spinner).toHaveAttribute('aria-labelledby', 'external-label');
+ expect(spinner).toHaveAttribute('aria-label', 'Contents');
+});📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| test('small spinner', () => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| const { asFragment } = render(<Spinner size="sm" />); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| expect(asFragment()).toMatchSnapshot(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Small nit: we should use
toHaveAccessibleNameinstead here