I have a primeng multiselect dropdown as:
<p-multiSelect
[options]="stateList.items || []"
[(ngModel)]="selectedStates"
[ngModelOptions]="{ standalone: true }"
optionLabel="name"
optionValue="id"
display="chip"
(click)="onMultiSelectClick($event)"
(mousedown)="onMultiSelectMouseDown($event)"
(ngModelChange)="onMultiSelectChange($event)"
placeholder="test">
</p-multiSelect>
It works well; I can open it and select the "select all" checkbox or select one by one; the problem is when I "unselect," sometimes it closes the dropdown automatically, and sometimes not... it's just weird behavior
As you can see, I tried multiple events to prevent it from closing:
onMultiSelectClick(event: Event) {
this.isDropdownOpen = !this.isDropdownOpen;
}
onMultiSelectMouseDown(event: Event) {
if (this.isDropdownOpen) {
event.stopPropagation();
}
}
onMultiSelectChange(event: any) {
this.selectedStates = event;
this.isDropdownOpen = false;
}
onItemDeSelect(event: Event) {
event.stopPropagation();
}
But none worked; it just keeps closing when I want to unselect (not always). Does anyone know how I can prevent it from closing?
One workaround for this is to use OnHide.
And the component.ts file changes will be like this. Declare one variable to handle it. And the function for it.
Try this method and see if it fits your requirement. Do let me know.