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

show 'empty' on dropdown list and empty label on placeholder #15325

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
8 changes: 4 additions & 4 deletions src/app/components/dropdown/dropdown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export const DROPDOWN_VALUE_ACCESSOR: any = {
[ngStyle]="{ height: itemSize + 'px' }"
[ngClass]="{ 'p-dropdown-item': true, 'p-highlight': selected, 'p-disabled': disabled, 'p-focus': focused }"
>
<span *ngIf="!template">{{ label ?? 'empty' }}</span>
<span *ngIf="!template">{{ label !== null && label !== '' ? label : 'empty' }}</span>
<ng-container *ngTemplateOutlet="template; context: { $implicit: option }"></ng-container>
</li>
`,
Expand Down Expand Up @@ -154,7 +154,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="displayPlaceholder()">{{ label() === 'p-emptylabel' ? '&nbsp;' : placeholder() }}</span>
<span *ngIf="displayPlaceholder()">{{ label() === 'p-emptylabel' || label() ? '&nbsp;' : placeholder() }}</span>
</ng-template>
</span>
<input
Expand Down Expand Up @@ -952,8 +952,8 @@ export class Dropdown implements OnInit, AfterViewInit, AfterContentInit, AfterV
const options = this.getAllVisibleAndNonVisibleOptions();
// use isOptionEqualsModelValue for the use case where the dropdown is initalized with a disabled option
const selectedOptionIndex = options.findIndex((option) => this.isOptionValueEqualsModelValue(option));

return selectedOptionIndex !== -1 ? this.getOptionLabel(options[selectedOptionIndex]) : this.placeholder() || 'p-emptylabel';
const optionLabel = this.getOptionLabel(options[selectedOptionIndex]);
return selectedOptionIndex !== -1 ? (optionLabel !== '' && optionLabel !== null ? optionLabel : 'p-emptylabel') : (this.placeholder() !== '' ? this.placeholder() : 'p-emptylabel');
});

filled = computed(() => {
Expand Down
Loading