Skip to content

Commit

Permalink
Fix HTML validation of the input field (#16)
Browse files Browse the repository at this point in the history
* Add handling of aria-expanded attribute on the input field.

role="combobox" requires aria-expanded to pass HTML validation.

* Set autocorrect only if the field supports it.

This ensures the result is valid HTML.
  • Loading branch information
EreMaijala authored Jun 6, 2024
1 parent 37da6a8 commit a0af4f0
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions autocomplete.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* https://github.com/vufind-org/autocomplete.js (v2.1.9) (2024-02-26) */
/* https://github.com/vufind-org/autocomplete.js (v2.1.10) (2024-06-06) */
function Autocomplete(_settings) {
const _DEFAULTS = {
delay: 250,
Expand Down Expand Up @@ -75,6 +75,9 @@ function Autocomplete(_settings) {

clearTimeout(debounceTimeout);
_currentIndex = -1;
if (lastInput) {
lastInput.setAttribute('aria-expanded', 'false');
}
lastInput = false;
lastCB = null;
}
Expand Down Expand Up @@ -197,6 +200,8 @@ function Autocomplete(_settings) {
_searchCallback(items, input);
_show(input);
_align(input);
// Set aria-expanded here so that the load indicator isn't marked expanded
input.setAttribute('aria-expanded', 'true');
});
}

Expand Down Expand Up @@ -295,12 +300,15 @@ function Autocomplete(_settings) {
list.setAttribute("role", "listbox");
input.setAttribute("role", "combobox");
input.setAttribute("aria-autocomplete", "both");
input.setAttribute('aria-expanded', 'false');
input.setAttribute("aria-controls", list.getAttribute("id"));
input.setAttribute("enterkeyhint", "search"); // phone keyboard hint
input.setAttribute("autocapitalize", "off"); // disable browser tinkering
input.setAttribute("autocomplete", "off"); // ^
input.setAttribute("autocorrect", "off"); // ^
input.setAttribute("spellcheck", "false"); // ^
if (typeof input.autocorrect !== 'undefined') {
input.setAttribute("autocorrect", "off"); // ^ only with Safari
}

// Activation / De-activation
if (input.getAttribute("autofocus") !== null) {
Expand Down

0 comments on commit a0af4f0

Please sign in to comment.