-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Fix UrlInput combobox to use the ARIA 1.0 pattern. #47148
Changes from 2 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 | ||
---|---|---|---|---|
|
@@ -140,6 +140,17 @@ describe( 'Basic rendering', () => { | |||
expect( searchInput ).toBeInTheDocument(); | ||||
} ); | ||||
|
||||
it( 'should have aria-owns attribute to follow the ARIA 1.0 pattern', () => { | ||||
render( <LinkControl /> ); | ||||
|
||||
// Search Input UI. | ||||
const searchInput = screen.getByRole( 'combobox', { name: 'URL' } ); | ||||
|
||||
expect( searchInput ).toBeInTheDocument(); | ||||
expect( searchInput ).not.toHaveAttribute( 'aria-controls' ); | ||||
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. I don't see a good reason to have this assertion in place. I think we can remove it.
Suggested change
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. I'd like to make sure 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. I understand. thanks for clarifying. I guess it's worth adding some context as a comment to the test then 👍 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. My bad, I see now you mentioned the assertion for |
||||
expect( searchInput ).toHaveAttribute( 'aria-owns' ); | ||||
} ); | ||||
|
||||
it( 'should not render protocol in links', async () => { | ||||
const user = userEvent.setup(); | ||||
mockFetchSearchSuggestions.mockImplementation( () => | ||||
|
@@ -1375,6 +1386,15 @@ describe( 'Selecting links', () => { | |||
firstSearchSuggestion | ||||
); | ||||
|
||||
// Check aria-selected attribute is omitted on non-highlighted items. | ||||
expect( firstSearchSuggestion ).toHaveAttribute( | ||||
'aria-selected', | ||||
'true' | ||||
); | ||||
expect( secondSearchSuggestion ).not.toHaveAttribute( | ||||
'aria-selected' | ||||
); | ||||
|
||||
// Check we can go down again using the down arrow. | ||||
triggerArrowDown( searchInput ); | ||||
|
||||
|
@@ -1387,6 +1407,15 @@ describe( 'Selecting links', () => { | |||
secondSearchSuggestion | ||||
); | ||||
|
||||
// Check aria-selected attribute is omitted on non-highlighted items. | ||||
expect( firstSearchSuggestion ).not.toHaveAttribute( | ||||
'aria-selected' | ||||
); | ||||
expect( secondSearchSuggestion ).toHaveAttribute( | ||||
'aria-selected', | ||||
'true' | ||||
); | ||||
|
||||
// Check we can go back up via up arrow. | ||||
triggerArrowUp( searchInput ); | ||||
|
||||
|
@@ -1399,6 +1428,15 @@ describe( 'Selecting links', () => { | |||
firstSearchSuggestion | ||||
); | ||||
|
||||
// Check aria-selected attribute is omitted on non-highlighted items. | ||||
expect( firstSearchSuggestion ).toHaveAttribute( | ||||
'aria-selected', | ||||
'true' | ||||
); | ||||
expect( secondSearchSuggestion ).not.toHaveAttribute( | ||||
'aria-selected' | ||||
); | ||||
|
||||
expect( mockFetchSearchSuggestions ).toHaveBeenCalledTimes( 1 ); | ||||
} ); | ||||
} ); | ||||
|
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.
Does it make sense to change this assertion to use
toBeVisible()
? I've found this to be a bit more specific query, sincetoBeInTheDocument()
will be truthy if the element is not accessible to the user at all.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.
Makes sense. There are a few more occurrences of
toBeInTheDocument()
. Some of them usenot
and they actually test for some elements to not be in the DOM. I guess the other ones should be changed totoBeVisible()
.