Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(time-picker): blur event not trigger #1505

Merged
merged 4 commits into from
Nov 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.en-US.md
Original file line number Diff line number Diff line change
Expand Up @@ -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-time-picker` not trigger blur event when the panel is closed by ok button, closes [#1499](https://github.com/TuSimple/naive-ui/issues/1499).
- Fix `n-upload` `UploadFileInfo`'s `thumbnailUrl` field not working, closes [#1495](https://github.com/TuSimple/naive-ui/issues/1245).
- 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.
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
### Fixes

- 修复 `n-alert` `contentTextColor` 和 `titleTextColor` 的类型主题变量不起作用,关闭 [#1495](https://github.com/TuSimple/naive-ui/issues/1495)
- 修复 `n-time-picker` 当选择面板通过确认按钮关闭时不会触发 blur 事件, closes [#1499](https://github.com/TuSimple/naive-ui/issues/1499)
- 修复 `n-upload` `UploadFileInfo` 的 `thumbnailUrl` 字段不起作用,关闭 [#1495](https://github.com/TuSimple/naive-ui/issues/1245)
- 修复 `n-button` `keyboard` 属性不起作用,关闭 [#1508](https://github.com/TuSimple/naive-ui/issues/1508)
- 修复 `n-upload` 实例缺少 `openOpenFileDialog` 方法
Expand Down
2 changes: 2 additions & 0 deletions src/time-picker/src/TimePicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,8 @@ export default defineComponent({
returnFocus: false
})
}
} else {
doBlur(e)
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

搞个测试吧,把 issue 的 case 模拟一下

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok 了


Expand Down
33 changes: 33 additions & 0 deletions src/time-picker/tests/TimePicker.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { mount } from '@vue/test-utils'
import { h } from 'vue'
import { NTimePicker } from '../index'
import { NInput } from '../../input'

describe('n-time-picker', () => {
it('should work with import on demand', () => {
Expand Down Expand Up @@ -95,6 +97,37 @@ describe('n-time-picker', () => {
expect(onBlur).toHaveBeenCalled()
wrapper.unmount()
})
it('should work with `on-blur` prop when use `ok` button', async () => {
const onBlur = jest.fn()
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
const Render = () => {
return h('div', null, [
h(NTimePicker, {
onBlur,
actions: ['confirm']
}),
h(NInput, {
inputProps: {
id: 'input'
}
})
])
}
const wrapper = mount(Render, {
attachTo: document.body
})
await wrapper.find('input').trigger('click')
const button: HTMLElement = document.querySelector(
'.n-button'
) as HTMLElement
button.click()

const input = document.querySelector('#input') as HTMLElement
input.focus()

expect(onBlur).toHaveBeenCalled()
wrapper.unmount()
})

it('should work with `on-focus` prop', async () => {
const onFocus = jest.fn()
Expand Down