fix(select): placeholder can be reset if value = null

This commit is contained in:
Manu Mtz.-Almeida
2018-09-25 02:29:38 +02:00
parent e18f8bfa0e
commit 602f668787

View File

@ -27,7 +27,7 @@ export class Select implements ComponentInterface {
@State() isExpanded = false; @State() isExpanded = false;
@State() keyFocus = false; @State() keyFocus = false;
@State() text?: string | null; @State() text = '';
/** /**
* The mode determines which platform styles to use. * The mode determines which platform styles to use.
@ -164,10 +164,8 @@ export class Select implements ComponentInterface {
} }
}); });
if (texts.length > 0) {
this.text = texts.join(', '); this.text = texts.join(', ');
} }
}
// emit the new value // emit the new value
this.ionChange.emit({ this.ionChange.emit({
@ -250,9 +248,7 @@ export class Select implements ComponentInterface {
// fire off an unnecessary change event // fire off an unnecessary change event
(this.value as string[]).push(o.value); (this.value as string[]).push(o.value);
}); });
if (checked.map(o => o.textContent).length > 0) {
this.text = checked.map(o => o.textContent).join(', '); this.text = checked.map(o => o.textContent).join(', ');
}
} else { } else {
const checked = this.childOpts.find(o => o.selected); const checked = this.childOpts.find(o => o.selected);
@ -475,7 +471,7 @@ export class Select implements ComponentInterface {
let addPlaceholderClass = false; let addPlaceholderClass = false;
let selectText = this.selectedText || this.text; let selectText = this.selectedText || this.text;
if (selectText == null && this.placeholder != null) { if (selectText === '' && this.placeholder != null) {
selectText = this.placeholder; selectText = this.placeholder;
addPlaceholderClass = true; addPlaceholderClass = true;
} }