fix(app): tooltip children focus loop
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
import { Tooltip as KobalteTooltip } from "@kobalte/core/tooltip"
|
import { Tooltip as KobalteTooltip } from "@kobalte/core/tooltip"
|
||||||
import { children, createSignal, Match, onMount, splitProps, Switch, type JSX } from "solid-js"
|
import { createSignal, Match, splitProps, Switch, type JSX } from "solid-js"
|
||||||
import type { ComponentProps } from "solid-js"
|
import type { ComponentProps } from "solid-js"
|
||||||
|
|
||||||
export interface TooltipProps extends ComponentProps<typeof KobalteTooltip> {
|
export interface TooltipProps extends ComponentProps<typeof KobalteTooltip> {
|
||||||
@@ -40,32 +40,16 @@ export function Tooltip(props: TooltipProps) {
|
|||||||
"contentStyle",
|
"contentStyle",
|
||||||
"inactive",
|
"inactive",
|
||||||
"forceOpen",
|
"forceOpen",
|
||||||
|
"value",
|
||||||
])
|
])
|
||||||
|
|
||||||
const c = children(() => local.children)
|
|
||||||
|
|
||||||
onMount(() => {
|
|
||||||
const childElements = c()
|
|
||||||
if (childElements instanceof HTMLElement) {
|
|
||||||
childElements.addEventListener("focusin", () => setOpen(true))
|
|
||||||
childElements.addEventListener("focusout", () => setOpen(false))
|
|
||||||
} else if (Array.isArray(childElements)) {
|
|
||||||
for (const child of childElements) {
|
|
||||||
if (child instanceof HTMLElement) {
|
|
||||||
child.addEventListener("focusin", () => setOpen(true))
|
|
||||||
child.addEventListener("focusout", () => setOpen(false))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Switch>
|
<Switch>
|
||||||
<Match when={local.inactive}>{local.children}</Match>
|
<Match when={local.inactive}>{local.children}</Match>
|
||||||
<Match when={true}>
|
<Match when={true}>
|
||||||
<KobalteTooltip gutter={4} {...others} open={local.forceOpen || open()} onOpenChange={setOpen}>
|
<KobalteTooltip gutter={4} {...others} open={local.forceOpen || open()} onOpenChange={setOpen}>
|
||||||
<KobalteTooltip.Trigger as={"div"} data-component="tooltip-trigger" class={local.class}>
|
<KobalteTooltip.Trigger as={"div"} data-component="tooltip-trigger" class={local.class}>
|
||||||
{c()}
|
{local.children}
|
||||||
</KobalteTooltip.Trigger>
|
</KobalteTooltip.Trigger>
|
||||||
<KobalteTooltip.Portal>
|
<KobalteTooltip.Portal>
|
||||||
<KobalteTooltip.Content
|
<KobalteTooltip.Content
|
||||||
@@ -75,7 +59,7 @@ export function Tooltip(props: TooltipProps) {
|
|||||||
class={local.contentClass}
|
class={local.contentClass}
|
||||||
style={local.contentStyle}
|
style={local.contentStyle}
|
||||||
>
|
>
|
||||||
{others.value}
|
{local.value}
|
||||||
{/* <KobalteTooltip.Arrow data-slot="tooltip-arrow" /> */}
|
{/* <KobalteTooltip.Arrow data-slot="tooltip-arrow" /> */}
|
||||||
</KobalteTooltip.Content>
|
</KobalteTooltip.Content>
|
||||||
</KobalteTooltip.Portal>
|
</KobalteTooltip.Portal>
|
||||||
|
|||||||
Reference in New Issue
Block a user