Skip to content

Commit 2d2dc49

Browse files
committed
experiment: Make input clear button keyboard-accessible
1 parent 2deaa03 commit 2d2dc49

File tree

24 files changed

+119
-33
lines changed

24 files changed

+119
-33
lines changed

pages/autosuggest/permutations.page.tsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ const permutations = createPermutations<AutosuggestProps>([
2323
undefined,
2424
],
2525
enteredTextLabel: [enteredTextLabel],
26+
clearAriaLabel: ['Clear'],
2627
},
2728
{
2829
ariaLabel: ['some label'],
@@ -36,6 +37,7 @@ const permutations = createPermutations<AutosuggestProps>([
3637
</>,
3738
],
3839
enteredTextLabel: [enteredTextLabel],
40+
clearAriaLabel: ['Clear'],
3941
},
4042
{
4143
ariaLabel: ['some label'],
@@ -44,27 +46,31 @@ const permutations = createPermutations<AutosuggestProps>([
4446
value: ['', 'Some option'],
4547
placeholder: ['Enter some data'],
4648
enteredTextLabel: [enteredTextLabel],
49+
clearAriaLabel: ['Clear'],
4750
},
4851
{
4952
ariaLabel: ['some label'],
5053
readOnly: [true],
5154
value: ['', 'Some option'],
5255
placeholder: ['Enter some data'],
5356
enteredTextLabel: [enteredTextLabel],
57+
clearAriaLabel: ['Clear'],
5458
},
5559
{
5660
value: [''],
5761
ariaLabel: ['some label'],
5862
statusType: ['loading'],
5963
loadingText: ['Loading more items', undefined],
6064
enteredTextLabel: [enteredTextLabel],
65+
clearAriaLabel: ['Clear'],
6166
},
6267
{
6368
value: [''],
6469
ariaLabel: ['some label'],
6570
statusType: ['error'],
6671
errorText: ['Error while loading', undefined],
6772
enteredTextLabel: [enteredTextLabel],
73+
clearAriaLabel: ['Clear'],
6874
},
6975
{
7076
value: ['', 'op', 'Option 2', 'tag1', 'this is a label tag', 'thisisafilteringtag'],
@@ -119,16 +125,19 @@ const permutations = createPermutations<AutosuggestProps>([
119125
],
120126
],
121127
enteredTextLabel: [enteredTextLabel],
128+
clearAriaLabel: ['Clear'],
122129
},
123130
{
124131
value: [''],
125132
enteredTextLabel: [enteredTextLabel],
133+
clearAriaLabel: ['Clear'],
126134
options: [range(20).map(i => ({ value: `option${i}`, label: `Option ${i}` }))],
127135
virtualScroll: [true, false],
128136
},
129137
{
130138
value: ['some value'],
131139
enteredTextLabel: [enteredTextLabel],
140+
clearAriaLabel: ['Clear'],
132141
options: [[]],
133142
virtualScroll: [true, false],
134143
},

pages/input/permutations.page.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ const permutations = createPermutations<InputProps>([
1616
'Short value',
1717
'Long value, enough to extend beyond the input width. Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.',
1818
],
19+
clearAriaLabel: ['Clear'],
1920
},
2021
{
2122
value: [''],
@@ -25,24 +26,28 @@ const permutations = createPermutations<InputProps>([
2526
'Short placeholder',
2627
'Long placeholder, enough to extend beyond the input width. Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.',
2728
],
29+
clearAriaLabel: ['Clear'],
2830
},
2931
{
3032
disabled: [false, true],
3133
type: ['text', 'password', 'search', 'email', 'url'] as const,
3234
value: ['Non-empty value: Placeholder should be hidden'],
3335
placeholder: ['Short placeholder'],
36+
clearAriaLabel: ['Clear'],
3437
},
3538
{
3639
disabled: [false, true],
3740
type: ['number'] as const,
3841
value: ['-1', '1'],
3942
placeholder: ['Short placeholder'],
43+
clearAriaLabel: ['Clear'],
4044
},
4145
{
4246
readOnly: [true],
4347
type: ['text', 'password', 'search', 'number', 'email', 'url'] as const,
4448
value: ['100000000'],
4549
placeholder: ['Short placeholder'],
50+
clearAriaLabel: ['Clear'],
4651
},
4752
]);
4853

pages/property-filter/common-props.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ export const i18nStrings: PropertyFilterProps.I18nStrings = {
147147
cancelActionText: 'Cancel',
148148
applyActionText: 'Apply',
149149
allPropertiesLabel: 'All properties',
150+
clearAriaLabel: 'Clear',
150151

151152
tokenLimitShowMore: 'Show more',
152153
tokenLimitShowFewer: 'Show fewer',

pages/property-filter/property-filter-autosuggest.page.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ export default function PropertyFilterAutosuggestPage() {
2929
onChange={event => setValue(event.detail.value)}
3030
enteredTextLabel={enteredTextLabel}
3131
ariaLabel={'internal autosuggest'}
32+
clearAriaLabel="Clear"
3233
virtualScroll={true}
3334
/>
3435
</div>

pages/tag-editor/shared.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ export const I18N_STRINGS: TagEditorProps.I18nStrings = {
3232
invalidValueError:
3333
'Invalid value. Values can only contain alphanumeric characters, spaces and any of the following: _.:/=+@-',
3434
awsPrefixError: 'Cannot start with aws:',
35+
clearAriaLabel: 'Clear',
3536
tagLimit: (availableTags, tagLimit) =>
3637
availableTags === tagLimit
3738
? `You can up to ${tagLimit} tags.`

pages/text-filter/permutations.page.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ const permutations = createPermutations<TextFilterProps>([
1212
countText: [undefined, 'N matches'],
1313
filteringText: ['', 'query'],
1414
filteringPlaceholder: [undefined, 'Filter instances...'],
15+
clearAriaLabel: ['Clear'],
1516
},
1617
]);
1718

src/__tests__/__snapshots__/documenter.test.ts.snap

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1385,6 +1385,12 @@ scrolled out of the viewport.",
13851385
"optional": true,
13861386
"type": "string",
13871387
},
1388+
Object {
1389+
"description": "Adds an \`aria-label\` to the clear button inside the search input.",
1390+
"name": "clearAriaLabel",
1391+
"optional": true,
1392+
"type": "string",
1393+
},
13881394
Object {
13891395
"description": "Specifies the ID of the native form element. You can use it to relate
13901396
a label element's \`for\` attribute to this control.
@@ -4431,6 +4437,12 @@ scrolled out of the viewport.",
44314437
"optional": true,
44324438
"type": "string",
44334439
},
4440+
Object {
4441+
"description": "Adds an \`aria-label\` to the clear button inside the search input.",
4442+
"name": "clearAriaLabel",
4443+
"optional": true,
4444+
"type": "string",
4445+
},
44344446
Object {
44354447
"description": "Specifies the ID of the native form element. You can use it to relate
44364448
a label element's \`for\` attribute to this control.
@@ -6250,6 +6262,12 @@ scrolled out of the viewport.",
62506262
"optional": true,
62516263
"type": "string",
62526264
},
6265+
Object {
6266+
"description": "Adds an \`aria-label\` to the clear button inside the search input.",
6267+
"name": "clearAriaLabel",
6268+
"optional": true,
6269+
"type": "string",
6270+
},
62536271
Object {
62546272
"description": "Specifies the ID of the native form element. You can use it to relate
62556273
a label element's \`for\` attribute to this control.
@@ -8872,6 +8890,11 @@ operations are communicated to the user in another way.",
88728890
"optional": false,
88738891
"type": "string",
88748892
},
8893+
Object {
8894+
"name": "clearAriaLabel",
8895+
"optional": true,
8896+
"type": "string",
8897+
},
88758898
Object {
88768899
"name": "clearFiltersText",
88778900
"optional": false,
@@ -11310,6 +11333,11 @@ character validation. You should use this property only when absolutely necessar
1131011333
"optional": false,
1131111334
"type": "string",
1131211335
},
11336+
Object {
11337+
"name": "clearAriaLabel",
11338+
"optional": true,
11339+
"type": "string",
11340+
},
1131311341
Object {
1131411342
"name": "duplicateKeyError",
1131511343
"optional": false,
@@ -11610,6 +11638,12 @@ period of time. If you want a delayed handler to invoke a filtering API call, yo
1161011638
"optional": true,
1161111639
"type": "string",
1161211640
},
11641+
Object {
11642+
"description": "Label for the input clear button.",
11643+
"name": "clearAriaLabel",
11644+
"optional": true,
11645+
"type": "string",
11646+
},
1161311647
Object {
1161411648
"description": "Accepts a human-readable, localized string that indicates the number of results. For example, \\"1 match\\" or \\"165 matches.\\"
1161511649
If the total number of results is unknown, also include an indication that there may be more results than
@@ -11857,6 +11891,12 @@ scrolled out of the viewport.",
1185711891
"optional": true,
1185811892
"type": "string",
1185911893
},
11894+
Object {
11895+
"description": "Adds an \`aria-label\` to the clear button inside the search input.",
11896+
"name": "clearAriaLabel",
11897+
"optional": true,
11898+
"type": "string",
11899+
},
1186011900
Object {
1186111901
"description": "Specifies the ID of the native form element. You can use it to relate
1186211902
a label element's \`for\` attribute to this control.
@@ -12200,6 +12240,12 @@ scrolled out of the viewport.",
1220012240
"optional": true,
1220112241
"type": "string",
1220212242
},
12243+
Object {
12244+
"description": "Adds an \`aria-label\` to the clear button inside the search input.",
12245+
"name": "clearAriaLabel",
12246+
"optional": true,
12247+
"type": "string",
12248+
},
1220312249
Object {
1220412250
"description": "Specifies the ID of the native form element. You can use it to relate
1220512251
a label element's \`for\` attribute to this control.

src/autosuggest/__integ__/events-autosuggest.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ describe.each<boolean>([false, true])('Autosuggest events (expandToViewport=%s)'
6464
await page.keys(['o']);
6565
await page.clearEventList();
6666

67-
await page.keys(['Tab']);
67+
await page.keys(['Tab', 'Tab']);
6868
await page.assertEventsFired(['onBlur']);
6969
})
7070
);
@@ -76,7 +76,7 @@ describe.each<boolean>([false, true])('Autosuggest events (expandToViewport=%s)'
7676
await page.keys(['o', 'ArrowDown', 'ArrowDown', 'Enter']);
7777
await page.clearEventList();
7878

79-
await page.keys(['b', 'Tab']);
79+
await page.keys(['b', 'Tab', 'Tab']);
8080
await page.assertEventsFired(['onChange', 'onBlur']);
8181
})
8282
);

