-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(input-number): many fixes (#259)
* fix(input-number): many fixes - Fix `n-input-number` lacks `on-update-value` prop. - Fix `n-input-number`'s value can't be null. - Fix `n-input-number`'s button doesn't work after value is cleared, closes [#251](#251). - `n-input-number` will focus directly, closes [#244](#244). * docs(input-number): fixes * docs
- Loading branch information
Showing
11 changed files
with
155 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# Debug | ||
|
||
```html | ||
<n-input-number | ||
v-model:value="value1" | ||
placeholder="最小值" | ||
:min="-3" | ||
:max="5" | ||
@update:value="handleUpdateValue1" | ||
/> | ||
{{ JSON.stringify(value1) }} | ||
<n-input-number v-model:value="value2" @update:value="handleUpdateValue2" /> | ||
{{ JSON.stringify(value2) }} | ||
``` | ||
|
||
```js | ||
import { defineComponent, ref } from 'vue' | ||
|
||
export default defineComponent({ | ||
setup () { | ||
return { | ||
handleUpdateValue1 (v) { | ||
console.log(v) | ||
}, | ||
handleUpdateValue2 (v) { | ||
console.log(v) | ||
}, | ||
value1: ref(null), | ||
value2: ref(null) | ||
} | ||
} | ||
}) | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export type OnUpdateValue = (value: number | null) => void |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import { mount } from '@vue/test-utils' | ||
import { NInputNumber } from '../index' | ||
import { NButton } from '../../button' | ||
|
||
describe('n-input-number', () => { | ||
it('should work with import on demand', () => { | ||
mount(NInputNumber) | ||
}) | ||
|
||
it('should work with `show-button` prop', async () => { | ||
const wrapper = mount(NInputNumber) | ||
expect(wrapper.findComponent(NButton).exists()).toBe(true) | ||
|
||
await wrapper.setProps({ showButton: false }) | ||
expect(wrapper.findComponent(NButton).exists()).toBe(false) | ||
}) | ||
|
||
it('should work with default value', async () => { | ||
const wrapper = mount(NInputNumber, { | ||
props: { | ||
defaultValue: 1 | ||
} | ||
}) | ||
expect(wrapper.find('input').element.value).toEqual('1') | ||
}) | ||
|
||
it('should not trigger update if value is same', async () => { | ||
const onUpdateValue = jest.fn() | ||
const wrapper = mount(NInputNumber, { | ||
attachTo: document.body, | ||
props: { | ||
defaultValue: 1, | ||
onUpdateValue | ||
} | ||
}) | ||
wrapper.find('input').element.value = '' | ||
await wrapper.find('input').trigger('input') | ||
expect(onUpdateValue).toHaveBeenCalledWith(null) | ||
wrapper.unmount() | ||
}) | ||
|
||
it('trigger focus & blur event', () => { | ||
const onFocus = jest.fn() | ||
const onBlur = jest.fn() | ||
const wrapper = mount(NInputNumber, { | ||
attachTo: document.body, | ||
props: { | ||
onFocus, | ||
onBlur | ||
} | ||
}) | ||
wrapper.find('input').element.focus() | ||
expect(onFocus).toHaveBeenCalledTimes(1) | ||
wrapper.find('input').element.blur() | ||
expect(onBlur).toHaveBeenCalledTimes(1) | ||
wrapper.unmount() | ||
}) | ||
}) |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { mount } from '@vue/test-utils' | ||
import { NInput } from '../index' | ||
|
||
describe('n-input', () => { | ||
it('should work with import on demand', () => { | ||
mount(NInput) | ||
}) | ||
it('should call input callbacks', async () => { | ||
const onUpdateValue = jest.fn() | ||
const wrapper = mount(NInput, { | ||
props: { | ||
onUpdateValue | ||
} | ||
}) | ||
wrapper.find('input').element.value = 'cool' | ||
await wrapper.find('input').trigger('input') | ||
expect(onUpdateValue).toHaveBeenCalledWith('cool') | ||
}) | ||
}) |