From 5a30f0449965d931a091bacb6d7b9d6c6db2421e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mehmet=20=C3=87etin?= <92744169+mehmetcetin01140@users.noreply.github.com> Date: Wed, 3 Jul 2024 16:23:04 +0300 Subject: [PATCH 1/4] Fixed #15869 - CascadeSelect | clicking a few times causes the component to freeze --- .../components/cascadeselect/cascadeselect.ts | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/app/components/cascadeselect/cascadeselect.ts b/src/app/components/cascadeselect/cascadeselect.ts index 3786a2ce95..a62824e007 100755 --- a/src/app/components/cascadeselect/cascadeselect.ts +++ b/src/app/components/cascadeselect/cascadeselect.ts @@ -662,6 +662,10 @@ export class CascadeSelect implements OnInit, AfterContentInit { processedOptions: string[] | string | undefined = []; + containerClickTimeout: any = null; + + containerClickDebounceTime = 200; + get containerClass() { return { 'p-cascadeselect p-component p-inputwrapper': true, @@ -1085,7 +1089,7 @@ export class CascadeSelect implements OnInit, AfterContentInit { } onContainerClick(event: MouseEvent) { - if (this.disabled || this.loading) { + if (this.disabled || this.loading || this.containerClickTimeout) { return; } @@ -1098,6 +1102,19 @@ export class CascadeSelect implements OnInit, AfterContentInit { this.focusInputViewChild?.nativeElement.focus(); } + + this.containerClickTimeout = setTimeout(() => { + this.containerClickTimeout = null; + + if (document?.activeElement !== this.focusInputViewChild?.nativeElement) { + this.focusInputViewChild?.nativeElement.focus(); + } + }, this.containerClickDebounceTime); + } + + cancelContainerClickTimeout(): void { + clearTimeout(this.containerClickTimeout); + this.containerClickTimeout = null; } isOptionMatched(processedOption) { From b2531deec268f7c8310357f65de2480820b25c13 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mehmet=20=C3=87etin?= <92744169+mehmetcetin01140@users.noreply.github.com> Date: Thu, 4 Jul 2024 10:41:05 +0300 Subject: [PATCH 2/4] refactor --- src/app/components/cascadeselect/cascadeselect.ts | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/app/components/cascadeselect/cascadeselect.ts b/src/app/components/cascadeselect/cascadeselect.ts index a62824e007..750ec88c62 100755 --- a/src/app/components/cascadeselect/cascadeselect.ts +++ b/src/app/components/cascadeselect/cascadeselect.ts @@ -1112,11 +1112,6 @@ export class CascadeSelect implements OnInit, AfterContentInit { }, this.containerClickDebounceTime); } - cancelContainerClickTimeout(): void { - clearTimeout(this.containerClickTimeout); - this.containerClickTimeout = null; - } - isOptionMatched(processedOption) { return this.isValidOption(processedOption) && this.getProccessedOptionLabel(processedOption).toLocaleLowerCase(this.searchLocale).startsWith(this.searchValue.toLocaleLowerCase(this.searchLocale)); } From 3e16a8d7aab32cbd8c86f177f6d6ae5bc568bd04 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mehmet=20=C3=87etin?= <92744169+mehmetcetin01140@users.noreply.github.com> Date: Fri, 5 Jul 2024 13:52:20 +0300 Subject: [PATCH 3/4] refactor --- src/app/components/overlay/overlay.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/app/components/overlay/overlay.ts b/src/app/components/overlay/overlay.ts index 32eee0082b..2d2e02a7b5 100644 --- a/src/app/components/overlay/overlay.ts +++ b/src/app/components/overlay/overlay.ts @@ -514,13 +514,18 @@ export class Overlay implements AfterContentInit, OnDestroy { switch (event.toState) { case 'visible': - this.show(container, true); + if (this.visible) { + this.show(container, true); + } this.bindListeners(); break; case 'void': - this.hide(container, true); + if (!this.visible) { + this.hide(container, true); + } + this.unbindListeners(); DomHandler.appendOverlay(this.overlayEl, this.targetEl, this.appendTo); From 86da162eb2bf6c56ac6f1362fcfed5a495f69206 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mehmet=20=C3=87etin?= <92744169+mehmetcetin01140@users.noreply.github.com> Date: Fri, 5 Jul 2024 13:54:51 +0300 Subject: [PATCH 4/4] revert cs click debounce --- src/app/components/cascadeselect/cascadeselect.ts | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/src/app/components/cascadeselect/cascadeselect.ts b/src/app/components/cascadeselect/cascadeselect.ts index 750ec88c62..3786a2ce95 100755 --- a/src/app/components/cascadeselect/cascadeselect.ts +++ b/src/app/components/cascadeselect/cascadeselect.ts @@ -662,10 +662,6 @@ export class CascadeSelect implements OnInit, AfterContentInit { processedOptions: string[] | string | undefined = []; - containerClickTimeout: any = null; - - containerClickDebounceTime = 200; - get containerClass() { return { 'p-cascadeselect p-component p-inputwrapper': true, @@ -1089,7 +1085,7 @@ export class CascadeSelect implements OnInit, AfterContentInit { } onContainerClick(event: MouseEvent) { - if (this.disabled || this.loading || this.containerClickTimeout) { + if (this.disabled || this.loading) { return; } @@ -1102,14 +1098,6 @@ export class CascadeSelect implements OnInit, AfterContentInit { this.focusInputViewChild?.nativeElement.focus(); } - - this.containerClickTimeout = setTimeout(() => { - this.containerClickTimeout = null; - - if (document?.activeElement !== this.focusInputViewChild?.nativeElement) { - this.focusInputViewChild?.nativeElement.focus(); - } - }, this.containerClickDebounceTime); } isOptionMatched(processedOption) {