src/autosuggest/internal.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ const InternalAutosuggest = React.forwardRef((props: InternalAutosuggestProps, r
4343
statusType = 'finished',
4444
recoveryText,
4545
placeholder,
46+
clearAriaLabel,
4647
name,
4748
disabled,
4849
disableBrowserAutocorrect = false,
@@ -172,6 +173,7 @@ const InternalAutosuggest = React.forwardRef((props: InternalAutosuggestProps, r
172173
autoFocus={autoFocus}
173174
ariaLabel={ariaLabel}
174175
ariaRequired={ariaRequired}
176+
clearAriaLabel={clearAriaLabel}
175177
disableBrowserAutocorrect={disableBrowserAutocorrect}
176178
expandToViewport={expandToViewport}
177179
ariaControls={listId}

src/input/index.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ const Input = React.forwardRef(
3737
ariaDescribedby,
3838
invalid,
3939
controlId,
40+
clearAriaLabel,
4041
...rest
4142
}: InputProps,
4243
ref: Ref<InputProps.Ref>
@@ -88,6 +89,7 @@ const Input = React.forwardRef(
8889
ariaLabelledby,
8990
invalid,
9091
controlId,
92+
clearAriaLabel,
9193
}}
9294
className={clsx(styles.root, baseProps.className)}
9395
__inheritFormFieldProps={true}

0 commit comments

Comments
 (0)