Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Dropdown: dynamic text in placeholder is not displayed fixes #14320 #14631

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions src/app/components/dropdown/dropdown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
Output,
QueryList,
Renderer2,
Signal,
signal,
SimpleChanges,
TemplateRef,
Expand Down Expand Up @@ -403,7 +404,13 @@ export class Dropdown implements OnInit, AfterViewInit, AfterContentInit, AfterV
* Default text to display when no option is selected.
* @group Props
*/
@Input() placeholder: string | undefined;
@Input() set placeholder(val: string | undefined) {
this._placeholder.set(val);
}
get placeholder(): Signal<string | undefined> {
return this._placeholder.asReadonly();
}
_placeholder = signal<string | undefined>(undefined);
/**
* Placeholder text to show when filter input is empty.
* @group Props
Expand Down Expand Up @@ -883,7 +890,7 @@ export class Dropdown implements OnInit, AfterViewInit, AfterContentInit, AfterV
const label = this.label();
return {
'p-dropdown-label p-inputtext': true,
'p-placeholder': this.placeholder && label === this.placeholder,
'p-placeholder': this.placeholder() && label === this.placeholder(),
'p-dropdown-label-empty': !this.editable && !this.selectedItemTemplate && (!label || label === 'p-emptylabel' || label.length === 0)
};
}
Expand Down Expand Up @@ -935,10 +942,10 @@ export class Dropdown implements OnInit, AfterViewInit, AfterContentInit, AfterV
// because of timining issues with virtual scroll lazy load PrimeNG demo, keep original logic for virtual scroll
if (this.virtualScroll) {
const selectedOptionIndex = this.findSelectedOptionIndex();
return selectedOptionIndex !== -1 ? this.getOptionLabel(this.visibleOptions()[selectedOptionIndex]) : this.placeholder || 'p-emptylabel';
return selectedOptionIndex !== -1 ? this.getOptionLabel(this.visibleOptions()[selectedOptionIndex]) : this.placeholder() || 'p-emptylabel';
}
const modelValue = this.modelValue();
return modelValue !== undefined && modelValue !== null ? this.getOptionLabel(this.selectedOption) : this.placeholder || 'p-emptylabel';
return modelValue !== undefined && modelValue !== null ? this.getOptionLabel(this.selectedOption) : this.placeholder() || 'p-emptylabel';
});

selectedOption: any;
Expand Down Expand Up @@ -1113,7 +1120,7 @@ export class Dropdown implements OnInit, AfterViewInit, AfterContentInit, AfterV
}

allowModelChange() {
return this.autoDisplayFirst && !this.placeholder && (this.modelValue() === undefined || this.modelValue() === null) && !this.editable && this.options && this.options.length;
return this.autoDisplayFirst && !this.placeholder() && (this.modelValue() === undefined || this.modelValue() === null) && !this.editable && this.options && this.options.length;
}

isSelected(option) {
Expand Down
Loading