diff --git a/src/app/components/dropdown/dropdown.ts b/src/app/components/dropdown/dropdown.ts index dd58cea843d..484b7b7a24e 100755 --- a/src/app/components/dropdown/dropdown.ts +++ b/src/app/components/dropdown/dropdown.ts @@ -146,9 +146,11 @@ export class DropdownItem { (blur)="onInputBlur($event)" (keydown)="onKeyDown($event)" > - {{ label() === 'p-emptylabel' ? ' ' : label() || 'empty' }} + {{ label() === 'p-emptylabel' ? ' ' : label() || 'empty' }} - {{ placeholder || 'empty' }} + + {{ label() === 'p-emptylabel' ? ' ' : placeholder}} + { let selectedOptionIndex; - - if (this.autoDisplayFirst) { - selectedOptionIndex = this.findFirstOptionIndex(); - } - if (!this.autoDisplayFirst) { - selectedOptionIndex = this.findSelectedOptionIndex(); - } - + this.autoDisplayFirst ? !this.modelValue() ? (selectedOptionIndex = -1) : (selectedOptionIndex = this.findFirstOptionIndex()) : (selectedOptionIndex = this.findSelectedOptionIndex()); return this.modelValue() ? this.getOptionLabel(this.modelValue()) : selectedOptionIndex !== -1 ? this.getOptionLabel(this.visibleOptions()[selectedOptionIndex]) : this.placeholder || 'p-emptylabel'; }); @@ -1049,6 +1044,7 @@ export class Dropdown implements OnInit, AfterViewInit, AfterContentInit, AfterV updateModel(value, event?) { this.onModelChange(value); + this.value = value; this.modelValue.set(value); this.selectedOptionUpdated = true; this.onChange.emit({ @@ -1116,7 +1112,6 @@ export class Dropdown implements OnInit, AfterViewInit, AfterContentInit, AfterV if (this.filter) { this.resetFilter(); } - this.value = this.modelValue(); this.updateModel(this.value); this.updateEditableLabel(); @@ -1691,7 +1686,7 @@ export class Dropdown implements OnInit, AfterViewInit, AfterContentInit, AfterV } clear(event: Event) { - this.updateModel(event, null); + this.updateModel(null, event); this.updateEditableLabel(); this.onClear.emit(event); } diff --git a/src/app/showcase/doc/dropdown/basicdoc.ts b/src/app/showcase/doc/dropdown/basicdoc.ts index edf1896cffd..8c684f31dba 100644 --- a/src/app/showcase/doc/dropdown/basicdoc.ts +++ b/src/app/showcase/doc/dropdown/basicdoc.ts @@ -17,7 +17,7 @@ interface City {

- +
` @@ -43,11 +43,11 @@ export class BasicDoc implements OnInit { code: Code = { basic: ` -`, +`, html: `
- +
`, typescript: `