fix(button): keyboard does not work when setting false (#1509)

Co-authored-by: unknown <liyang@xiaoyouzi.com>
Co-authored-by: 07akioni <07akioni2@gmail.com>
This commit is contained in:
小魔王 2021-11-03 23:14:13 +08:00 committed by GitHub
parent 26fc49f233
commit a28b09c528
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 21 additions and 2 deletions

View File

@ -10,6 +10,7 @@
### Fixes
- Fix `n-alert` `contentTextColor` and `titleTextColor` type theme variable not working, closes [#1495](https://github.com/TuSimple/naive-ui/issues/1495).
- Fix `n-button` `keyboard` prop does not work, closes [#1508](https://github.com/TuSimple/naive-ui/issues/1508).
- Fix `n-upload` instance misses `openOpenFileDialog` method.
### i18n

View File

@ -10,6 +10,7 @@
### Fixes
- 修复 `n-alert` `contentTextColor``titleTextColor` 的类型主题变量不起作用,关闭 [#1495](https://github.com/TuSimple/naive-ui/issues/1495)
- 修复 `n-button` `keyboard` 属性不起作用,关闭 [#1508](https://github.com/TuSimple/naive-ui/issues/1508)
- 修复 `n-upload` 实例缺少 `openOpenFileDialog` 方法
### i18n

View File

@ -153,8 +153,10 @@ const Button = defineComponent({
switch (e.code) {
case 'Enter':
case 'NumpadEnter':
if (!props.keyboard) return
e.preventDefault()
if (!props.keyboard) {
e.preventDefault()
return
}
enterPressedRef.value = true
}
}

View File

@ -18,6 +18,21 @@ describe('n-button', () => {
await inst.trigger('click')
expect(onClick).toHaveBeenCalled()
})
it('keyboard', async () => {
const onClick = jest.fn()
const inst = mount(NButton, {
props: {
keyboard: false,
onClick
}
})
await inst.trigger('click')
expect(onClick).toBeCalledTimes(1)
await inst.trigger('keydown.space')
expect(onClick).toBeCalledTimes(1)
await inst.trigger('keydown.enter')
expect(onClick).toBeCalledTimes(1)
})
it('disabled', async () => {
const onClick = jest.fn()
const inst = mount(NButton, {