From a608f72cc70a089649781b34744bc8a8577a619d Mon Sep 17 00:00:00 2001 From: Stamen Stoychev Date: Tue, 22 Jul 2025 14:29:33 +0300 Subject: [PATCH] feat(dropdown): adding activedescendants to toggles for screen readers --- .../lib/drop-down/drop-down-navigation.directive.ts | 7 ++++++- .../src/lib/drop-down/drop-down.base.ts | 10 ++++++++++ src/app/drop-down/drop-down.sample.html | 1 + 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/projects/igniteui-angular/src/lib/drop-down/drop-down-navigation.directive.ts b/projects/igniteui-angular/src/lib/drop-down/drop-down-navigation.directive.ts index 133e239e3a7..fb9802328f8 100644 --- a/projects/igniteui-angular/src/lib/drop-down/drop-down-navigation.directive.ts +++ b/projects/igniteui-angular/src/lib/drop-down/drop-down-navigation.directive.ts @@ -1,4 +1,4 @@ -import { Directive, Optional, Self, Input, HostListener, Inject } from '@angular/core'; +import { Directive, Optional, Self, Input, HostListener, Inject, HostBinding } from '@angular/core'; import { IGX_DROPDOWN_BASE } from './drop-down.common'; import { IDropDownNavigationDirective } from './drop-down.common'; import { IgxDropDownBaseDirective } from './drop-down.base'; @@ -53,6 +53,11 @@ export class IgxDropDownItemNavigationDirective implements IDropDownNavigationDi this._target = target ? target : this.dropdown; } + @HostBinding('attr.aria-activedescendant') + public get activeDescendant(): string { + return this._target?.activeDescendant; + } + /** * Captures keydown events and calls the appropriate handlers on the target component */ diff --git a/projects/igniteui-angular/src/lib/drop-down/drop-down.base.ts b/projects/igniteui-angular/src/lib/drop-down/drop-down.base.ts index 4fe729f4dac..3d4d9308226 100644 --- a/projects/igniteui-angular/src/lib/drop-down/drop-down.base.ts +++ b/projects/igniteui-angular/src/lib/drop-down/drop-down.base.ts @@ -162,6 +162,16 @@ export abstract class IgxDropDownBaseDirective implements IDropDownList, OnInit return this.element; } + /** + * @hidden @internal + * Gets the id of the focused item during dropdown navigation. + * This is used to update the `aria-activedescendant` attribute of + * the IgxDropDownNavigationDirective host element. + */ + public get activeDescendant (): string { + return this.focusedItem ? this.focusedItem.id : null; + } + /** * @hidden * @internal diff --git a/src/app/drop-down/drop-down.sample.html b/src/app/drop-down/drop-down.sample.html index 255bd3bcac6..ab354fe3ff2 100644 --- a/src/app/drop-down/drop-down.sample.html +++ b/src/app/drop-down/drop-down.sample.html @@ -16,6 +16,7 @@ > @for(item of items; track item) {