From 3a33e02083647ea20e85cf30717d533a068b59c1 Mon Sep 17 00:00:00 2001 From: Ryan Mathis Date: Tue, 3 Dec 2019 13:00:02 -0700 Subject: [PATCH] SHIBUI-1663 Fixed issue with announcing list items --- .../autocomplete/autocomplete.component.html | 25 +++++++++++++------ .../autocomplete/autocomplete.component.ts | 12 +++++++-- .../shared/autocomplete/autocomplete.model.ts | 6 ++--- 3 files changed, 30 insertions(+), 13 deletions(-) diff --git a/ui/src/app/shared/autocomplete/autocomplete.component.html b/ui/src/app/shared/autocomplete/autocomplete.component.html index 735b3bc48..558dcb454 100644 --- a/ui/src/app/shared/autocomplete/autocomplete.component.html +++ b/ui/src/app/shared/autocomplete/autocomplete.component.html @@ -6,32 +6,38 @@ [id]="fieldId" class="form-control" autocomplete="off" + autocorrect="off" + aria-autocomplete="list" role="combobox" type="text" [placeholder]="placeholder" [attr.aria-activedescendant]="activeDescendant" - aria-autocomplete="both" [attr.aria-owns]="fieldId + '__listbox'" [attr.aria-expanded]="(menuIsVisible$ | async) ? 'true' : 'false'" + [attr.aria-haspopup]="fieldId + '__listbox'" (focus)="handleInputFocus()" (blur)="handleInputBlur()" />
- +

+ diff --git a/ui/src/app/shared/autocomplete/autocomplete.component.ts b/ui/src/app/shared/autocomplete/autocomplete.component.ts index 28a4c0365..472db6dd5 100644 --- a/ui/src/app/shared/autocomplete/autocomplete.component.ts +++ b/ui/src/app/shared/autocomplete/autocomplete.component.ts @@ -153,6 +153,12 @@ export class AutoCompleteComponent implements OnInit, OnDestroy, OnChanges, Afte }); } + handleDropdown($event: MouseEvent | KeyboardEvent | Event): void { + const open = this.state.currentState.menuOpen; + this.state.setState({menuOpen: !open}); + this.handleOptionFocus(0); + } + handleViewMore($event: MouseEvent | KeyboardEvent | Event): void { $event.preventDefault(); $event.stopPropagation(); @@ -235,6 +241,8 @@ export class AutoCompleteComponent implements OnInit, OnDestroy, OnChanges, Afte focused: index, selected: index }); + + console.log(this.activeDescendant); } handleOptionClick(index: number): void { const selectedOption = this.matches[index]; @@ -278,7 +286,6 @@ export class AutoCompleteComponent implements OnInit, OnDestroy, OnChanges, Afte } handleDownArrow(event: KeyboardEvent): void { - event.preventDefault(); let isNotAtBottom = this.state.currentState.selected !== this.matches.length - 1; if (this.showMoreAvailable) { isNotAtBottom = this.state.currentState.selected !== this.matches.length; @@ -287,6 +294,7 @@ export class AutoCompleteComponent implements OnInit, OnDestroy, OnChanges, Afte if (allowMoveDown) { this.handleOptionFocus(this.state.currentState.selected + 1); } + event.preventDefault(); } handleSpace(event: KeyboardEvent): void { @@ -344,7 +352,7 @@ export class AutoCompleteComponent implements OnInit, OnDestroy, OnChanges, Afte } getOptionId(index): string { - return `${this.fieldId}__option--${index}`; + return `${this.fieldId}__option--${index}`.replace('/', ''); } get hasAutoselect(): boolean { diff --git a/ui/src/app/shared/autocomplete/autocomplete.model.ts b/ui/src/app/shared/autocomplete/autocomplete.model.ts index 8e96dae05..83c003d91 100644 --- a/ui/src/app/shared/autocomplete/autocomplete.model.ts +++ b/ui/src/app/shared/autocomplete/autocomplete.model.ts @@ -9,9 +9,9 @@ export const defaultState: AutoCompleteState = { }; export interface AutoCompleteState { - focused: number | null; - selected: number | null; - hovered: number | null; + focused: number; + selected: number; + hovered: number; menuOpen: boolean; }