提交 dddedd2b 编写于 作者: D dolymood

input support change event

上级 eaf623c1
......@@ -15,6 +15,7 @@
:autofocus="autofocus"
@focus="handleFocus"
@blur="handleBlur"
@change="changeHander"
>
<div class="cube-input-append" v-if="$slots.append || _showClear || _showPwdEye">
<div class="cube-input-clear" v-if="_showClear" @click="handleClear">
......@@ -31,6 +32,7 @@
<script type="text/ecmascript-6">
const COMPONENT_NAME = 'cube-input'
const EVENT_INPUT = 'input'
const EVENT_CHANGE = 'change'
const EVENT_BLUR = 'blur'
const EVENT_FOCUS = 'focus'
......@@ -118,6 +120,9 @@
this._computedPwdVisible()
},
methods: {
changeHander(e) {
this.$emit(EVENT_CHANGE, e)
},
_computedPwdVisible() {
if (typeof this.eye === 'boolean') {
this.pwdVisible = this.eye
......
import Vue from 'vue2'
import Input from '@/modules/input'
import createVue from '../utils/create-vue'
import { createEvent } from '../utils/event'
describe('Input.vue', () => {
let vm
......@@ -104,6 +105,42 @@ describe('Input.vue', () => {
})
})
})
it('should trigger events', (done) => {
const focusHandler = sinon.spy()
const blurHandler = sinon.spy()
const changeHandler = sinon.spy()
vm = createVue({
template: `
<cube-input type="password" v-model="value" @focus="focusHandler" @blur="blurHandler" @change="changeHandler" />
`,
data: {
value: 'value'
},
methods: {
focusHandler: focusHandler,
blurHandler: blurHandler,
changeHandler: changeHandler
}
})
const input = vm.$el.querySelector('input')
input.focus()
setTimeout(() => {
expect(focusHandler)
.to.be.calledOnce
input.value = 'new value'
input.blur()
const e = createEvent('', 'change')
input.dispatchEvent(e)
setTimeout(() => {
expect(blurHandler)
.to.be.calledOnce
expect(changeHandler)
.to.be.calledOnce
done()
})
})
})
})
function createInput (value) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册