Skip to content

Commit

Permalink
fix(ui/select): fix bug of select blur event can't trigger
Browse files Browse the repository at this point in the history
affects: @varlet/ui
  • Loading branch information
haoziqaq committed May 13, 2021
1 parent 6bc64e9 commit b9918fc
Show file tree
Hide file tree
Showing 5 changed files with 693 additions and 2 deletions.
14 changes: 14 additions & 0 deletions packages/varlet-ui/src/input/__tests__/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ test('test input focus & blur', async () => {
wrapper.vm.blur()
await wrapper.find('.var-input__input').trigger('blur')
expect(wrapper.html()).toMatchSnapshot()

wrapper.unmount()
})

test('test input onInput & onChange & onClick', async () => {
Expand Down Expand Up @@ -64,6 +66,8 @@ test('test input onInput & onChange & onClick', async () => {

await wrapper.find('.var-input__input').trigger('change')
expect(onChange).lastCalledWith('t', new Event('input'))

wrapper.unmount()
})

test('test input maxlength', () => {
Expand All @@ -87,6 +91,8 @@ test('test input hint to be false', () => {
})

expect(wrapper.html()).toMatchSnapshot()

wrapper.unmount()
})

test('test input clear', async () => {
Expand All @@ -108,6 +114,8 @@ test('test input clear', async () => {
expect(onUpdateModelValue).lastCalledWith('')
expect(onClear).lastCalledWith('')
expect(wrapper.props('modelValue')).toBe('')

wrapper.unmount()
})

test('test input disabled', async () => {
Expand Down Expand Up @@ -140,6 +148,8 @@ test('test input disabled', async () => {
expect(onClick).toHaveBeenCalledTimes(0)
expect(onChange).toHaveBeenCalledTimes(0)
expect(onUpdateModelValue).toHaveBeenCalledTimes(0)

wrapper.unmount()
})

test('test input validation', async () => {
Expand Down Expand Up @@ -169,6 +179,8 @@ test('test input validation', async () => {
await delay(16)
expect(wrapper.find('.var-form-details__message').exists()).toBeFalsy()
expect(wrapper.html()).toMatchSnapshot()

wrapper.unmount()
})

test('test input number value', async () => {
Expand All @@ -186,4 +198,6 @@ test('test input number value', async () => {

expect(onUpdateModelValue).lastCalledWith(1)
expect(wrapper.props('modelValue')).toBe(1)

wrapper.unmount()
})
2 changes: 1 addition & 1 deletion packages/varlet-ui/src/option/Option.vue
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export default defineComponent({
watch(
[() => props.label, () => props.value],
() => {
if (props.label == null && props.value === null) {
if (props.label == null && props.value == null) {
throw Error("Props label and value can't both be undefined\n")
}
},
Expand Down
8 changes: 7 additions & 1 deletion packages/varlet-ui/src/select/Select.vue
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,13 @@
<slot name="prepend-icon" />
</div>

<var-menu class="var-select__menu" var-select-cover :offset-y="offsetY" v-model:show="isFocus" @blur="handleBlur">
<var-menu
class="var-select__menu"
var-select-cover
:offset-y="offsetY"
v-model:show="isFocus"
@close="handleBlur"
>
<div
class="var-select__wrap"
:class="[!hint ? 'var-select--non-hint' : null]"
Expand Down
Loading

0 comments on commit b9918fc

Please sign in to comment.