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

feat(components): [time-picker] add open and close handlers #9572

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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 6 additions & 4 deletions docs/en-US/component/time-picker.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 | — |
34 changes: 34 additions & 0 deletions packages/components/time-picker/__tests__/time-picker.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
16 changes: 16 additions & 0 deletions packages/components/time-picker/src/common/picker.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -732,6 +740,14 @@ defineExpose({
* @description emit blur event
*/
handleBlurInput,
/**
* @description opens picker
*/
handleOpen,
/**
* @description closes picker
*/
handleClose,
/**
* @description pick item manually
*/
Expand Down
12 changes: 12 additions & 0 deletions packages/components/time-picker/src/time-picker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down