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,
|
name: PropTypes.string,
|
||||||
id: PropTypes.string,
|
id: PropTypes.string,
|
||||||
precision: PropTypes.number,
|
precision: PropTypes.number,
|
||||||
|
autoFocus: PropTypes.bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
|
|
|
@ -105,6 +105,9 @@ export default {
|
||||||
},
|
},
|
||||||
mounted () {
|
mounted () {
|
||||||
this.$nextTick(() => {
|
this.$nextTick(() => {
|
||||||
|
if (this.autoFocus && !this.disabled) {
|
||||||
|
this.focus()
|
||||||
|
}
|
||||||
this.updatedFunc()
|
this.updatedFunc()
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
@ -571,7 +574,6 @@ export default {
|
||||||
onBlur={this.onBlur}
|
onBlur={this.onBlur}
|
||||||
onKeydown={editable ? this.onKeyDown : noop}
|
onKeydown={editable ? this.onKeyDown : noop}
|
||||||
onKeyup={editable ? this.onKeyUp : noop}
|
onKeyup={editable ? this.onKeyUp : noop}
|
||||||
autoFocus={this.autoFocus}
|
|
||||||
maxLength={this.maxLength}
|
maxLength={this.maxLength}
|
||||||
readOnly={this.readOnly}
|
readOnly={this.readOnly}
|
||||||
disabled={this.disabled}
|
disabled={this.disabled}
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import { mount } from '@vue/test-utils'
|
import { mount } from '@vue/test-utils'
|
||||||
|
import { asyncExpect } from '../utils'
|
||||||
|
|
||||||
export default function focusTest (Component) {
|
export default function focusTest (Component) {
|
||||||
describe('focus and blur', () => {
|
describe('focus and blur', () => {
|
||||||
|
@ -22,7 +23,7 @@ export default function focusTest (Component) {
|
||||||
expect(handleFocus).toBeCalled()
|
expect(handleFocus).toBeCalled()
|
||||||
})
|
})
|
||||||
|
|
||||||
it('blur() and onBlur', () => {
|
it('blur() and onBlur', async () => {
|
||||||
const handleBlur = jest.fn()
|
const handleBlur = jest.fn()
|
||||||
const wrapper = mount({
|
const wrapper = mount({
|
||||||
render (h) {
|
render (h) {
|
||||||
|
@ -32,7 +33,9 @@ export default function focusTest (Component) {
|
||||||
wrapper.vm.$refs.component.focus()
|
wrapper.vm.$refs.component.focus()
|
||||||
wrapper.vm.$refs.component.blur()
|
wrapper.vm.$refs.component.blur()
|
||||||
jest.runAllTimers()
|
jest.runAllTimers()
|
||||||
expect(handleBlur).toBeCalled()
|
await asyncExpect(() => {
|
||||||
|
expect(handleBlur).toBeCalled()
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
it('autoFocus', (done) => {
|
it('autoFocus', (done) => {
|
||||||
|
|
Loading…
Reference in New Issue