Skip to content

Commit

Permalink
Fixed #14299
Browse files Browse the repository at this point in the history
  • Loading branch information
cetincakiroglu committed Dec 12, 2023
1 parent cfb1729 commit 92c38d5
Showing 1 changed file with 14 additions and 20 deletions.
34 changes: 14 additions & 20 deletions src/app/components/multiselect/multiselect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -381,8 +381,8 @@ export class MultiSelectItem {
`,
host: {
class: 'p-element p-inputwrapper',
'[class.p-inputwrapper-filled]': 'filled',
'[class.p-inputwrapper-focus]': 'focused || overlayVisible'
'[class.p-inputwrapper-focus]': 'focused || overlayVisible',
'[class.p-inputwrapper-filled]': 'filled'
},
providers: [MULTISELECT_VALUE_ACCESSOR],
changeDetection: ChangeDetectionStrategy.OnPush,
Expand Down Expand Up @@ -948,8 +948,6 @@ export class MultiSelect implements OnInit, AfterViewInit, AfterContentInit, Aft

filterOptions: MultiSelectFilterOptions | undefined;

maxSelectionLimitReached: boolean | undefined;

preventModelTouched: boolean | undefined;

preventDocumentDefault: boolean | undefined;
Expand Down Expand Up @@ -980,9 +978,7 @@ export class MultiSelect implements OnInit, AfterViewInit, AfterContentInit, Aft
'p-disabled': this.disabled,
'p-multiselect-clearable': this.showClear && !this.disabled,
'p-multiselect-chip': this.display === 'chip',
'p-focus': this.focused,
'p-inputwrapper-filled': ObjectUtils.isNotEmpty(this.modelValue()),
'p-inputwrapper-focus': this.focused || this.overlayVisible
'p-focus': this.focused
};
}

Expand Down Expand Up @@ -1021,7 +1017,7 @@ export class MultiSelect implements OnInit, AfterViewInit, AfterContentInit, Aft
get filled(): boolean {
if (typeof this.modelValue() === 'string') return !!this.modelValue();

return this.modelValue() || this.modelValue() != null || this.modelValue() != undefined;
return ObjectUtils.isNotEmpty(this.modelValue());
}

get isVisibleClearIcon(): boolean | undefined {
Expand Down Expand Up @@ -1091,6 +1087,7 @@ export class MultiSelect implements OnInit, AfterViewInit, AfterContentInit, Aft
constructor(public el: ElementRef, public renderer: Renderer2, public cd: ChangeDetectorRef, public zone: NgZone, public filterService: FilterService, public config: PrimeNGConfig, public overlayService: OverlayService) {
effect(() => {
const modelValue = this.modelValue();

const visibleOptions = this.visibleOptions();
if (visibleOptions && ObjectUtils.isNotEmpty(visibleOptions) && modelValue) {
if (this.optionValue && this.optionLabel) {
Expand All @@ -1114,6 +1111,10 @@ export class MultiSelect implements OnInit, AfterViewInit, AfterContentInit, Aft
}
}

maxSelectionLimitReached() {
return this.selectionLimit && this.modelValue() && this.modelValue().length === this.selectionLimit;
}

ngAfterContentInit() {
(this.templates as QueryList<PrimeTemplate>).forEach((item) => {
switch (item.getType()) {
Expand Down Expand Up @@ -1356,8 +1357,10 @@ export class MultiSelect implements OnInit, AfterViewInit, AfterContentInit, Aft
}

isOptionDisabled(option: any) {
let disabled = this.optionDisabled ? ObjectUtils.resolveFieldData(option, this.optionDisabled) : option && option.disabled !== undefined ? option.disabled : false;
return disabled || (this.maxSelectionLimitReached && !this.isSelected(option));
if (this.maxSelectionLimitReached() && !this.isSelected(option)) {
return true;
}
return this.optionDisabled ? ObjectUtils.resolveFieldData(option, this.optionDisabled) : option && option.disabled !== undefined ? option.disabled : false;
}

isSelected(option) {
Expand Down Expand Up @@ -1836,18 +1839,9 @@ export class MultiSelect implements OnInit, AfterViewInit, AfterContentInit, Aft
return this.focusedOptionIndex() !== -1 ? `${this.id}_${this.focusedOptionIndex()}` : null;
}

checkSelectionLimit() {
if (this.selectionLimit && this.value && this.value.length === this.selectionLimit) {
this.maxSelectionLimitReached = true;
} else {
this.maxSelectionLimitReached = false;
}
}

writeValue(value: any): void {
this.value = value;
this.modelValue.set(this.value);
this.checkSelectionLimit();
this.cd.markForCheck();
}

Expand Down Expand Up @@ -1946,7 +1940,6 @@ export class MultiSelect implements OnInit, AfterViewInit, AfterContentInit, Aft

clear(event: Event) {
this.value = null;
this.checkSelectionLimit();
this.updateModel(null, event);
this.selectedOptions = null;
this.onClear.emit();
Expand All @@ -1963,6 +1956,7 @@ export class MultiSelect implements OnInit, AfterViewInit, AfterContentInit, Aft
value: value,
itemValue: optionValue
});

event && event.stopPropagation();
}

Expand Down

0 comments on commit 92c38d5

Please sign in to comment.