Skip to content

Commit

Permalink
Fixed #14801 and Fixed #14815
Browse files Browse the repository at this point in the history
  • Loading branch information
cetincakiroglu committed Feb 22, 2024
1 parent fc8747b commit 24ea912
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/app/components/dropdown/dropdown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ export class DropdownItem {
<ng-container *ngIf="!selectedItemTemplate; else defaultPlaceholder">{{ label() === 'p-emptylabel' ? '&nbsp;' : label() }}</ng-container>
<ng-container *ngIf="selectedItemTemplate && selectedOption" [ngTemplateOutlet]="selectedItemTemplate" [ngTemplateOutletContext]="{ $implicit: selectedOption }"></ng-container>
<ng-template #defaultPlaceholder>
<span *ngIf="(modelValue() === undefined || modelValue() === null) && (label() === placeholder() || (label() && !placeholder()))">{{ label() === 'p-emptylabel' ? '&nbsp;' : placeholder() }}</span>
<span *ngIf="displayPlaceholder()">{{ label() === 'p-emptylabel' ? '&nbsp;' : placeholder() }}</span>
</ng-template>
</span>
<input
Expand Down Expand Up @@ -969,7 +969,7 @@ export class Dropdown implements OnInit, AfterViewInit, AfterContentInit, AfterV

if (visibleOptions && ObjectUtils.isNotEmpty(visibleOptions)) {
const selectedOptionIndex = this.findSelectedOptionIndex();
if (selectedOptionIndex !== -1 || modelValue === undefined || modelValue === null || this.editable) {
if (selectedOptionIndex !== -1 || modelValue === undefined || (typeof modelValue === 'string' && modelValue.length === 0) || modelValue === null || this.editable) {
this.selectedOption = visibleOptions[selectedOptionIndex];
}
}
Expand All @@ -985,6 +985,10 @@ export class Dropdown implements OnInit, AfterViewInit, AfterContentInit, AfterV
});
}

displayPlaceholder() {
return ObjectUtils.isEmpty(this.selectedOption) && this.label() === this.placeholder();
}

private getAllVisibleAndNonVisibleOptions() {
return this.group ? this.flatOptions(this.options) : this.options || [];
}
Expand Down Expand Up @@ -1111,9 +1115,9 @@ export class Dropdown implements OnInit, AfterViewInit, AfterContentInit, AfterV
const value = this.getOptionValue(option);
this.updateModel(value, event);
this.focusedOptionIndex.set(this.findSelectedOptionIndex());
isHide && setTimeout(() => this.hide(true), 1);
preventChange === false && this.onChange.emit({ originalEvent: event, value: value });
}
isHide && setTimeout(() => this.hide(true), 1);
}

onOptionMouseEnter(event, index) {
Expand Down Expand Up @@ -1184,7 +1188,11 @@ export class Dropdown implements OnInit, AfterViewInit, AfterContentInit, AfterV
}

isOptionDisabled(option: any) {
return this.optionDisabled ? ObjectUtils.resolveFieldData(option, this.optionDisabled) : option && option.disabled !== undefined ? option.disabled : false;
if (this.getOptionValue(this.modelValue()) === this.getOptionValue(option) || (this.getOptionLabel(this.modelValue() === this.getOptionLabel(option)) && option.disabled === false)) {
return false;
} else {
return this.optionDisabled ? ObjectUtils.resolveFieldData(option, this.optionDisabled) : option && option.disabled !== undefined ? option.disabled : false;
}
}

getOptionGroupLabel(optionGroup: any) {
Expand Down

1 comment on commit 24ea912

@rosenthalj
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cetincakiroglu ,

I quickly tested all the changes made to dropdown.ts that were merged back into the master branch (before the next release). Everything was working well except for Issue #14811. It appears the merge for Issue #14811 inadvertently reverted the changes that were made just a few hours earlier. See the two annotated screenshots listed below.

Cursor_and_History_for_src_-_primefaces_primeng_and_Angular_Dropdown_Component

Cursor_and_Fixed__14801_and_Fixed__14815_·_primefaces_primeng_24ea912

Please sign in to comment.