Skip to content
Open
Show file tree
Hide file tree
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
6 changes: 6 additions & 0 deletions src/typeahead/testing/typeahead.directive.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,12 @@ describe('Directive: Typeahead', () => {
expect(() => directive.onBlur()).not.toThrow();
});
}));

it('should have appropriate aria attributes', () => {
expect(inputElement.getAttribute('role')).toEqual('combobox');
expect(inputElement.getAttribute('aria-expanded')).toEqual('false');
expect(inputElement.getAttribute('aria-autocomplete')).toEqual('list');
});
});

describe('onFocus', () => {
Expand Down
31 changes: 16 additions & 15 deletions src/typeahead/typeahead-container.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,13 +145,13 @@ export class TypeaheadContainerComponent implements OnDestroy {
if (this.typeaheadIsFirstItemActive && this._matches.length > 0) {
this.setActive(this._matches[0]);

if (this._active?.isHeader()) {
if (this.active?.isHeader()) {
this.nextActiveMatch();
}
}

if (this._active && !this.typeaheadIsFirstItemActive) {
const concurrency = this._matches.find(match => match.value === this._active?.value);
if (this.active && !this.typeaheadIsFirstItemActive) {
const concurrency = this._matches.find(match => match.value === this.active?.value);

if (concurrency) {
this.selectActive(concurrency);
Expand Down Expand Up @@ -200,34 +200,35 @@ export class TypeaheadContainerComponent implements OnDestroy {
}

selectActiveMatch(isActiveItemChanged?: boolean): void {
if (this._active && this.parent?.typeaheadSelectFirstItem) {
this.selectMatch(this._active);
if (this.active && this.parent?.typeaheadSelectFirstItem) {
this.selectMatch(this.active);
}

if (!this.parent?.typeaheadSelectFirstItem && isActiveItemChanged) {
this.selectMatch(this._active);
this.selectMatch(this.active);
}
}

activeChanged(): void {
if (!this._active) {
if (!this.active) {
this.activeChangeEvent.emit(void 0);
return;
}
const index = this.matches.indexOf(this._active);
const index = this.matches.indexOf(this.active);
this.activeChangeEvent.emit(`${this.popupId}-${index}`);
}

prevActiveMatch(): void {
if (!this._active) {
if (!this.active) {
return;
}

const index = this.matches.indexOf(this._active);
const index = this.matches.indexOf(this.active);
this.setActive(this.matches[
index - 1 < 0 ? this.matches.length - 1 : index - 1
]);

if (this._active.isHeader()) {
if (this.active.isHeader()) {
this.prevActiveMatch();
}

Expand All @@ -237,12 +238,12 @@ export class TypeaheadContainerComponent implements OnDestroy {
}

nextActiveMatch(): void {
const index = this._active ? this.matches.indexOf(this._active) : -1;
const index = this.active ? this.matches.indexOf(this.active) : -1;
this.setActive(this.matches[
index + 1 > this.matches.length - 1 ? 0 : index + 1
]);

if (this._active?.isHeader()) {
if (this.active?.isHeader()) {
this.nextActiveMatch();
}

Expand Down Expand Up @@ -377,9 +378,9 @@ export class TypeaheadContainerComponent implements OnDestroy {
}

protected setActive(value?: TypeaheadMatch): void {
this._active = value;
this.active = value;
let preview;
if (!(this._active == null || this._active.isHeader())) {
if (!(this.active == null || this.active.isHeader())) {
preview = value;
}
this.parent?.typeaheadOnPreview.emit(preview);
Expand Down
6 changes: 4 additions & 2 deletions src/typeahead/typeahead.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,10 @@ type TypeaheadOptionArr = TypeaheadOption[] | Observable<TypeaheadOption>;
exportAs: 'bs-typeahead',
host: {
'[attr.aria-activedescendant]': 'activeDescendant',
'[attr.aria-owns]': 'isOpen ? this._container?.popupId : null',
'[attr.aria-controls]': 'isOpen ? this._container?.popupId : null',
'[attr.aria-expanded]': 'isOpen',
'[attr.aria-autocomplete]': 'list'
'[attr.aria-autocomplete]': 'list',
'[attr.role]': `'combobox'`
},
standalone: true,
providers: [ComponentLoaderFactory, PositioningService]
Expand Down Expand Up @@ -430,6 +431,7 @@ export class TypeaheadDirective implements OnInit, OnDestroy {
this._outsideClickListener();
this._container = void 0;
this.isOpen = false;
this.activeDescendant = void 0;
this.changeDetection.markForCheck();
}
this.typeaheadOnPreview.emit();
Expand Down