fix(select): fix emptyText error show (#1213)

* fix(select): fix emptyText error show

* test(select): add emptyText error show test case
This commit is contained in:
Ryan2128
2021-01-07 06:26:26 -06:00
committed by GitHub
parent f7bd2ff710
commit dd13cb78da
2 changed files with 43 additions and 8 deletions

View File

@@ -17,7 +17,7 @@ interface SelectProps {
popperClass?: string
}
const _mount = (template: string, data: any = () => ({}), otherObj?): any => mount({
const _mount = (template: string, data: any = () => ({}), otherObj?) => mount({
components: {
'el-select': Select,
'el-option': Option,
@@ -432,7 +432,6 @@ describe('Select', () => {
await nextTick()
const tagWrappers = wrapper.findAll('.el-select__tags-text')
const tagWrapperDom = tagWrappers[0].element
console.log(tagWrapperDom.style.maxWidth)
expect(parseInt(tagWrapperDom.style.maxWidth) === inputRect.width - 123).toBe(true)
mockInputWidth.mockRestore()
})
@@ -610,4 +609,40 @@ describe('Select', () => {
await vm.$nextTick()
expect(wrapper.find('.el-input__inner').element.value).toBe('黄金糕')
})
test('emptyText error show', async () => {
const wrapper = _mount(`
<el-select :model-value="value" filterable placeholder="Select">
<el-option
v-for="item in options"
:key="item.value"
:label="item.label"
:value="item.value">
</el-option>
</el-select>`,
() => ({
options: [{
value: 'Option1',
label: 'Option1',
}, {
value: 'Option2',
label: 'Option2',
}, {
value: 'Option3',
label: 'Option3',
}, {
value: 'Option4',
label: 'Option4',
}, {
value: 'Option5',
label: 'Option5',
}],
value: 'test',
}))
const select = wrapper.findComponent({ name: 'ElSelect' })
select.trigger('click')
await nextTick()
expect(!!document.querySelector('.el-select__popper').style.display).toBeFalsy()
expect(wrapper.findAll('.el-select-dropdown__empty').length).toBe(0)
})
})

View File

@@ -192,20 +192,20 @@ export const useSelect = (props, states: States, ctx) => {
if (props.filterable) {
states.query = props.remote ? '' : states.selectedLabel
handleQueryChange(states.query)
if (props.multiple) {
input.value.focus()
} else {
if (!props.remote) {
states.selectEmitter.emit('elOptionQueryChange', '')
states.selectEmitter.emit('elOptionGroupQueryChange')
}
if (states.selectedLabel) {
states.currentPlaceholder = states.selectedLabel
states.selectedLabel = ''
}
}
if (!props.multiple && !props.remote) {
states.selectEmitter.emit('elOptionQueryChange', '')
states.selectEmitter.emit('elOptionGroupQueryChange')
} else {
handleQueryChange(states.query)
}
}
}
ctx.emit('visible-change', val)