From b9d15505aafb82cfc6aba60f99a06945baeb3564 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mehmet=20=C3=87etin?= <92744169+mehmetcetin01140@users.noreply.github.com> Date: Fri, 21 Jun 2024 10:56:06 +0300 Subject: [PATCH 1/3] Fixed #15851 - Component: Accordion --- src/app/components/accordion/accordion.ts | 25 +++++++++++++---------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/src/app/components/accordion/accordion.ts b/src/app/components/accordion/accordion.ts index 447dbf88104..4a085387e85 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(); } @@ -261,10 +257,20 @@ export class AccordionTab implements AfterContentInit, OnDestroy { }); } + isElementInList(target: HTMLElement | null, elementList: string[]): boolean { + if (!target) { + return false; + } + + const tagName = target.tagName.toLowerCase(); + return elementList.includes(tagName); + } + toggle(event?: MouseEvent | KeyboardEvent) { const target = event.target as HTMLElement; + const elements = ['a', 'button', 'input']; - if (this.disabled || !(target.tagName.toLowerCase() === 'a' && target.classList.contains('p-accordion-header-link'))) { + if (this.disabled || (this.isElementInList(target, elements) && !target.classList.contains('p-accordion-header-link'))) { return false; } @@ -316,7 +322,6 @@ export class AccordionTab implements AfterContentInit, OnDestroy { case 'Enter': case 'Space': this.toggle(event); - event.preventDefault(); break; default: break; @@ -443,10 +448,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) { @@ -646,3 +648,4 @@ export class Accordion implements BlockableUI, AfterContentInit, OnDestroy { declarations: [Accordion, AccordionTab] }) export class AccordionModule {} + From b6422b3e754fd491b3594466a49976ad4b23190c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mehmet=20=C3=87etin?= <92744169+mehmetcetin01140@users.noreply.github.com> Date: Fri, 21 Jun 2024 11:08:09 +0300 Subject: [PATCH 2/3] refactor --- src/app/components/accordion/accordion.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app/components/accordion/accordion.ts b/src/app/components/accordion/accordion.ts index 4a085387e85..ff5aa5f8ff1 100755 --- a/src/app/components/accordion/accordion.ts +++ b/src/app/components/accordion/accordion.ts @@ -268,7 +268,7 @@ export class AccordionTab implements AfterContentInit, OnDestroy { toggle(event?: MouseEvent | KeyboardEvent) { const target = event.target as HTMLElement; - const elements = ['a', 'button', 'input']; + const elements = ['a', 'button', 'input', 'textarea']; if (this.disabled || (this.isElementInList(target, elements) && !target.classList.contains('p-accordion-header-link'))) { return false; From ecea54b3f944e0f67d6c0e64efbc87d047f797db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mehmet=20=C3=87etin?= <92744169+mehmetcetin01140@users.noreply.github.com> Date: Thu, 27 Jun 2024 15:25:53 +0300 Subject: [PATCH 3/3] revert --- src/app/components/accordion/accordion.ts | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/src/app/components/accordion/accordion.ts b/src/app/components/accordion/accordion.ts index ff5aa5f8ff1..391e1cff553 100755 --- a/src/app/components/accordion/accordion.ts +++ b/src/app/components/accordion/accordion.ts @@ -257,20 +257,9 @@ export class AccordionTab implements AfterContentInit, OnDestroy { }); } - isElementInList(target: HTMLElement | null, elementList: string[]): boolean { - if (!target) { - return false; - } - - const tagName = target.tagName.toLowerCase(); - return elementList.includes(tagName); - } - toggle(event?: MouseEvent | KeyboardEvent) { - const target = event.target as HTMLElement; - const elements = ['a', 'button', 'input', 'textarea']; - if (this.disabled || (this.isElementInList(target, elements) && !target.classList.contains('p-accordion-header-link'))) { + if (this.disabled) { return false; } @@ -322,6 +311,7 @@ export class AccordionTab implements AfterContentInit, OnDestroy { case 'Enter': case 'Space': this.toggle(event); + event.preventDefault(); break; default: break;