Skip to content

Commit ed826ba

Browse files
committed
feat(drop-down): add role input property
1 parent d0361ce commit ed826ba

File tree

4 files changed

+21
-1
lines changed

4 files changed

+21
-1
lines changed

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,17 @@ export abstract class IgxDropDownBaseDirective implements IDropDownList, OnInit
104104
@HostBinding('class.igx-drop-down')
105105
public cssClass = true;
106106

107+
/**
108+
* Gets/sets the `role` attribute of the drop down. Default is 'listbox'.
109+
*
110+
* ```html
111+
* <igx-drop-down [role]="customRole"></igx-drop-down-item>
112+
* ```
113+
*/
114+
@Input()
115+
@HostBinding('attr.role')
116+
public role = 'listbox';
117+
107118
/**
108119
* Get all non-header items
109120
*

projects/igniteui-angular/src/lib/drop-down/drop-down.common.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ export interface IDropDownList {
5252
height: string;
5353
id: string;
5454
maxHeight: string;
55+
role: string;
5556
collapsed: boolean;
5657
items: IgxDropDownItemBaseDirective[];
5758
headers: IgxDropDownItemBaseDirective[];

projects/igniteui-angular/src/lib/drop-down/drop-down.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
(appended)="onToggleContentAppended($event)"
44
(opening)="onToggleOpening($event)" (opened)="onToggleOpened()"
55
(closing)="onToggleClosing($event)" (closed)="onToggleClosed()">
6-
<div class="igx-drop-down__list-scroll" #scrollContainer [attr.id]="listId" role="listbox" [attr.aria-labelledby]="labelledBy"
6+
<div class="igx-drop-down__list-scroll" #scrollContainer [attr.id]="listId" [attr.role]="role" [attr.aria-labelledby]="labelledBy"
77
[style.height]="height"
88
[style.maxHeight]="maxHeight">
99
@if (!collapsed) {

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1185,6 +1185,14 @@ describe('IgxDropDown ', () => {
11851185
expect(parseInt(ddList.style.maxHeight, 10)).toBeGreaterThan(ddList.offsetHeight);
11861186
expect(ddList.style.maxHeight).toBe('700px');
11871187
});
1188+
it('should properly set role option', () => {
1189+
const ddList = fixture.debugElement.query(By.css(`.${CSS_CLASS_SCROLL}`)).nativeElement;
1190+
expect(ddList.getAttribute('role')).toBe('listbox');
1191+
dropdown.role = 'menu';
1192+
fixture.detectChanges();
1193+
expect(ddList.getAttribute('role')).toBe('menu');
1194+
1195+
});
11881196
it('should set custom id, width/height properties runtime', () => {
11891197
fixture.componentInstance.dropdown.width = '80%';
11901198
fixture.componentInstance.dropdown.height = '400px';

0 commit comments

Comments
 (0)