Skip to content

Commit 504b426

Browse files
authored
Merge pull request #554 from gselderslaghs/autocomplete-accessibility
accessibility(Autocomplete) implemented tab index and aria expanded
2 parents 4d736ee + c4292d9 commit 504b426

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

src/autocomplete.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,11 @@ const _defaults: AutocompleteOptions = {
8282
onSearch: (text: string, autocomplete: Autocomplete) => {
8383
const normSearch = text.toLocaleLowerCase();
8484
autocomplete.setMenuItems(
85-
autocomplete.options.data.filter(
86-
(option) =>
87-
option.id.toString().toLocaleLowerCase().includes(normSearch) ||
88-
option.text?.toLocaleLowerCase().includes(normSearch)
85+
86+
autocomplete.options.data.filter((option) =>
87+
option.id.toString().toLocaleLowerCase().includes(normSearch)
88+
|| option.text?.toLocaleLowerCase().includes(normSearch)
89+
8990
)
9091
);
9192
},
@@ -207,6 +208,7 @@ export class Autocomplete extends Component<AutocompleteOptions> {
207208
this.container.style.maxHeight = this.options.maxDropDownHeight;
208209
this.container.id = `autocomplete-options-${Utils.guid()}`;
209210
this.container.classList.add('autocomplete-content', 'dropdown-content');
211+
this.container.ariaExpanded = 'true';
210212
this.el.setAttribute('data-target', this.container.id);
211213

212214
this.menuItems.forEach((menuItem) => {
@@ -253,6 +255,7 @@ export class Autocomplete extends Component<AutocompleteOptions> {
253255
}
254256

255257
_removeDropdown() {
258+
this.container.ariaExpanded = 'false';
256259
this.container.parentNode.removeChild(this.container);
257260
}
258261

@@ -377,6 +380,7 @@ export class Autocomplete extends Component<AutocompleteOptions> {
377380
'style',
378381
'display:grid; grid-auto-flow: column; user-select: none; align-items: center;'
379382
);
383+
item.tabIndex = 0;
380384
// Checkbox
381385
if (this.options.isMultiSelect) {
382386
item.innerHTML = `

0 commit comments

Comments
 (0)