Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions packages/ui/src/v2/components/tooltip-v2-utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export function shouldDropBlock(expand: boolean, hovered: boolean, inside: boolean) {
return !expand && !hovered && !inside
}
19 changes: 19 additions & 0 deletions packages/ui/src/v2/components/tooltip-v2.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { describe, expect, test } from "bun:test"
import { shouldDropBlock } from "./tooltip-v2-utils"
describe("shouldDropBlock", () => {
test("drops the block when tooltip is not expanded, hovered, or focused", () => {
expect(shouldDropBlock(false, false, false)).toBe(true)
})

test("keeps the block while expanded", () => {
expect(shouldDropBlock(true, false, false)).toBe(false)
})

test("keeps the block while hovered", () => {
expect(shouldDropBlock(false, true, false)).toBe(false)
})

test("keeps the block while focus is inside", () => {
expect(shouldDropBlock(false, false, true)).toBe(false)
})
})
11 changes: 7 additions & 4 deletions packages/ui/src/v2/components/tooltip-v2.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { createEffect, Match, onCleanup, splitProps, Switch, type JSX } from "so
import type { ComponentProps } from "solid-js"
import { createStore } from "solid-js/store"
import "./tooltip-v2.css"
import { shouldDropBlock } from "./tooltip-v2-utils"

export interface TooltipV2Props extends ComponentProps<typeof KobalteTooltip> {
value: JSX.Element
Expand All @@ -13,6 +14,8 @@ export interface TooltipV2Props extends ComponentProps<typeof KobalteTooltip> {
forceOpen?: boolean
}



export function TooltipV2(props: TooltipV2Props) {
let ref: HTMLDivElement | undefined
const [state, setState] = createStore({
Expand Down Expand Up @@ -40,10 +43,10 @@ export function TooltipV2(props: TooltipV2Props) {
}

const drop = (expand = state.expand) => {
if (expand) return
if (ref?.matches(":hover")) return
if (inside()) return
setState("block", false)
const hovered = ref?.matches(":hover") ?? false
if (shouldDropBlock(expand, hovered, inside())) {
setState("block", false)
}
}

const sync = () => {
Expand Down
Loading