Skip to content

Commit a608f72

Browse files
committed
feat(dropdown): adding activedescendants to toggles for screen readers
1 parent 0cc5dc5 commit a608f72

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

projects/igniteui-angular/src/lib/drop-down/drop-down-navigation.directive.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Directive, Optional, Self, Input, HostListener, Inject } from '@angular/core';
1+
import { Directive, Optional, Self, Input, HostListener, Inject, HostBinding } from '@angular/core';
22
import { IGX_DROPDOWN_BASE } from './drop-down.common';
33
import { IDropDownNavigationDirective } from './drop-down.common';
44
import { IgxDropDownBaseDirective } from './drop-down.base';
@@ -53,6 +53,11 @@ export class IgxDropDownItemNavigationDirective implements IDropDownNavigationDi
5353
this._target = target ? target : this.dropdown;
5454
}
5555

56+
@HostBinding('attr.aria-activedescendant')
57+
public get activeDescendant(): string {
58+
return this._target?.activeDescendant;
59+
}
60+
5661
/**
5762
* Captures keydown events and calls the appropriate handlers on the target component
5863
*/

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,16 @@ export abstract class IgxDropDownBaseDirective implements IDropDownList, OnInit
162162
return this.element;
163163
}
164164

165+
/**
166+
* @hidden @internal
167+
* Gets the id of the focused item during dropdown navigation.
168+
* This is used to update the `aria-activedescendant` attribute of
169+
* the IgxDropDownNavigationDirective host element.
170+
*/
171+
public get activeDescendant (): string {
172+
return this.focusedItem ? this.focusedItem.id : null;
173+
}
174+
165175
/**
166176
* @hidden
167177
* @internal

src/app/drop-down/drop-down.sample.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
>
1717
@for(item of items; track item) {
1818
<igx-drop-down-item
19+
[ariaLabel]="item.field"
1920
[disabled]="item.disabled"
2021
[isHeader]="item.header"
2122
>

0 commit comments

Comments
 (0)