fix: input-number autoFocus not work
parent
a8dcabb1a0
commit
88f165edb5
|
@ -0,0 +1,4 @@
|
|||
import InputNumber from '..'
|
||||
import focusTest from '../../../tests/shared/focusTest'
|
||||
|
||||
focusTest(InputNumber)
|
|
@ -25,6 +25,7 @@ export const InputNumberProps = {
|
|||
name: PropTypes.string,
|
||||
id: PropTypes.string,
|
||||
precision: PropTypes.number,
|
||||
autoFocus: PropTypes.bool,
|
||||
}
|
||||
|
||||
export default {
|
||||
|
|
|
@ -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}
|
||||
|
|
|
@ -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) => {
|
||||
|
|
Loading…
Reference in New Issue