mirror of
https://github.com/element-plus/element-plus.git
synced 2024-11-21 01:02:59 +08:00
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:
parent
a4063fd8d2
commit
a99bc4fb49
@ -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,
|
||||
})
|
||||
|
@ -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))
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user