fix: prevent tooltip reopen on trigger click (#22571)
This commit is contained in:
@@ -99,6 +99,8 @@ export function Tooltip(props: TooltipProps) {
|
|||||||
onCleanup(() => obs.disconnect())
|
onCleanup(() => obs.disconnect())
|
||||||
})
|
})
|
||||||
|
|
||||||
|
let justClickedTrigger = false
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Switch>
|
<Switch>
|
||||||
<Match when={local.inactive}>{local.children}</Match>
|
<Match when={local.inactive}>{local.children}</Match>
|
||||||
@@ -112,6 +114,10 @@ export function Tooltip(props: TooltipProps) {
|
|||||||
onOpenChange={(open) => {
|
onOpenChange={(open) => {
|
||||||
if (local.forceOpen) return
|
if (local.forceOpen) return
|
||||||
if (state.block && open) return
|
if (state.block && open) return
|
||||||
|
if (justClickedTrigger) {
|
||||||
|
justClickedTrigger = false
|
||||||
|
return
|
||||||
|
}
|
||||||
setState("open", open)
|
setState("open", open)
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
@@ -137,6 +143,12 @@ export function Tooltip(props: TooltipProps) {
|
|||||||
data-force-open={local.forceOpen}
|
data-force-open={local.forceOpen}
|
||||||
class={local.contentClass}
|
class={local.contentClass}
|
||||||
style={local.contentStyle}
|
style={local.contentStyle}
|
||||||
|
onPointerDownOutside={(e) => {
|
||||||
|
if (ref === e.target || (e.target instanceof Node && ref?.contains(e.target))) {
|
||||||
|
justClickedTrigger = true
|
||||||
|
}
|
||||||
|
e.preventDefault()
|
||||||
|
}}
|
||||||
>
|
>
|
||||||
{local.value}
|
{local.value}
|
||||||
{/* <KobalteTooltip.Arrow data-slot="tooltip-arrow" /> */}
|
{/* <KobalteTooltip.Arrow data-slot="tooltip-arrow" /> */}
|
||||||
|
|||||||
Reference in New Issue
Block a user