Skip to content

Preventing aria-label to defualt to id - 18.2.x #15881

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ export class IgxDropDownItemBaseDirective implements DoCheck {

@HostBinding('attr.aria-label')
@Input()
public get ariaLabel(): string {
return this._label ? this._label : this.value ? this.value : this.id;
public get ariaLabel(): string | null{
return this._label ? this._label : this.value ? this.value : null;
}

public set ariaLabel(value: string) {
public set ariaLabel(value: string | null) {
this._label = value;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1039,6 +1039,56 @@ describe('IgxDropDown ', () => {
});
});
describe('Rendering', () => {
describe('Accessibility', () => {
beforeEach(waitForAsync(() => {
TestBed.configureTestingModule({
imports: [
NoopAnimationsModule,
IgxDropDownTestComponent,
]
}).compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(IgxDropDownTestComponent);
fixture.detectChanges();
dropdown = fixture.componentInstance.dropDown;
});
it('should set the aria-label property correctly', () => {
fixture = TestBed.createComponent(IgxDropDownTestComponent);
fixture.detectChanges();
dropdown = fixture.componentInstance.dropdown;

// Initially aria-label should be null
dropdown.toggle();
fixture.detectChanges();
let items = document.querySelectorAll(`.${CSS_CLASS_ITEM}`);
items.forEach(item => {
expect(item.getAttribute('aria-label')).toBeNull();
});

// Set value and check if aria-label reflects it
dropdown.toggle();
fixture.detectChanges();
dropdown.items.forEach((item, index) => item.value = `value ${index}`);
dropdown.toggle();
fixture.detectChanges();
items = document.querySelectorAll(`.${CSS_CLASS_ITEM}`);
items.forEach((item, index) => {
expect(item.getAttribute('aria-label')).toBe(`value ${index}`);
});

// Phase 3: Set explicit ariaLabel and verify it overrides value
dropdown.toggle();
fixture.detectChanges();
dropdown.items.forEach((item, index) => item.ariaLabel = `label ${index}`);
dropdown.toggle();
fixture.detectChanges();
items = document.querySelectorAll(`.${CSS_CLASS_ITEM}`);
items.forEach((item, index) => {
expect(item.getAttribute('aria-label')).toBe(`label ${index}`);
});
});
});
describe('Grouped items', () => {
configureTestSuite();
beforeAll(waitForAsync(() => {
Expand Down