From 7632ab81dd01444687d40b2663e093c6e13b4db6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mehmet=20=C3=87etin?= <92744169+mehmetcetin01140@users.noreply.github.com> Date: Mon, 24 Jun 2024 13:10:22 +0300 Subject: [PATCH] Fixed #15889 - Accessibility: Buttons within a Tree component can't be activated via Keyboard --- src/app/components/tree/tree.ts | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/app/components/tree/tree.ts b/src/app/components/tree/tree.ts index 7ab4a17a4ca..3a83472ca33 100755 --- a/src/app/components/tree/tree.ts +++ b/src/app/components/tree/tree.ts @@ -635,10 +635,19 @@ export class UITreeNode implements OnInit { event.preventDefault(); } + isActionableElement(event) { + const target = event.target; + + const isActionable = target instanceof HTMLElement && (target.nodeName == 'A' || target.nodeName == 'BUTTON'); + + return isActionable; + } + onEnter(event: KeyboardEvent) { this.tree.onNodeClick(event, this.node); this.setTabIndexForSelectionMode(event, this.tree.nodeTouched); - if (!(event.target instanceof HTMLElement && event.target.nodeName === 'A')) { + + if (!this.isActionableElement(event)) { event.preventDefault(); } } @@ -1157,12 +1166,7 @@ export class Tree implements OnInit, AfterContentInit, OnChanges, OnDestroy, Blo public dragStopSubscription: Subscription | undefined | null; - constructor( - public el: ElementRef, - @Optional() public dragDropService: TreeDragDropService, - public config: PrimeNGConfig, - private cd: ChangeDetectorRef - ) {} + constructor(public el: ElementRef, @Optional() public dragDropService: TreeDragDropService, public config: PrimeNGConfig, private cd: ChangeDetectorRef) {} ngOnInit() { if (this.droppableNodes) {