diff --git a/src/app/components/accordion/accordion.ts b/src/app/components/accordion/accordion.ts index 333a5de89aa..7b46b274d8e 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) { @@ -471,18 +464,12 @@ export class Accordion implements BlockableUI, AfterContentInit, OnDestroy { } } - isInput(event): boolean { - const { tagName } = event.target; - return tagName?.toLowerCase() === 'input'; - } - - isTextArea(event): boolean { - const { tagName } = event.target; - 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.focusedElementIsAccordionHeader()) { const nextHeaderAction = this.findNextHeaderAction(event.target.parentElement.parentElement.parentElement); nextHeaderAction ? this.changeFocusedTab(nextHeaderAction) : this.onTabHomeKey(event); @@ -491,7 +478,7 @@ export class Accordion implements BlockableUI, AfterContentInit, OnDestroy { } onTabArrowUpKey(event) { - if (!this.isInput(event) && !this.isTextArea(event)) { + if (this.focusedElementIsAccordionHeader()) { const prevHeaderAction = this.findPrevHeaderAction(event.target.parentElement.parentElement.parentElement); prevHeaderAction ? this.changeFocusedTab(prevHeaderAction) : this.onTabEndKey(event);