Skip to content

Commit 31b9f29

Browse files
fix(SearchField): accessibility - do not exclude clear button from tab order (#5376)
* fix(SearchField): accessibility - do not exclude clear button from tab order * Create eighty-candles-complain.md --------- Co-authored-by: Tim Nguyen <54393192+timngyn@users.noreply.github.com>
1 parent 1783fe8 commit 31b9f29

File tree

3 files changed

+29
-2
lines changed

3 files changed

+29
-2
lines changed

Diff for: .changeset/eighty-candles-complain.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@aws-amplify/ui-react": patch
3+
---
4+
5+
fix:(SearchField) accessibility - do not exclude clear button from tab order

Diff for: packages/react/src/primitives/SearchField/SearchField.tsx

-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@ const SearchFieldPrimitive: Primitive<SearchFieldProps, 'input'> = (
7878
innerEndComponent={
7979
<FieldClearButton
8080
ariaLabel={clearButtonLabel}
81-
excludeFromTabOrder
8281
isVisible={!isDisabled && strHasLength(composedValue)}
8382
onClick={onClearHandler}
8483
size={size}

Diff for: packages/react/src/primitives/SearchField/__tests__/SearchField.test.tsx

+24-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
import * as React from 'react';
2-
import { act, fireEvent, render, screen } from '@testing-library/react';
2+
import {
3+
act,
4+
fireEvent,
5+
render,
6+
screen,
7+
waitFor,
8+
} from '@testing-library/react';
39
import userEvent from '@testing-library/user-event';
410

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

223+
it('should be focusable via keyboard', async () => {
224+
const user = userEvent.setup();
225+
render(<SearchField label={label} name="q" />);
226+
227+
const searchField = await screen.findByLabelText(label);
228+
229+
await user.type(searchField, searchQuery);
230+
231+
const clearButton = await screen.findByLabelText(clearButtonLabel);
232+
expect(clearButton).not.toHaveFocus();
233+
234+
await user.tab();
235+
await waitFor(() => {
236+
expect(clearButton).toHaveFocus();
237+
});
238+
});
239+
217240
it('should clear text and refocus controlled input when clicked', async () => {
218241
render(<ControlledSearchField />);
219242

0 commit comments

Comments
 (0)