mirror of
https://gitee.com/element-plus/element-plus.git
synced 2024-12-05 12:48:04 +08:00
feat(components): [time-picker] add open and close handlers (#9572)
* feat(components): [time-picker] add handleOpen and handleClose methods * chore: update time-picker docs * chore: update time-picker docs * feat(components): [time-picker] add handleOpen and handleClose methods * fix: revert changes in pnpm-lock.yaml * fix: update the handlers description in the docs Co-authored-by: João Gonçalves <jandretgoncalves@gmail.com>
This commit is contained in:
parent
718c23c923
commit
8156606388
@ -76,7 +76,9 @@ time-picker/range
|
||||
|
||||
## Methods
|
||||
|
||||
| Method | Description | Parameters |
|
||||
| ------ | ------------------------- | ---------- |
|
||||
| focus | focus the Input component | — |
|
||||
| blur | blur the Input component | — |
|
||||
| Method | Description | Parameters |
|
||||
| ----------- | --------------------------- | ---------- |
|
||||
| focus | focus the Input component | — |
|
||||
| blur | blur the Input component | — |
|
||||
| handleOpen | open the TimePicker popper | — |
|
||||
| handleClose | close the TimePicker popper | — |
|
||||
|
@ -347,6 +347,40 @@ describe('TimePicker', () => {
|
||||
expect(attr).toEqual('false')
|
||||
})
|
||||
|
||||
it('ref handleOpen', async () => {
|
||||
const value = ref(new Date(2016, 9, 10, 18, 40))
|
||||
const wrapper = mount(() => <TimePicker v-model={value.value} />)
|
||||
const timePickerExposed = wrapper.findComponent(TimePicker).vm.$.exposed
|
||||
|
||||
await nextTick()
|
||||
timePickerExposed.handleOpen()
|
||||
|
||||
await nextTick()
|
||||
const popperEl = document.querySelector('.el-picker__popper')
|
||||
const attr = popperEl.getAttribute('aria-hidden')
|
||||
expect(attr).toEqual('false')
|
||||
})
|
||||
|
||||
it('ref handleClose', async () => {
|
||||
vi.useFakeTimers()
|
||||
|
||||
const value = ref(new Date(2016, 9, 10, 18, 40))
|
||||
const wrapper = mount(() => <TimePicker v-model={value.value} />)
|
||||
const timePickerExposed = wrapper.findComponent(TimePicker).vm.$.exposed
|
||||
|
||||
await nextTick()
|
||||
timePickerExposed.handleOpen()
|
||||
await nextTick()
|
||||
timePickerExposed.handleClose()
|
||||
|
||||
await nextTick()
|
||||
const popperEl = document.querySelector('.el-picker__popper')
|
||||
const attr = popperEl.getAttribute('aria-hidden')
|
||||
expect(attr).toEqual('true')
|
||||
|
||||
vi.useRealTimers()
|
||||
})
|
||||
|
||||
it('model value should sync when disabled-hours was updated', async () => {
|
||||
const value = ref('2000-01-01 00:00:00')
|
||||
const minHour = ref('8')
|
||||
|
@ -338,6 +338,14 @@ const onHide = () => {
|
||||
emit('visible-change', false)
|
||||
}
|
||||
|
||||
const handleOpen = () => {
|
||||
pickerVisible.value = true
|
||||
}
|
||||
|
||||
const handleClose = () => {
|
||||
pickerVisible.value = false
|
||||
}
|
||||
|
||||
const focus = (focusStartInput = true, isIgnoreFocusEvent = false) => {
|
||||
ignoreFocusEvent = isIgnoreFocusEvent
|
||||
const [leftInput, rightInput] = unref(refInput)
|
||||
@ -732,6 +740,14 @@ defineExpose({
|
||||
* @description emit blur event
|
||||
*/
|
||||
handleBlurInput,
|
||||
/**
|
||||
* @description opens picker
|
||||
*/
|
||||
handleOpen,
|
||||
/**
|
||||
* @description closes picker
|
||||
*/
|
||||
handleClose,
|
||||
/**
|
||||
* @description pick item manually
|
||||
*/
|
||||
|
@ -40,6 +40,18 @@ export default defineComponent({
|
||||
blur: (e: FocusEvent | undefined) => {
|
||||
commonPicker.value?.handleBlurInput(e)
|
||||
},
|
||||
/**
|
||||
* @description opens the picker element
|
||||
*/
|
||||
handleOpen: () => {
|
||||
commonPicker.value?.handleOpen()
|
||||
},
|
||||
/**
|
||||
* @description closes the picker element
|
||||
*/
|
||||
handleClose: () => {
|
||||
commonPicker.value?.handleClose()
|
||||
},
|
||||
})
|
||||
|
||||
return () => {
|
||||
|
Loading…
Reference in New Issue
Block a user