From e5af155b3164adc9108bb45cf862e9d8ae8d4a63 Mon Sep 17 00:00:00 2001 From: Sofia Papacharalampous Date: Tue, 30 Apr 2024 17:43:10 +0300 Subject: [PATCH] fixed single autocomplete panel behavior --- .../single-auto-complete.component.html | 64 ++++++++++--------- .../single/single-auto-complete.component.ts | 16 ++++- 2 files changed, 47 insertions(+), 33 deletions(-) diff --git a/dmp-frontend/src/app/library/auto-complete/single/single-auto-complete.component.html b/dmp-frontend/src/app/library/auto-complete/single/single-auto-complete.component.html index 9f231ecb1..43d806668 100644 --- a/dmp-frontend/src/app/library/auto-complete/single/single-auto-complete.component.html +++ b/dmp-frontend/src/app/library/auto-complete/single/single-auto-complete.component.html @@ -4,45 +4,47 @@ --> arrow_drop_down - - - - - -
- {{_titleFn(item)}} -
- {{_subtitleFn(item)}} - {{popupItemActionIcon}} -
-
-
-
- -
- - +
+ + + + item: item + }">
- {{_titleFn(item)}} + {{_titleFn(item)}}
{{_subtitleFn(item)}} {{popupItemActionIcon}}
- - - No results found! +
+
+ +
+ + + + +
+ {{_titleFn(item)}} +
+ {{_subtitleFn(item)}} + {{popupItemActionIcon}} +
+
+
+ + No results found! + +
+ + loading... -
- - loading... - - + +
\ No newline at end of file diff --git a/dmp-frontend/src/app/library/auto-complete/single/single-auto-complete.component.ts b/dmp-frontend/src/app/library/auto-complete/single/single-auto-complete.component.ts index 8a34d8dd0..97d2c11c5 100644 --- a/dmp-frontend/src/app/library/auto-complete/single/single-auto-complete.component.ts +++ b/dmp-frontend/src/app/library/auto-complete/single/single-auto-complete.component.ts @@ -8,7 +8,7 @@ import { MatFormFieldControl } from '@angular/material/form-field'; import { AutoCompleteGroup } from '@app/library/auto-complete/auto-complete-group'; import { SingleAutoCompleteConfiguration } from '@app/library/auto-complete/single/single-auto-complete-configuration'; import { BaseComponent } from '@common/base/base.component'; -import { Observable, Subject, of as observableOf, of } from 'rxjs'; +import { Observable, Subject, Subscription, of as observableOf, of } from 'rxjs'; import { catchError, debounceTime, distinctUntilChanged, map, mergeMap, startWith, switchMap, takeUntil, tap } from 'rxjs/operators'; @@ -31,6 +31,9 @@ export const _CustomComponentMixinBase = mixinErrorState(CustomComponentBase); }) export class SingleAutoCompleteComponent extends _CustomComponentMixinBase implements OnInit, MatFormFieldControl, ControlValueAccessor, OnDestroy, DoCheck, OnChanges { + isMouseOverPanel: boolean = false; + panelClosedSubscription: Subscription; + static nextId = 0; @ViewChild('autocomplete', { static: true }) autocomplete: MatAutocomplete; @ViewChild('autocompleteTrigger', { static: true }) autocompleteTrigger: MatAutocompleteTrigger; @@ -115,6 +118,10 @@ export class SingleAutoCompleteComponent extends _CustomComponentMixinBase imple fm.monitor(elRef.nativeElement, true).pipe(takeUntil(this._destroyed)).subscribe((origin) => { this.focused = !!origin; this.stateChanges.next(); + + if (!this.isMouseOverPanel && !this.focused) { + this.autocompleteTrigger?.closePanel(); + } }); if (this.ngControl != null) { @@ -124,7 +131,11 @@ export class SingleAutoCompleteComponent extends _CustomComponentMixinBase imple } } - ngOnInit() { } + ngOnInit() { + this.panelClosedSubscription = this.autocomplete.closed.subscribe((next) => { + this.isMouseOverPanel = false; + }); + } ngDoCheck(): void { if (this.ngControl) { @@ -292,6 +303,7 @@ export class SingleAutoCompleteComponent extends _CustomComponentMixinBase imple } ngOnDestroy() { + this.panelClosedSubscription.unsubscribe(); this.stateChanges.complete(); this.fm.stopMonitoring(this.elRef.nativeElement); }