fix: input-number autoFocus not work

pull/77/merge
tjz 2018-06-09 15:48:34 +08:00
parent a8dcabb1a0
commit 88f165edb5
4 changed files with 13 additions and 3 deletions

View File

@ -0,0 +1,4 @@
import InputNumber from '..'
import focusTest from '../../../tests/shared/focusTest'
focusTest(InputNumber)

View File

@ -25,6 +25,7 @@ export const InputNumberProps = {
name: PropTypes.string,
id: PropTypes.string,
precision: PropTypes.number,
autoFocus: PropTypes.bool,
}
export default {

View File

@ -105,6 +105,9 @@ export default {
},
mounted () {
this.$nextTick(() => {
if (this.autoFocus && !this.disabled) {
this.focus()
}
this.updatedFunc()
})
},
@ -571,7 +574,6 @@ export default {
onBlur={this.onBlur}
onKeydown={editable ? this.onKeyDown : noop}
onKeyup={editable ? this.onKeyUp : noop}
autoFocus={this.autoFocus}
maxLength={this.maxLength}
readOnly={this.readOnly}
disabled={this.disabled}

View File

@ -1,4 +1,5 @@
import { mount } from '@vue/test-utils'
import { asyncExpect } from '../utils'
export default function focusTest (Component) {
describe('focus and blur', () => {
@ -22,7 +23,7 @@ export default function focusTest (Component) {
expect(handleFocus).toBeCalled()
})
it('blur() and onBlur', () => {
it('blur() and onBlur', async () => {
const handleBlur = jest.fn()
const wrapper = mount({
render (h) {
@ -32,7 +33,9 @@ export default function focusTest (Component) {
wrapper.vm.$refs.component.focus()
wrapper.vm.$refs.component.blur()
jest.runAllTimers()
expect(handleBlur).toBeCalled()
await asyncExpect(() => {
expect(handleBlur).toBeCalled()
})
})
it('autoFocus', (done) => {