Skip to content

Commit

Permalink
fix(SearchField): accessibility - do not exclude clear button from ta…
Browse files Browse the repository at this point in the history
…b order (#5376)

* fix(SearchField): accessibility - do not exclude clear button from tab order

* Create eighty-candles-complain.md

---------

Co-authored-by: Tim Nguyen <[email protected]>
  • Loading branch information
awinberg-aws and timngyn authored Jul 10, 2024
1 parent 1783fe8 commit 31b9f29
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/eighty-candles-complain.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@aws-amplify/ui-react": patch
---

fix:(SearchField) accessibility - do not exclude clear button from tab order
1 change: 0 additions & 1 deletion packages/react/src/primitives/SearchField/SearchField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ const SearchFieldPrimitive: Primitive<SearchFieldProps, 'input'> = (
innerEndComponent={
<FieldClearButton
ariaLabel={clearButtonLabel}
excludeFromTabOrder
isVisible={!isDisabled && strHasLength(composedValue)}
onClick={onClearHandler}
size={size}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import * as React from 'react';
import { act, fireEvent, render, screen } from '@testing-library/react';
import {
act,
fireEvent,
render,
screen,
waitFor,
} from '@testing-library/react';
import userEvent from '@testing-library/user-event';

import { ComponentClassName } from '@aws-amplify/ui';
Expand Down Expand Up @@ -214,6 +220,23 @@ describe('SearchField component', () => {
expect(searchField).toHaveFocus();
});

it('should be focusable via keyboard', async () => {
const user = userEvent.setup();
render(<SearchField label={label} name="q" />);

const searchField = await screen.findByLabelText(label);

await user.type(searchField, searchQuery);

const clearButton = await screen.findByLabelText(clearButtonLabel);
expect(clearButton).not.toHaveFocus();

await user.tab();
await waitFor(() => {
expect(clearButton).toHaveFocus();
});
});

it('should clear text and refocus controlled input when clicked', async () => {
render(<ControlledSearchField />);

Expand Down

0 comments on commit 31b9f29

Please sign in to comment.