@@ -12,6 +12,7 @@ import {
1212 ElementRef
1313} from "@angular/core" ;
1414
15+ import { I18n } from "../../i18n/i18n.module" ;
1516import { AbstractDropdownView } from "./../abstract-dropdown-view.class" ;
1617import { ListItem } from "./../list-item.interface" ;
1718import { watchFocusJump } from "./../dropdowntools" ;
@@ -49,12 +50,15 @@ import { ScrollableList } from "./../scrollable-list.directive";
4950 <ul
5051 #list
5152 role="listbox"
52- class="bx--list-box__menu">
53- <li tabindex="{{item.disabled? -1 : 0}}"
53+ class="bx--list-box__menu"
54+ [attr.aria-label]="dropdownListLabel">
55+ <li tabindex="-1"
5456 role="option"
55- *ngFor="let item of displayItems"
57+ *ngFor="let item of displayItems; let i = index "
5658 (click)="doClick($event, item)"
5759 (keydown)="doKeyDown($event, item)"
60+ (focus)="listElementList[i].classList.add('bx--list-box__menu-item--highlighted'); listElementList[i].tabIndex = 0"
61+ (blur)="listElementList[i].classList.remove('bx--list-box__menu-item--highlighted'); listElementList[i].tabIndex = -1"
5862 class="bx--list-box__menu-item"
5963 [ngClass]="{
6064 selected: item.selected,
@@ -88,6 +92,7 @@ import { ScrollableList } from "./../scrollable-list.directive";
8892 ]
8993} ) // conceptually this extends list-group, but we dont have to
9094export class DropdownList implements AbstractDropdownView , AfterViewInit , OnChanges , OnDestroy {
95+ @Input ( ) dropdownListLabel = this . i18n . get ( ) . DROPDOWN_LIST . LABEL ;
9196 /**
9297 * The list items belonging to the `DropdownList`.
9398 */
@@ -139,7 +144,7 @@ export class DropdownList implements AbstractDropdownView, AfterViewInit, OnChan
139144 /**
140145 * Creates an instance of `DropdownList`.
141146 */
142- constructor ( public elementRef : ElementRef ) { }
147+ constructor ( public elementRef : ElementRef , protected i18n : I18n ) { }
143148
144149 /**
145150 * Updates list when changes occur within the items belonging to the `DropdownList`.
@@ -353,24 +358,24 @@ export class DropdownList implements AbstractDropdownView, AfterViewInit, OnChan
353358 * Manages the keyboard accessiblity for navigation and selection within a `DropdownList`.
354359 */
355360 doKeyDown ( event : KeyboardEvent , item : ListItem ) {
356- if ( event . key && ( event . key === "Enter" || event . key === " " ) ) {
361+ // "Spacebar", "Down", and "Up" are IE specific values
362+ if ( event . key && event . key === "Enter" || event . key === " " || event . key === "Spacebar" ) {
357363 event . preventDefault ( ) ;
358- this . doClick ( event , item ) ;
359- } else if ( event . key === "ArrowDown" || event . key === "ArrowUp" ) {
364+ if ( event . key === "Enter" ) {
365+ this . doClick ( event , item ) ;
366+ }
367+ } else if ( event . key === "ArrowDown" || event . key === "ArrowUp" || event . key === "Down" || event . key === "Up" ) {
360368 event . preventDefault ( ) ;
361369 // this.checkScrollArrows();
362- if ( event . key === "ArrowDown" && this . hasNextElement ( ) ) {
370+ if ( event . key === "ArrowDown" || event . key === "Down" && this . hasNextElement ( ) ) {
363371 this . getNextElement ( ) . focus ( ) ;
364- } else if ( event . key === "ArrowUp" ) {
372+ } else if ( event . key === "ArrowUp" || event . key === "Up" ) {
365373 if ( this . hasPrevElement ( ) ) {
366374 this . getPrevElement ( ) . focus ( ) ;
367375 } else if ( this . getSelected ( ) ) {
368376 this . clearSelected . nativeElement . focus ( ) ;
369377 }
370378 }
371- if ( event . shiftKey ) {
372- ( event . target as HTMLElement ) . click ( ) ;
373- }
374379 }
375380 }
376381
0 commit comments