Skip to content

Commit 4df9f17

Browse files
Add role input property to the dropdown (#15912)
* feat(drop-down): add role input property * chore(*): move the role prop to the drop-down component * chore(*): update CHANGELOG --------- Co-authored-by: Stamen Stoychev <[email protected]>
1 parent 779edb5 commit 4df9f17

File tree

4 files changed

+23
-1
lines changed

4 files changed

+23
-1
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
All notable changes for each version of this project will be documented in this file.
44

5+
## 20.1.0
6+
### General
7+
- `IgxDropDown` now exposes a `role` input property, allowing users to customize the role attribute based on the use case. The default is `listbox`.
8+
59
## 20.0.6
610
### General
711
- `IgxSimpleCombo`

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
@@ -1260,6 +1260,14 @@ describe('IgxDropDown ', () => {
12601260
expect(parseInt(ddList.style.maxHeight, 10)).toBeGreaterThan(ddList.offsetHeight);
12611261
expect(ddList.style.maxHeight).toBe('700px');
12621262
});
1263+
it('should properly set role option', () => {
1264+
const ddList = fixture.debugElement.query(By.css(`.${CSS_CLASS_SCROLL}`)).nativeElement;
1265+
expect(ddList.getAttribute('role')).toBe('listbox');
1266+
dropdown.role = 'menu';
1267+
fixture.detectChanges();
1268+
expect(ddList.getAttribute('role')).toBe('menu');
1269+
1270+
});
12631271
it('should set custom id, width/height properties runtime', () => {
12641272
fixture.componentInstance.dropdown.width = '80%';
12651273
fixture.componentInstance.dropdown.height = '400px';

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,16 @@ export class IgxDropDownComponent extends IgxDropDownBaseDirective implements ID
134134
@Input()
135135
public labelledBy: string;
136136

137+
/**
138+
* Gets/sets the `role` attribute of the drop down. Default is 'listbox'.
139+
*
140+
* ```html
141+
* <igx-drop-down [role]="customRole"></igx-drop-down-item>
142+
* ```
143+
*/
144+
@Input()
145+
public role = 'listbox';
146+
137147
@ContentChild(IgxForOfToken)
138148
protected virtDir: IgxForOfToken<any>;
139149

0 commit comments

Comments
 (0)