From 9ee4c47818ec07fbdaaf9b6a5a139a655a950c09 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Tue, 7 May 2024 14:34:23 +0530 Subject: [PATCH] fix(a11y): treeview incorrect levels (backport to 16.x) (#1385) Backport 9c67c41e979a1ea6e058ee1599d873a7b5fa305f from #1383.
## PR Checklist Please check if your PR fulfills the following requirements: - [ ] Tests for the changes have been added (for bug fixes / features) - [ ] Docs have been added / updated (for bug fixes / features) - [ ] If applicable, have a visual design approval ## PR Type What kind of change does this PR introduce? <!-- Please check the one that applies to this PR using "x". --> - [x] Bugfix - [ ] Feature - [ ] Code style update (formatting, local variables) - [ ] Refactoring (no functional changes, no api changes) - [ ] Build related changes - [ ] CI related changes - [ ] Documentation content changes - [ ] Other... Please describe: ## What is the current behavior? <!-- Please describe the current behavior that you are modifying, or link to a relevant issue. --> The screen reader is reading out incorrect levels in case of a recursive tree view component. Issue Number: CDE-1697 ## What is the new behavior? The screen reader will read out correct levels for the recursive tree view ## Does this PR introduce a breaking change? - [ ] Yes - [x] No <!-- If this PR contains a breaking change, please describe the impact and migration path for existing applications below. --> ## Other information Co-authored-by: Andrea A Fernandes --- .../angular/src/data/tree-view/recursive-children.ts | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/projects/angular/src/data/tree-view/recursive-children.ts b/projects/angular/src/data/tree-view/recursive-children.ts index 2a4a52567a..e827c412db 100644 --- a/projects/angular/src/data/tree-view/recursive-children.ts +++ b/projects/angular/src/data/tree-view/recursive-children.ts @@ -23,7 +23,7 @@ import { TreeFeaturesService } from './tree-features.service'; `, host: { - '[attr.role]': '"group"', // Safari + VO needs direct relationship between treeitem and group; no element should exist between them + '[attr.role]': 'role', // Safari + VO needs direct relationship between treeitem and group; no element should exist between them }, }) /** @@ -37,6 +37,7 @@ export class RecursiveChildren { @Input('children') children: TreeNodeModel[]; subscription: Subscription; + role: string; constructor(public featuresService: TreeFeaturesService, @Optional() private expandService: IfExpandService) { if (expandService) { @@ -51,6 +52,10 @@ export class RecursiveChildren { } } + ngAfterContentInit() { + this.setAriaRoles(); + } + shouldRender() { return ( this.featuresService.recursion && @@ -73,4 +78,8 @@ export class RecursiveChildren { this.subscription.unsubscribe(); } } + + private setAriaRoles() { + this.role = this.parent ? 'group' : null; + } }