Skip to content

Commit

Permalink
Select: Fix show empty option when value is undefined (ElemeFE#15007)
Browse files Browse the repository at this point in the history
  • Loading branch information
cl199793 committed May 15, 2019
1 parent 16a6059 commit 65da4c4
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
28 changes: 24 additions & 4 deletions examples/play/index.vue
Original file line number Diff line number Diff line change
@@ -1,14 +1,34 @@
<template>
<div style="margin: 20px;">
<el-input v-model="input" placeholder="请输入内容"></el-input>
</div>
<el-select
v-model="value10"
filterable
allow-create
default-first-option
placeholder="请选择文章标签">
<el-option
v-for="item in options5"
:key="item.value"
:label="item.label"
:value="item.value">
</el-option>
</el-select>
</template>

<script>
export default {
data() {
return {
input: 'Hello Element UI!'
options5: [{
value: 'HTML',
label: 'HTML'
}, {
value: 'CSS',
label: 'CSS'
}, {
value: 'JavaScript',
label: 'JavaScript'
}],
value10: undefined
};
}
};
Expand Down
3 changes: 2 additions & 1 deletion packages/select/src/select.vue
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,7 @@
let option;
const isObject = Object.prototype.toString.call(value).toLowerCase() === '[object object]';
const isNull = Object.prototype.toString.call(value).toLowerCase() === '[object null]';
const isUndefined = value === undefined;
for (let i = this.cachedOptions.length - 1; i >= 0; i--) {
const cachedOption = this.cachedOptions[i];
Expand All @@ -522,7 +523,7 @@
}
}
if (option) return option;
const label = (!isObject && !isNull)
const label = (!isObject && !isNull && !isUndefined)
? value : '';
let newOption = {
value: value,
Expand Down

0 comments on commit 65da4c4

Please sign in to comment.