Skip to content

Commit 0171b33

Browse files
committed
Hide autocomplete list when a page/window is scrolled
1 parent 7a9e81a commit 0171b33

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

ddp-workspace/projects/ddp-sdk/src/lib/components/activityForm/picklist/autocompleteActivityPicklistQuestion.component.ts

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
1-
import { Component, Inject, OnChanges, OnDestroy, OnInit, SimpleChanges } from '@angular/core';
1+
import {
2+
Component,
3+
HostListener,
4+
Inject,
5+
OnChanges,
6+
OnDestroy,
7+
OnInit,
8+
SimpleChanges,
9+
ViewChild
10+
} from '@angular/core';
211
import { FormControl } from '@angular/forms';
12+
import { MatAutocompleteTrigger } from '@angular/material/autocomplete';
313
import { Subject } from 'rxjs';
414
import { debounceTime, distinctUntilChanged, map, startWith, takeUntil } from 'rxjs/operators';
515

@@ -44,12 +54,13 @@ import { ConfigurationService } from '../../../services/configuration.service';
4454
`]
4555
})
4656
export class AutocompleteActivityPicklistQuestion extends BaseActivityPicklistQuestion implements OnInit, OnDestroy, OnChanges {
47-
private readonly ngUnsubscribe = new Subject();
57+
@ViewChild(MatAutocompleteTrigger, {read: MatAutocompleteTrigger}) autoComplete: MatAutocompleteTrigger;
4858

4959
filteredGroups: ActivityPicklistNormalizedGroup[] = [];
5060
// options w/o a group
5161
filteredOptions: ActivityPicklistOption[] = [];
5262
inputFormControl = new FormControl();
63+
private readonly ngUnsubscribe = new Subject();
5364

5465
constructor(
5566
translate: NGXTranslateService,
@@ -169,4 +180,10 @@ export class AutocompleteActivityPicklistQuestion extends BaseActivityPicklistQu
169180
displayAutoComplete(option: ActivityPicklistOption | string): string {
170181
return typeof option === 'string' ? option : (option?.optionLabel || '');
171182
}
183+
184+
@HostListener('window: scroll') public onWindowScroll(): void {
185+
if (this.autoComplete?.panelOpen) {
186+
this.autoComplete.closePanel();
187+
}
188+
}
172189
}

0 commit comments

Comments
 (0)