Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

accessibility(Autocomplete) implemented tab index and aria expanded #554

Draft
wants to merge 1 commit into
base: v2-dev
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions src/autocomplete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Dropdown, DropdownOptions } from "./dropdown";
import { Component, BaseOptions, InitElements, MElement } from "./component";

export interface AutocompleteData {
/**
/**
* A primitive value that can be converted to string.
* If "text" is not provided, it will also be used as "option text" as well
*/
Expand Down Expand Up @@ -82,7 +82,7 @@ let _defaults: AutocompleteOptions = {
onSearch: (text: string, autocomplete: Autocomplete) => {
const normSearch = text.toLocaleLowerCase();
autocomplete.setMenuItems(
autocomplete.options.data.filter((option) =>
autocomplete.options.data.filter((option) =>
option.id.toString().toLocaleLowerCase().includes(normSearch)
|| option.text?.toLocaleLowerCase().includes(normSearch)
)
Expand Down Expand Up @@ -118,7 +118,7 @@ export class Autocomplete extends Component<AutocompleteOptions> {
...Autocomplete.defaults,
...options
};

this.isOpen = false;
this.count = 0;
this.activeIndex = -1;
Expand Down Expand Up @@ -215,6 +215,7 @@ export class Autocomplete extends Component<AutocompleteOptions> {
this.container.style.maxHeight = this.options.maxDropDownHeight;
this.container.id = `autocomplete-options-${Utils.guid()}`;
this.container.classList.add('autocomplete-content', 'dropdown-content');
this.container.ariaExpanded = 'true';
this.el.setAttribute('data-target', this.container.id);

this.menuItems.forEach(menuItem => {
Expand Down Expand Up @@ -260,6 +261,7 @@ export class Autocomplete extends Component<AutocompleteOptions> {
}

_removeDropdown() {
this.container.ariaExpanded = 'false';
this.container.parentNode.removeChild(this.container);
}

Expand Down Expand Up @@ -368,6 +370,7 @@ export class Autocomplete extends Component<AutocompleteOptions> {
'style',
'display:grid; grid-auto-flow: column; user-select: none; align-items: center;'
);
item.tabIndex = 0;
// Checkbox
if (this.options.isMultiSelect) {
item.innerHTML = `
Expand Down
Loading