@gitlab/ui 123.9.1 → 123.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/base/token_selector/token_container.js +1 -6
- package/dist/components/base/token_selector/token_selector.js +32 -6
- package/dist/components/base/token_selector/token_selector_dropdown.js +1 -1
- package/dist/index.css +1 -1
- package/dist/index.css.map +1 -1
- package/dist/utils/unique_id.js +18 -0
- package/package.json +1 -1
- package/src/components/base/filtered_search/filtered_search.scss +1 -1
- package/src/components/base/token_selector/token_container.vue +1 -11
- package/src/components/base/token_selector/token_selector.vue +38 -7
- package/src/components/base/token_selector/token_selector_dropdown.vue +7 -5
- package/src/utils/unique_id.js +17 -0
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Function uses browser native crypto to return a sixteen
|
|
3
|
+
* character base16 encoded string. It is often used to
|
|
4
|
+
* generate collision-resistant IDs for aria markup such
|
|
5
|
+
* as aria-activedescendant and aria-controls.
|
|
6
|
+
*
|
|
7
|
+
* @returns String
|
|
8
|
+
*/
|
|
9
|
+
const GlUniqueId = () => {
|
|
10
|
+
if (typeof window !== 'undefined' && window.crypto) {
|
|
11
|
+
const arr32 = new Uint32Array(2);
|
|
12
|
+
window.crypto.getRandomValues(arr32);
|
|
13
|
+
return Array.from(arr32, id => id.toString(16)).join('');
|
|
14
|
+
}
|
|
15
|
+
throw new Error('Cannot generate a unique ID');
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export { GlUniqueId };
|
package/package.json
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
@apply gl-pl-4;
|
|
9
9
|
@apply gl-pr-7;
|
|
10
10
|
@apply gl-border-none;
|
|
11
|
-
@apply gl-rounded-
|
|
11
|
+
@apply gl-rounded-control;
|
|
12
12
|
box-shadow: inset 0 0 0 $gl-border-size-1 var(--gl-control-border-color-default);
|
|
13
13
|
background-color: var(--gl-control-background-color-default);
|
|
14
14
|
|
|
@@ -13,11 +13,6 @@ export default {
|
|
|
13
13
|
validator: tokensValidator,
|
|
14
14
|
required: true,
|
|
15
15
|
},
|
|
16
|
-
state: {
|
|
17
|
-
type: Boolean,
|
|
18
|
-
required: false,
|
|
19
|
-
default: null,
|
|
20
|
-
},
|
|
21
16
|
registerFocusOnToken: {
|
|
22
17
|
type: Function,
|
|
23
18
|
required: true,
|
|
@@ -133,11 +128,6 @@ export default {
|
|
|
133
128
|
<div
|
|
134
129
|
ref="tokenContainer"
|
|
135
130
|
class="-gl-mx-1 -gl-my-1 gl-flex gl-w-auto gl-list-none gl-flex-wrap gl-items-center gl-p-0"
|
|
136
|
-
role="listbox"
|
|
137
|
-
aria-multiselectable="false"
|
|
138
|
-
aria-orientation="horizontal"
|
|
139
|
-
:aria-invalid="state === false && 'true'"
|
|
140
|
-
aria-label="token list"
|
|
141
131
|
@keydown.left="handleLeftArrow"
|
|
142
132
|
@keydown.right="handleRightArrow"
|
|
143
133
|
@keydown.home="handleHome"
|
|
@@ -152,7 +142,7 @@ export default {
|
|
|
152
142
|
:key="token.id"
|
|
153
143
|
:data-token-id="token.id"
|
|
154
144
|
class="gl-token-selector-token-container gl-px-1 gl-py-2 gl-outline-none"
|
|
155
|
-
|
|
145
|
+
data-testid="gl-token-selector-tokens"
|
|
156
146
|
tabindex="-1"
|
|
157
147
|
@focus="bindFocusEvent ? handleTokenFocus(index) : null"
|
|
158
148
|
>
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
<script>
|
|
2
|
-
import
|
|
2
|
+
import { GlUniqueId } from '../../../utils/unique_id';
|
|
3
3
|
import { tokensValidator } from './helpers';
|
|
4
4
|
import GlTokenContainer from './token_container.vue';
|
|
5
5
|
import GlTokenSelectorDropdown from './token_selector_dropdown.vue';
|
|
6
6
|
|
|
7
7
|
export default {
|
|
8
8
|
name: 'GlTokenSelector',
|
|
9
|
-
componentId: uniqueId('token-selector'),
|
|
10
9
|
components: {
|
|
11
10
|
GlTokenContainer,
|
|
12
11
|
GlTokenSelectorDropdown,
|
|
@@ -75,7 +74,7 @@ export default {
|
|
|
75
74
|
default: '',
|
|
76
75
|
},
|
|
77
76
|
/**
|
|
78
|
-
* The autocomplete attribute value for the underlying `input` element
|
|
77
|
+
* The HTML5 autocomplete attribute value for the underlying `input` element.
|
|
79
78
|
*/
|
|
80
79
|
autocomplete: {
|
|
81
80
|
type: String,
|
|
@@ -83,7 +82,21 @@ export default {
|
|
|
83
82
|
default: 'off',
|
|
84
83
|
},
|
|
85
84
|
/**
|
|
86
|
-
* The `aria-
|
|
85
|
+
* The `aria-label` attribute value for the underlying `input` element.
|
|
86
|
+
* Input must have an aria-label or aria-labelledby prop or it will be inaccessible.
|
|
87
|
+
*
|
|
88
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Reference/Attributes/aria-label
|
|
89
|
+
*/
|
|
90
|
+
ariaLabel: {
|
|
91
|
+
type: String,
|
|
92
|
+
required: false,
|
|
93
|
+
default: null,
|
|
94
|
+
},
|
|
95
|
+
/**
|
|
96
|
+
* The `aria-labelledby` attribute value for the underlying `input` element.
|
|
97
|
+
* String must match the unique ID on a text element to create an accessible label.
|
|
98
|
+
*
|
|
99
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Reference/Attributes/aria-labelledby
|
|
87
100
|
*/
|
|
88
101
|
ariaLabelledby: {
|
|
89
102
|
type: String,
|
|
@@ -237,6 +250,10 @@ export default {
|
|
|
237
250
|
}
|
|
238
251
|
},
|
|
239
252
|
},
|
|
253
|
+
created() {
|
|
254
|
+
// Each instance must have a unique ID for proper ARIA relationships
|
|
255
|
+
this.uniqueId = `token-selector-${GlUniqueId()}`;
|
|
256
|
+
},
|
|
240
257
|
methods: {
|
|
241
258
|
handleFocus(event) {
|
|
242
259
|
/**
|
|
@@ -382,6 +399,13 @@ export default {
|
|
|
382
399
|
this.$emit('input', []);
|
|
383
400
|
this.focusTextInput();
|
|
384
401
|
},
|
|
402
|
+
handleAriaInvalid() {
|
|
403
|
+
const { state } = this;
|
|
404
|
+
return state === false ? 'true' : null;
|
|
405
|
+
},
|
|
406
|
+
handleAriaActiveDescendent(value) {
|
|
407
|
+
return value ? `${this.uniqueId}-dropdown-item-${value.id}` : null;
|
|
408
|
+
},
|
|
385
409
|
},
|
|
386
410
|
};
|
|
387
411
|
</script>
|
|
@@ -428,10 +452,17 @@ export default {
|
|
|
428
452
|
type="text"
|
|
429
453
|
class="gl-token-selector-input gl-h-auto gl-w-4/10 gl-grow gl-border-none gl-bg-transparent gl-px-1 gl-font-regular gl-text-base gl-leading-normal gl-text-default gl-outline-none"
|
|
430
454
|
:value="inputText"
|
|
455
|
+
:aria-activedescendant="handleAriaActiveDescendent(focusedDropdownItem)"
|
|
431
456
|
:autocomplete="autocomplete"
|
|
457
|
+
:aria-controls="uniqueId"
|
|
458
|
+
:aria-expanded="dropdownIsOpen.toString()"
|
|
459
|
+
:aria-invalid="handleAriaInvalid()"
|
|
460
|
+
:aria-label="ariaLabelledby ? null : ariaLabel"
|
|
432
461
|
:aria-labelledby="ariaLabelledby"
|
|
433
462
|
:placeholder="placeholder"
|
|
434
463
|
:disabled="viewOnly"
|
|
464
|
+
aria-autocomplete="list"
|
|
465
|
+
role="combobox"
|
|
435
466
|
v-bind="textInputAttrs"
|
|
436
467
|
@input="inputText = $event.target.value"
|
|
437
468
|
@focus="handleFocus"
|
|
@@ -450,18 +481,18 @@ export default {
|
|
|
450
481
|
</gl-token-container>
|
|
451
482
|
</div>
|
|
452
483
|
<gl-token-selector-dropdown
|
|
453
|
-
v-model="focusedDropdownItem"
|
|
454
484
|
:menu-class="menuClass"
|
|
455
485
|
:show="dropdownIsOpen"
|
|
456
486
|
:loading="loading"
|
|
457
487
|
:dropdown-items="filteredDropdownItems"
|
|
458
|
-
:selected-tokens="selectedTokens"
|
|
459
488
|
:input-text="inputText"
|
|
460
489
|
:user-defined-token-can-be-added="userDefinedTokenCanBeAdded"
|
|
461
|
-
:component-id="
|
|
490
|
+
:component-id="uniqueId"
|
|
462
491
|
:register-dropdown-event-handlers="registerDropdownEventHandlers"
|
|
463
492
|
:register-reset-focused-dropdown-item="registerResetFocusedDropdownItem"
|
|
464
493
|
@dropdown-item-click="addToken"
|
|
494
|
+
@input="focusedDropdownItem = $event"
|
|
495
|
+
@aria-active-descendant="handleAriaActiveDescendent"
|
|
465
496
|
@show="openDropdown"
|
|
466
497
|
>
|
|
467
498
|
<template #loading-content
|
|
@@ -106,7 +106,6 @@ export default {
|
|
|
106
106
|
});
|
|
107
107
|
|
|
108
108
|
this.registerResetFocusedDropdownItem(this.resetFocusedDropdownItem);
|
|
109
|
-
|
|
110
109
|
this.$emit('input', this.focusedDropdownItem);
|
|
111
110
|
},
|
|
112
111
|
methods: {
|
|
@@ -199,13 +198,13 @@ export default {
|
|
|
199
198
|
<template>
|
|
200
199
|
<div class="dropdown b-dropdown gl-dropdown gl-relative" :class="{ show }">
|
|
201
200
|
<ul
|
|
201
|
+
:id="componentId"
|
|
202
202
|
ref="dropdownMenu"
|
|
203
|
-
role="
|
|
203
|
+
role="listbox"
|
|
204
204
|
class="dropdown-menu gl-absolute"
|
|
205
|
-
:aria-activedescendant="dropdownItemIdAttribute(focusedDropdownItem)"
|
|
206
205
|
:class="[{ show }, menuClass]"
|
|
207
206
|
>
|
|
208
|
-
<gl-dropdown-item v-if="loading" disabled>
|
|
207
|
+
<gl-dropdown-item v-if="loading" role="option" disabled>
|
|
209
208
|
<slot name="loading-content">Searching...</slot>
|
|
210
209
|
</gl-dropdown-item>
|
|
211
210
|
|
|
@@ -216,7 +215,9 @@ export default {
|
|
|
216
215
|
:key="dropdownItem.id"
|
|
217
216
|
:data-dropdown-item-id="dropdownItem.id"
|
|
218
217
|
:active="dropdownItemIsFocused(dropdownItem)"
|
|
218
|
+
:aria-selected="dropdownItemIsFocused(dropdownItem).toString()"
|
|
219
219
|
active-class="is-focused"
|
|
220
|
+
role="option"
|
|
220
221
|
tabindex="-1"
|
|
221
222
|
@click="handleDropdownItemClick(dropdownItem)"
|
|
222
223
|
>
|
|
@@ -234,6 +235,7 @@ export default {
|
|
|
234
235
|
:data-dropdown-item-id="userDefinedToken.id"
|
|
235
236
|
:active="dropdownItemIsFocused(userDefinedToken)"
|
|
236
237
|
active-class="is-focused"
|
|
238
|
+
role="option"
|
|
237
239
|
tabindex="-1"
|
|
238
240
|
@click="handleDropdownItemClick(userDefinedToken)"
|
|
239
241
|
>
|
|
@@ -247,7 +249,7 @@ export default {
|
|
|
247
249
|
</div>
|
|
248
250
|
</gl-dropdown-item>
|
|
249
251
|
|
|
250
|
-
<gl-dropdown-item v-else-if="!dropdownItems.length" disabled>
|
|
252
|
+
<gl-dropdown-item v-else-if="!dropdownItems.length" role="option" disabled>
|
|
251
253
|
<slot name="no-results-content">No matches found</slot>
|
|
252
254
|
</gl-dropdown-item>
|
|
253
255
|
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Function uses browser native crypto to return a sixteen
|
|
3
|
+
* character base16 encoded string. It is often used to
|
|
4
|
+
* generate collision-resistant IDs for aria markup such
|
|
5
|
+
* as aria-activedescendant and aria-controls.
|
|
6
|
+
*
|
|
7
|
+
* @returns String
|
|
8
|
+
*/
|
|
9
|
+
export const GlUniqueId = () => {
|
|
10
|
+
if (typeof window !== 'undefined' && window.crypto) {
|
|
11
|
+
const arr32 = new Uint32Array(2);
|
|
12
|
+
window.crypto.getRandomValues(arr32);
|
|
13
|
+
return Array.from(arr32, (id) => id.toString(16)).join('');
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
throw new Error('Cannot generate a unique ID');
|
|
17
|
+
};
|