Skip to content

Commit 0215da5

Browse files
authored
fix: remove tabIndex={-1} from clear button to make it keyboard accessible (#168)
1 parent 5d1a32d commit 0215da5

5 files changed

Lines changed: 16 additions & 39 deletions

File tree

src/BaseInput.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,6 @@ const BaseInput = React.forwardRef<HolderRef, BaseInputProps>((props, ref) => {
8888
clearIcon = (
8989
<button
9090
type="button"
91-
tabIndex={-1}
9291
onClick={(event) => {
9392
handleReset?.(event);
9493
onClear?.();

tests/BaseInput.test.tsx

Lines changed: 16 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,6 @@ describe('BaseInput', () => {
5151
const onBlur = jest.fn();
5252
const onFocus = jest.fn();
5353

54-
const user = userEvent.setup();
55-
5654
const Demo: FC = () => {
5755
const [value, setValue] = useState<string>('');
5856

@@ -97,33 +95,27 @@ describe('BaseInput', () => {
9795
expect(inputEl!.value).toBe('');
9896
});
9997

100-
// it('By focus and Space', async () => {
101-
// const { container } = render(<Demo />);
102-
103-
// const inputEl = container.querySelector('input');
104-
// await user.click(inputEl!);
105-
106-
// await user.type(inputEl!, 'some text');
107-
// expect(inputEl!.value).toBe('some text');
98+
it.each(['[Space]', '[Enter]'])('By focus and %s', async (key) => {
99+
const user = userEvent.setup();
100+
const { container } = render(<Demo />);
108101

109-
// await user.tab();
110-
// await user.keyboard('[Space]');
111-
// expect(inputEl!.value).toBe('');
112-
// });
102+
const inputEl = container.querySelector('input');
103+
await user.click(inputEl!);
113104

114-
// it('By focus and Enter', async () => {
115-
// const { container } = render(<Demo />);
105+
await user.type(inputEl!, 'some text');
106+
expect(inputEl!.value).toBe('some text');
116107

117-
// const inputEl = container.querySelector('input');
118-
// await user.click(inputEl!);
108+
await user.tab();
119109

120-
// await user.type(inputEl!, 'some text');
121-
// expect(inputEl!.value).toBe('some text');
110+
const clearIcon = container.querySelector<HTMLButtonElement>(
111+
'.rc-input-clear-icon',
112+
)!;
113+
expect(document.activeElement).toBe(clearIcon);
114+
expect(clearIcon.tabIndex).toBe(0);
122115

123-
// await user.tab();
124-
// await user.keyboard('[Enter]');
125-
// expect(inputEl!.value).toBe('');
126-
// });
116+
await user.keyboard(key);
117+
expect(inputEl!.value).toBe('');
118+
});
127119
});
128120

129121
it('should display clearIcon correctly', () => {

tests/__snapshots__/TextArea.allowClear.test.tsx.snap

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ exports[`should support allowClear should not show icon if defaultValue is undef
1212
>
1313
<button
1414
class="rc-textarea-clear-icon rc-textarea-clear-icon-hidden"
15-
tabindex="-1"
1615
type="button"
1716
>
1817
@@ -33,7 +32,6 @@ exports[`should support allowClear should not show icon if defaultValue is undef
3332
>
3433
<button
3534
class="rc-textarea-clear-icon rc-textarea-clear-icon-hidden"
36-
tabindex="-1"
3735
type="button"
3836
>
3937
@@ -54,7 +52,6 @@ exports[`should support allowClear should not show icon if defaultValue is undef
5452
>
5553
<button
5654
class="rc-textarea-clear-icon rc-textarea-clear-icon-hidden"
57-
tabindex="-1"
5855
type="button"
5956
>
6057
@@ -75,7 +72,6 @@ exports[`should support allowClear should not show icon if value is undefined, n
7572
>
7673
<button
7774
class="rc-textarea-clear-icon rc-textarea-clear-icon-hidden"
78-
tabindex="-1"
7975
type="button"
8076
>
8177
@@ -96,7 +92,6 @@ exports[`should support allowClear should not show icon if value is undefined, n
9692
>
9793
<button
9894
class="rc-textarea-clear-icon rc-textarea-clear-icon-hidden"
99-
tabindex="-1"
10095
type="button"
10196
>
10297
@@ -117,7 +112,6 @@ exports[`should support allowClear should not show icon if value is undefined, n
117112
>
118113
<button
119114
class="rc-textarea-clear-icon rc-textarea-clear-icon-hidden"
120-
tabindex="-1"
121115
type="button"
122116
>
123117

tests/__snapshots__/TextArea.test.tsx.snap

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ exports[`TextArea classNames and styles should work 1`] = `
2020
<button
2121
class="rc-textarea-clear-icon rc-textarea-clear-icon-has-suffix custom-clear"
2222
style="color: orange;"
23-
tabindex="-1"
2423
type="button"
2524
>
2625

tests/__snapshots__/index.test.tsx.snap

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ exports[`Input allowClear classNames and styles should work 1`] = `
2525
<button
2626
class="rc-input-clear-icon rc-input-clear-icon-has-suffix custom-clear"
2727
style="color: orange;"
28-
tabindex="-1"
2928
type="button"
3029
>
3130
@@ -125,7 +124,6 @@ exports[`Input allowClear should change type when click 1`] = `
125124
>
126125
<button
127126
class="rc-input-clear-icon"
128-
tabindex="-1"
129127
type="button"
130128
>
131129
@@ -150,7 +148,6 @@ exports[`Input allowClear should change type when click 2`] = `
150148
>
151149
<button
152150
class="rc-input-clear-icon rc-input-clear-icon-hidden"
153-
tabindex="-1"
154151
type="button"
155152
>
156153
@@ -175,7 +172,6 @@ exports[`Input allowClear should not show icon if defaultValue is undefined or e
175172
>
176173
<button
177174
class="rc-input-clear-icon rc-input-clear-icon-hidden"
178-
tabindex="-1"
179175
type="button"
180176
>
181177
@@ -200,7 +196,6 @@ exports[`Input allowClear should not show icon if defaultValue is undefined or e
200196
>
201197
<button
202198
class="rc-input-clear-icon rc-input-clear-icon-hidden"
203-
tabindex="-1"
204199
type="button"
205200
>
206201
@@ -225,7 +220,6 @@ exports[`Input allowClear should not show icon if value is undefined or empty st
225220
>
226221
<button
227222
class="rc-input-clear-icon rc-input-clear-icon-hidden"
228-
tabindex="-1"
229223
type="button"
230224
>
231225
@@ -250,7 +244,6 @@ exports[`Input allowClear should not show icon if value is undefined or empty st
250244
>
251245
<button
252246
class="rc-input-clear-icon rc-input-clear-icon-hidden"
253-
tabindex="-1"
254247
type="button"
255248
>
256249

0 commit comments

Comments
 (0)