TarekRaafat / autoComplete.js

Simple autocomplete pure vanilla Javascript library.
https://tarekraafat.github.io/autoComplete.js
Apache License 2.0
3.93k stars 236 forks source link

Missing label for resultsList #289

Open binarious opened 2 years ago

binarious commented 2 years ago

axe throws the following error:

ARIA input fields must have an accessible name

The node:

<ul id="autoComplete_list_2" role="listbox" hidden=""></ul>
binarious commented 2 years ago

Workaround 1:

new autoComplete({
  resultsList: {
    element: (list, data) => list.setAttribute('aria-label', 'My Label');
  }
});

Still results in axe errors, because this only gets executed and added on focus.

Workaround/hack 2:

// after new autoComplete
const unlabelledListbox = document.querySelector('ul[role="listbox"]:not([aria-label])');
if (unlabelledListbox) {
  unlabelledListbox.setAttribute('aria-label', 'My Label');
}