Skip to content

Commit

Permalink
fix: input-number autoFocus not work
Browse files Browse the repository at this point in the history
  • Loading branch information
tangjinzhou committed Jun 9, 2018
1 parent a8dcabb commit 88f165e
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 3 deletions.
4 changes: 4 additions & 0 deletions components/input-number/__tests__/index.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import InputNumber from '..'
import focusTest from '../../../tests/shared/focusTest'

focusTest(InputNumber)
1 change: 1 addition & 0 deletions components/input-number/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export const InputNumberProps = {
name: PropTypes.string,
id: PropTypes.string,
precision: PropTypes.number,
autoFocus: PropTypes.bool,
}

export default {
Expand Down
4 changes: 3 additions & 1 deletion components/vc-input-number/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@ export default {
},
mounted () {
this.$nextTick(() => {
if (this.autoFocus && !this.disabled) {
this.focus()
}
this.updatedFunc()
})
},
Expand Down Expand Up @@ -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}
Expand Down
7 changes: 5 additions & 2 deletions tests/shared/focusTest.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { mount } from '@vue/test-utils'
import { asyncExpect } from '../utils'

export default function focusTest (Component) {
describe('focus and blur', () => {
Expand All @@ -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) {
Expand All @@ -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) => {
Expand Down

0 comments on commit 88f165e

Please sign in to comment.