From 2c0402061be6412792e1bb2c70089525f5387d5b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mehmet=20=C3=87etin?= <92744169+mehmetcetin01140@users.noreply.github.com> Date: Wed, 12 Jun 2024 14:02:33 +0300 Subject: [PATCH] Fixed #15830 - Accessibility: Tree inside an Accordion (arrow navigation) --- src/app/components/accordion/accordion.ts | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/src/app/components/accordion/accordion.ts b/src/app/components/accordion/accordion.ts index 333a5de89aa..238e2ab0b61 100755 --- a/src/app/components/accordion/accordion.ts +++ b/src/app/components/accordion/accordion.ts @@ -230,11 +230,7 @@ export class AccordionTab implements AfterContentInit, OnDestroy { accordion: Accordion; - constructor( - @Inject(forwardRef(() => Accordion)) accordion: Accordion, - public el: ElementRef, - public changeDetector: ChangeDetectorRef - ) { + constructor(@Inject(forwardRef(() => Accordion)) accordion: Accordion, public el: ElementRef, public changeDetector: ChangeDetectorRef) { this.accordion = accordion as Accordion; this.id = UniqueComponentId(); } @@ -441,10 +437,7 @@ export class Accordion implements BlockableUI, AfterContentInit, OnDestroy { public tabs: AccordionTab[] = []; - constructor( - public el: ElementRef, - public changeDetector: ChangeDetectorRef - ) {} + constructor(public el: ElementRef, public changeDetector: ChangeDetectorRef) {} @HostListener('keydown', ['$event']) onKeydown(event) { @@ -481,8 +474,12 @@ export class Accordion implements BlockableUI, AfterContentInit, OnDestroy { return tagName?.toLowerCase() === 'textarea'; } + focusedElementIsAccordionHeader() { + return document.activeElement.tagName.toLowerCase() === 'a' && document.activeElement.classList.contains('p-accordion-header-link'); + } + onTabArrowDownKey(event) { - if (!this.isInput(event) && !this.isTextArea(event)) { + if (!this.isInput(event) && !this.isTextArea(event) && this.focusedElementIsAccordionHeader()) { const nextHeaderAction = this.findNextHeaderAction(event.target.parentElement.parentElement.parentElement); nextHeaderAction ? this.changeFocusedTab(nextHeaderAction) : this.onTabHomeKey(event); @@ -491,7 +488,7 @@ export class Accordion implements BlockableUI, AfterContentInit, OnDestroy { } onTabArrowUpKey(event) { - if (!this.isInput(event) && !this.isTextArea(event)) { + if (!this.isInput(event) && !this.isTextArea(event) && this.focusedElementIsAccordionHeader()) { const prevHeaderAction = this.findPrevHeaderAction(event.target.parentElement.parentElement.parentElement); prevHeaderAction ? this.changeFocusedTab(prevHeaderAction) : this.onTabEndKey(event);