From 811900e4897c06bfd91c42c33ad14bca5711abce Mon Sep 17 00:00:00 2001 From: Diego Franchina Date: Fri, 8 Dec 2023 10:48:47 +0100 Subject: [PATCH 1/2] fix(autocomplete): Stop event propagations on remove option --- .../components/autocomplete/autocomplete.ts | 20 ++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/app/components/autocomplete/autocomplete.ts b/src/app/components/autocomplete/autocomplete.ts index dde193169dd..068e6cbcc9f 100755 --- a/src/app/components/autocomplete/autocomplete.ts +++ b/src/app/components/autocomplete/autocomplete.ts @@ -718,9 +718,9 @@ export class AutoComplete implements AfterViewChecked, AfterContentInit, OnDestr _suggestions = signal(null); - onModelChange: Function = () => {}; + onModelChange: Function = () => { }; - onModelTouched: Function = () => {}; + onModelTouched: Function = () => { }; timeout: Nullable; @@ -844,7 +844,7 @@ export class AutoComplete implements AfterViewChecked, AfterContentInit, OnDestr return !this.virtualScroll; } - constructor(@Inject(DOCUMENT) private document: Document, public el: ElementRef, public renderer: Renderer2, public cd: ChangeDetectorRef, public config: PrimeNGConfig, public overlayService: OverlayService, private zone: NgZone) {} + constructor(@Inject(DOCUMENT) private document: Document, public el: ElementRef, public renderer: Renderer2, public cd: ChangeDetectorRef, public config: PrimeNGConfig, public overlayService: OverlayService, private zone: NgZone) { } ngOnInit() { this.id = this.id || UniqueComponentId(); @@ -974,8 +974,8 @@ export class AutoComplete implements AfterViewChecked, AfterContentInit, OnDestr const matchedOptionIndex = index < this.visibleOptions().length - 1 ? this.visibleOptions() - .slice(index + 1) - .findIndex((option) => this.isValidOption(option)) + .slice(index + 1) + .findIndex((option) => this.isValidOption(option)) : -1; return matchedOptionIndex > -1 ? matchedOptionIndex + index + 1 : index; @@ -1418,6 +1418,8 @@ export class AutoComplete implements AfterViewChecked, AfterContentInit, OnDestr } removeOption(event, index) { + event.stopPropagation(); + const removedOption = this.modelValue()[index]; const value = this.modelValue() .filter((_, i) => i !== index) @@ -1529,9 +1531,9 @@ export class AutoComplete implements AfterViewChecked, AfterContentInit, OnDestr return ( (this.optionGroupLabel ? index - - this.visibleOptions() - .slice(0, index) - .filter((option) => this.isOptionGroup(option)).length + this.visibleOptions() + .slice(0, index) + .filter((option) => this.isOptionGroup(option)).length : index) + 1 ); } @@ -1608,4 +1610,4 @@ export class AutoComplete implements AfterViewChecked, AfterContentInit, OnDestr exports: [AutoComplete, OverlayModule, SharedModule, ScrollerModule, AutoFocusModule], declarations: [AutoComplete] }) -export class AutoCompleteModule {} +export class AutoCompleteModule { } From 0cf708096b6cd724518e7725a00b9e8676bffced Mon Sep 17 00:00:00 2001 From: Diego Franchina Date: Fri, 8 Dec 2023 11:01:02 +0100 Subject: [PATCH 2/2] format code --- .../components/autocomplete/autocomplete.ts | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/app/components/autocomplete/autocomplete.ts b/src/app/components/autocomplete/autocomplete.ts index 068e6cbcc9f..918036729c0 100755 --- a/src/app/components/autocomplete/autocomplete.ts +++ b/src/app/components/autocomplete/autocomplete.ts @@ -718,9 +718,9 @@ export class AutoComplete implements AfterViewChecked, AfterContentInit, OnDestr _suggestions = signal(null); - onModelChange: Function = () => { }; + onModelChange: Function = () => {}; - onModelTouched: Function = () => { }; + onModelTouched: Function = () => {}; timeout: Nullable; @@ -844,7 +844,7 @@ export class AutoComplete implements AfterViewChecked, AfterContentInit, OnDestr return !this.virtualScroll; } - constructor(@Inject(DOCUMENT) private document: Document, public el: ElementRef, public renderer: Renderer2, public cd: ChangeDetectorRef, public config: PrimeNGConfig, public overlayService: OverlayService, private zone: NgZone) { } + constructor(@Inject(DOCUMENT) private document: Document, public el: ElementRef, public renderer: Renderer2, public cd: ChangeDetectorRef, public config: PrimeNGConfig, public overlayService: OverlayService, private zone: NgZone) {} ngOnInit() { this.id = this.id || UniqueComponentId(); @@ -974,8 +974,8 @@ export class AutoComplete implements AfterViewChecked, AfterContentInit, OnDestr const matchedOptionIndex = index < this.visibleOptions().length - 1 ? this.visibleOptions() - .slice(index + 1) - .findIndex((option) => this.isValidOption(option)) + .slice(index + 1) + .findIndex((option) => this.isValidOption(option)) : -1; return matchedOptionIndex > -1 ? matchedOptionIndex + index + 1 : index; @@ -1531,9 +1531,9 @@ export class AutoComplete implements AfterViewChecked, AfterContentInit, OnDestr return ( (this.optionGroupLabel ? index - - this.visibleOptions() - .slice(0, index) - .filter((option) => this.isOptionGroup(option)).length + this.visibleOptions() + .slice(0, index) + .filter((option) => this.isOptionGroup(option)).length : index) + 1 ); } @@ -1610,4 +1610,4 @@ export class AutoComplete implements AfterViewChecked, AfterContentInit, OnDestr exports: [AutoComplete, OverlayModule, SharedModule, ScrollerModule, AutoFocusModule], declarations: [AutoComplete] }) -export class AutoCompleteModule { } +export class AutoCompleteModule {}