Commit b91e8ee3 authored by Lukasz Balcerzak's avatar Lukasz Balcerzak Committed by 杨奕

Select: reset input height when filterable and collapse tags (#8966)

* Added example that exposes the issue

* Fixed issue if select component has collapse tags and filtering enabled at the same time

* tests

* simpler tests
parent fdd746f2
...@@ -102,6 +102,7 @@ ...@@ -102,6 +102,7 @@
value9: [], value9: [],
value10: [], value10: [],
value11: [], value11: [],
value12: [],
loading: false, loading: false,
states: ["Alabama", "Alaska", "Arizona", "Arkansas", "California", "Colorado", "Connecticut", "Delaware", "Florida", "Georgia", "Hawaii", "Idaho", "Illinois", "Indiana", "Iowa", "Kansas", "Kentucky", "Louisiana", "Maine", "Maryland", "Massachusetts", "Michigan", "Minnesota", "Mississippi", "Missouri", "Montana", "Nebraska", "Nevada", "New Hampshire", "New Jersey", "New Mexico", "New York", "North Carolina", "North Dakota", "Ohio", "Oklahoma", "Oregon", "Pennsylvania", "Rhode Island", "South Carolina", "South Dakota", "Tennessee", "Texas", "Utah", "Vermont", "Virginia", "Washington", "West Virginia", "Wisconsin", "Wyoming"] states: ["Alabama", "Alaska", "Arizona", "Arkansas", "California", "Colorado", "Connecticut", "Delaware", "Florida", "Georgia", "Hawaii", "Idaho", "Illinois", "Indiana", "Iowa", "Kansas", "Kentucky", "Louisiana", "Maine", "Maryland", "Massachusetts", "Michigan", "Minnesota", "Mississippi", "Missouri", "Montana", "Nebraska", "Nevada", "New Hampshire", "New Jersey", "New Mexico", "New York", "North Carolina", "North Dakota", "Ohio", "Oklahoma", "Oregon", "Pennsylvania", "Rhode Island", "South Carolina", "South Dakota", "Tennessee", "Texas", "Utah", "Vermont", "Virginia", "Washington", "West Virginia", "Wisconsin", "Wyoming"]
}; };
...@@ -346,6 +347,21 @@ Multiple select uses tags to display selected options. ...@@ -346,6 +347,21 @@ Multiple select uses tags to display selected options.
:value="item.value"> :value="item.value">
</el-option> </el-option>
</el-select> </el-select>
<el-select
v-model="value12"
multiple
filterable
collapse-tags
style="margin-left: 20px; width: 200px"
placeholder="Select">
<el-option
v-for="item in options"
:key="item.value"
:label="item.label"
:value="item.value">
</el-option>
</el-select>
</template> </template>
<script> <script>
......
...@@ -564,7 +564,7 @@ ...@@ -564,7 +564,7 @@
}, },
resetInputHeight() { resetInputHeight() {
if (this.collapseTags) return; if (this.collapseTags && !this.filterable) return;
this.$nextTick(() => { this.$nextTick(() => {
if (!this.$refs.reference) return; if (!this.$refs.reference) return;
let inputChildNodes = this.$refs.reference.$el.childNodes; let inputChildNodes = this.$refs.reference.$el.childNodes;
......
...@@ -3,7 +3,7 @@ import Select from 'packages/select'; ...@@ -3,7 +3,7 @@ import Select from 'packages/select';
describe('Select', () => { describe('Select', () => {
const getSelectVm = (configs = {}, options) => { const getSelectVm = (configs = {}, options) => {
['multiple', 'clearable', 'filterable', 'allowCreate', 'remote'].forEach(config => { ['multiple', 'clearable', 'filterable', 'allowCreate', 'remote', 'collapseTags'].forEach(config => {
configs[config] = configs[config] || false; configs[config] = configs[config] || false;
}); });
configs.multipleLimit = configs.multipleLimit || 0; configs.multipleLimit = configs.multipleLimit || 0;
...@@ -34,12 +34,14 @@ describe('Select', () => { ...@@ -34,12 +34,14 @@ describe('Select', () => {
template: ` template: `
<div> <div>
<el-select <el-select
ref="select"
v-model="value" v-model="value"
:multiple="multiple" :multiple="multiple"
:multiple-limit="multipleLimit" :multiple-limit="multipleLimit"
:popper-class="popperClass" :popper-class="popperClass"
:clearable="clearable" :clearable="clearable"
:filterable="filterable" :filterable="filterable"
:collapse-tags="collapseTags"
:allow-create="allowCreate" :allow-create="allowCreate"
:filterMethod="filterMethod" :filterMethod="filterMethod"
:remote="remote" :remote="remote"
...@@ -63,6 +65,7 @@ describe('Select', () => { ...@@ -63,6 +65,7 @@ describe('Select', () => {
multipleLimit: configs.multipleLimit, multipleLimit: configs.multipleLimit,
clearable: configs.clearable, clearable: configs.clearable,
filterable: configs.filterable, filterable: configs.filterable,
collapseTags: configs.collapseTags,
allowCreate: configs.allowCreate, allowCreate: configs.allowCreate,
popperClass: configs.popperClass, popperClass: configs.popperClass,
loading: false, loading: false,
...@@ -713,4 +716,32 @@ describe('Select', () => { ...@@ -713,4 +716,32 @@ describe('Select', () => {
}, 10); }, 10);
}, 10); }, 10);
}); });
describe('resetInputHeight', () => {
const getSelectComponentVm = (configs) => {
vm = getSelectVm(configs || {});
return vm.$refs.select;
};
it('should reset height if collapse-tags option is disabled', () => {
const select = getSelectComponentVm();
sinon.stub(select, '$nextTick');
select.resetInputHeight();
expect(select.$nextTick.callCount).to.equal(1);
});
it('should not reset height if collapse-tags option is enabled', () => {
const select = getSelectComponentVm({ collapseTags: true });
sinon.stub(select, '$nextTick');
select.resetInputHeight();
expect(select.$nextTick.callCount).to.equal(0);
});
it('should reset height if both collapse-tags and filterable are enabled', () => {
const select = getSelectComponentVm({ collapseTags: true, filterable: true });
sinon.stub(select, '$nextTick');
select.resetInputHeight();
expect(select.$nextTick.callCount).to.equal(1);
});
});
}); });
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment