Skip to content

Commit 081b0db

Browse files
Ivan KitanovIvan Kitanov
authored andcommitted
fix(dropdown): Preventing aria-label to defualt to id
1 parent 4979d5e commit 081b0db

File tree

2 files changed

+53
-3
lines changed

2 files changed

+53
-3
lines changed

projects/igniteui-angular/src/lib/drop-down/drop-down-item.base.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,11 @@ export class IgxDropDownItemBaseDirective implements DoCheck {
3434

3535
@HostBinding('attr.aria-label')
3636
@Input()
37-
public get ariaLabel(): string {
38-
return this._label ? this._label : this.value ? this.value : this.id;
37+
public get ariaLabel(): string | null{
38+
return this._label ? this._label : this.value ? this.value : null;
3939
}
4040

41-
public set ariaLabel(value: string) {
41+
public set ariaLabel(value: string | null) {
4242
this._label = value;
4343
}
4444

projects/igniteui-angular/src/lib/drop-down/drop-down.component.spec.ts

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1034,6 +1034,56 @@ describe('IgxDropDown ', () => {
10341034
});
10351035
});
10361036
describe('Rendering', () => {
1037+
describe('Accessibility', () => {
1038+
beforeEach(waitForAsync(() => {
1039+
TestBed.configureTestingModule({
1040+
imports: [
1041+
NoopAnimationsModule,
1042+
IgxDropDownTestComponent,
1043+
]
1044+
}).compileComponents();
1045+
}));
1046+
beforeEach(() => {
1047+
fixture = TestBed.createComponent(IgxDropDownTestComponent);
1048+
fixture.detectChanges();
1049+
dropdown = fixture.componentInstance.dropDown;
1050+
});
1051+
it('should set the aria-label property correctly', () => {
1052+
fixture = TestBed.createComponent(IgxDropDownTestComponent);
1053+
fixture.detectChanges();
1054+
dropdown = fixture.componentInstance.dropdown;
1055+
1056+
// Initially aria-label should be null
1057+
dropdown.toggle();
1058+
fixture.detectChanges();
1059+
let items = document.querySelectorAll(`.${CSS_CLASS_ITEM}`);
1060+
items.forEach(item => {
1061+
expect(item.getAttribute('aria-label')).toBeNull();
1062+
});
1063+
1064+
// Set value and check if aria-label reflects it
1065+
dropdown.toggle();
1066+
fixture.detectChanges();
1067+
dropdown.items.forEach((item, index) => item.value = `value ${index}`);
1068+
dropdown.toggle();
1069+
fixture.detectChanges();
1070+
items = document.querySelectorAll(`.${CSS_CLASS_ITEM}`);
1071+
items.forEach((item, index) => {
1072+
expect(item.getAttribute('aria-label')).toBe(`value ${index}`);
1073+
});
1074+
1075+
// Phase 3: Set explicit ariaLabel and verify it overrides value
1076+
dropdown.toggle();
1077+
fixture.detectChanges();
1078+
dropdown.items.forEach((item, index) => item.ariaLabel = `label ${index}`);
1079+
dropdown.toggle();
1080+
fixture.detectChanges();
1081+
items = document.querySelectorAll(`.${CSS_CLASS_ITEM}`);
1082+
items.forEach((item, index) => {
1083+
expect(item.getAttribute('aria-label')).toBe(`label ${index}`);
1084+
});
1085+
});
1086+
});
10371087
describe('Grouped items', () => {
10381088
beforeEach(waitForAsync(() => {
10391089
TestBed.configureTestingModule({

0 commit comments

Comments
 (0)