Skip to content

Add role input property to the dropdown #15912

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

Open
wants to merge 2 commits into
base: 20.0.x
Choose a base branch
from
Open
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 @@ -3,7 +3,7 @@
(appended)="onToggleContentAppended($event)"
(opening)="onToggleOpening($event)" (opened)="onToggleOpened()"
(closing)="onToggleClosing($event)" (closed)="onToggleClosed()">
<div class="igx-drop-down__list-scroll" #scrollContainer [attr.id]="listId" role="listbox" [attr.aria-labelledby]="labelledBy"
<div class="igx-drop-down__list-scroll" #scrollContainer [attr.id]="listId" [attr.role]="role" [attr.aria-labelledby]="labelledBy"
[style.height]="height"
[style.maxHeight]="maxHeight">
@if (!collapsed) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1185,6 +1185,14 @@ describe('IgxDropDown ', () => {
expect(parseInt(ddList.style.maxHeight, 10)).toBeGreaterThan(ddList.offsetHeight);
expect(ddList.style.maxHeight).toBe('700px');
});
it('should properly set role option', () => {
const ddList = fixture.debugElement.query(By.css(`.${CSS_CLASS_SCROLL}`)).nativeElement;
expect(ddList.getAttribute('role')).toBe('listbox');
dropdown.role = 'menu';
fixture.detectChanges();
expect(ddList.getAttribute('role')).toBe('menu');

});
it('should set custom id, width/height properties runtime', () => {
fixture.componentInstance.dropdown.width = '80%';
fixture.componentInstance.dropdown.height = '400px';
Expand Down
10 changes: 10 additions & 0 deletions projects/igniteui-angular/src/lib/drop-down/drop-down.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,16 @@ export class IgxDropDownComponent extends IgxDropDownBaseDirective implements ID
@Input()
public labelledBy: string;

/**
* Gets/sets the `role` attribute of the drop down. Default is 'listbox'.
*
* ```html
* <igx-drop-down [role]="customRole"></igx-drop-down-item>
* ```
*/
@Input()
public role = 'listbox';

@ContentChild(IgxForOfToken)
protected virtDir: IgxForOfToken<any>;

Expand Down
Loading