mirror of
https://gitee.com/element-plus/element-plus.git
synced 2024-12-14 09:20:51 +08:00
42ff59fc39
* feat(components): [date-picker] a11y controls and attributes * feat(components): [date-picker] keyboard controls for picker * feat(components): [date-picker] unit test complete * feat(components): [date-picker] remove immediate watch date
48 lines
936 B
TypeScript
48 lines
936 B
TypeScript
import { unref } from 'vue'
|
|
import { buildProps } from '@element-plus/utils'
|
|
import { useTimeout } from '../use-timeout'
|
|
|
|
import type { ExtractPropTypes, ToRefs } from 'vue'
|
|
|
|
export const useDelayedToggleProps = buildProps({
|
|
showAfter: {
|
|
type: Number,
|
|
default: 0,
|
|
},
|
|
hideAfter: {
|
|
type: Number,
|
|
default: 200,
|
|
},
|
|
} as const)
|
|
|
|
export type UseDelayedToggleProps = {
|
|
open: (event?: Event) => void
|
|
close: (event?: Event) => void
|
|
} & ToRefs<ExtractPropTypes<typeof useDelayedToggleProps>>
|
|
|
|
export const useDelayedToggle = ({
|
|
showAfter,
|
|
hideAfter,
|
|
open,
|
|
close,
|
|
}: UseDelayedToggleProps) => {
|
|
const { registerTimeout } = useTimeout()
|
|
|
|
const onOpen = (event?: Event) => {
|
|
registerTimeout(() => {
|
|
open(event)
|
|
}, unref(showAfter))
|
|
}
|
|
|
|
const onClose = (event?: Event) => {
|
|
registerTimeout(() => {
|
|
close(event)
|
|
}, unref(hideAfter))
|
|
}
|
|
|
|
return {
|
|
onOpen,
|
|
onClose,
|
|
}
|
|
}
|