fix(components): [popover | tooltip] keep autoClose prop (#11833)

* feat(hooks): [use-delayed-toggle] add autoClose option

* fix(components): [tooltip] keep autoClose prop
This commit is contained in:
Dave 2023-03-10 14:48:12 +08:00 committed by GitHub
parent a4063fd8d2
commit a99bc4fb49
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 1 deletions

View File

@ -103,6 +103,7 @@ const { show, hide, hasUpdateHandler } = useTooltipModelToggle({
const { onOpen, onClose } = useDelayedToggle({
showAfter: toRef(props, 'showAfter'),
hideAfter: toRef(props, 'hideAfter'),
autoClose: toRef(props, 'autoClose'),
open: show,
close: hide,
})

View File

@ -1,5 +1,5 @@
import { unref } from 'vue'
import { buildProps } from '@element-plus/utils'
import { buildProps, isNumber } from '@element-plus/utils'
import { useTimeout } from '../use-timeout'
import type { ExtractPropTypes, ToRefs } from 'vue'
@ -19,6 +19,10 @@ export const useDelayedToggleProps = buildProps({
type: Number,
default: 200,
},
autoClose: {
type: Number,
default: 0,
},
} as const)
export type UseDelayedToggleProps = {
@ -29,14 +33,23 @@ export type UseDelayedToggleProps = {
export const useDelayedToggle = ({
showAfter,
hideAfter,
autoClose,
open,
close,
}: UseDelayedToggleProps) => {
const { registerTimeout } = useTimeout()
const { registerTimeout: registerTimeoutForAutoClose } = useTimeout()
const onOpen = (event?: Event) => {
registerTimeout(() => {
open(event)
const _autoClose = unref(autoClose)
if (isNumber(_autoClose) && _autoClose > 0) {
registerTimeoutForAutoClose(() => {
close(event)
}, _autoClose)
}
}, unref(showAfter))
}