Skip to content

Commit b800406

Browse files
authored
Merge pull request #8157 from IgniteUI/iganchev/select-aria-8079-10.1.x
Add aria-labelledby for listbox - 10.1.x
2 parents 9516784 + a572ead commit b800406

File tree

3 files changed

+15
-6
lines changed

3 files changed

+15
-6
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ All notable changes for each version of this project will be documented in this
2929
- Added a disabled style for time parts outside of the minimum and maximum range.
3030
- `igxDatePicker`
3131
- Added new property - `editorTabIndex`, that allows setting tabindex for the default editor.
32+
- `IgxSelect`
33+
- Added `aria-labelledby` property for the items list container(marked as `role="listbox"`). This will ensure the users of assistive technologies will also know what the list items container is used for, upon opening.
3234

3335
### New Theme
3436
Ignite UI for Angular now has a new theme based on our own design system.

projects/igniteui-angular/src/lib/select/select.component.html

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
[value]="this.selectionValue"
1313
role="combobox"
1414
aria-haspopup="listbox"
15-
[attr.aria-labelledby]="this.label ? this.label.id : ''"
15+
[attr.aria-labelledby]="this.label?.id"
1616
[attr.aria-expanded]="!this.collapsed"
1717
[attr.aria-owns]="this.listId"
1818
[attr.aria-activedescendant]="!this.collapsed ? this.focusedItem?.id : null"
@@ -40,7 +40,8 @@
4040
</div>
4141

4242
<!-- #7436 LMB scrolling closes items container - unselectable attribute is IE specific -->
43-
<div #scrollContainer class="igx-drop-down__list-scroll" unselectable="on" [style.maxHeight]="maxHeight" [attr.id]="this.listId" role="listbox">
43+
<div #scrollContainer class="igx-drop-down__list-scroll" unselectable="on" [style.maxHeight]="maxHeight"
44+
[attr.id]="this.listId" role="listbox" [attr.aria-labelledby]="this.label?.id">
4445
<ng-content select="igx-select-item, igx-select-item-group"></ng-content>
4546
</div>
4647

projects/igniteui-angular/src/lib/select/select.component.spec.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { IgxInputState } from './../directives/input/input.directive';
2-
import { Component, ViewChild, DebugElement, OnInit, ViewChildren, QueryList } from '@angular/core';
2+
import { Component, ViewChild, DebugElement, OnInit, ViewChildren, QueryList, ElementRef } from '@angular/core';
33
import { async, TestBed, tick, fakeAsync } from '@angular/core/testing';
44
import { FormsModule, FormGroup, FormBuilder, FormControl, Validators, ReactiveFormsModule, NgForm, NgControl } from '@angular/forms';
55
import { By } from '@angular/platform-browser';
@@ -380,8 +380,11 @@ describe('igxSelect', () => {
380380
const dropdownListElement = fixture.debugElement.query(By.css('.' + CSS_CLASS_DROPDOWN_LIST_SCROLL));
381381
const dropdownWrapper = fixture.debugElement.query(By.css('.' + CSS_CLASS_DROPDOWN_LIST));
382382
const toggleBtn = fixture.debugElement.query(By.css('.' + CSS_CLASS_TOGGLE_BUTTON));
383+
const labelID = fixture.componentInstance.label1.nativeElement.getAttribute('id');
383384
expect(inputElement.nativeElement.getAttribute('role')).toEqual('combobox');
384385
expect(inputElement.nativeElement.getAttribute('aria-haspopup')).toEqual('listbox');
386+
expect(inputElement.nativeElement.getAttribute('aria-labelledby')).toEqual(labelID);
387+
expect(dropdownListElement.nativeElement.getAttribute('aria-labelledby')).toEqual(labelID);
385388
expect(inputElement.nativeElement.getAttribute('aria-owns')).toEqual(select.listId);
386389
expect(inputElement.nativeElement.getAttribute('aria-expanded')).toEqual('false');
387390
expect(toggleBtn.nativeElement.getAttribute('aria-hidden')).toEqual('true');
@@ -2657,15 +2660,18 @@ describe('igxSelect ControlValueAccessor Unit', () => {
26572660
@Component({
26582661
template: `
26592662
<igx-select #select [width]="'300px'" [height]="'200px'" [placeholder]="'Choose a city'" [(ngModel)]="value">
2660-
<igx-select-item *ngFor="let item of items" [value]="item" [text]="item">
2661-
{{ item }} {{'©'}}
2662-
</igx-select-item>
2663+
<label igxLabel #simpleLabel>Select Simple Component</label>
2664+
<igx-select-item *ngFor="let item of items" [value]="item" [text]="item">
2665+
{{ item }} {{'©'}}
2666+
</igx-select-item>
26632667
</igx-select>
26642668
`
26652669
})
26662670
class IgxSelectSimpleComponent {
26672671
@ViewChild('select', { read: IgxSelectComponent, static: true })
26682672
public select: IgxSelectComponent;
2673+
@ViewChild('simpleLabel', { read: ElementRef, static: true })
2674+
public label1: ElementRef;
26692675
public items: string[] = [
26702676
'New York',
26712677
'Sofia',

0 commit comments

Comments
 (0)