From 5b6fc47eff589cd4a86daee72a9b4dd397457a59 Mon Sep 17 00:00:00 2001 From: Haruko Sugimoto Date: Mon, 2 Nov 2026 18:32:02 +0900 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20feat(tooltip):=20=E9=96=8B=E9=96=89?= =?UTF-8?q?=E3=81=AE=E3=82=A2=E3=83=8B=E3=83=A1=E3=83=BC=E3=82=B7=E3=83=A7?= =?UTF-8?q?=E3=83=B3=E3=82=92=E3=83=A2=E3=83=BC=E3=82=B7=E3=83=A7=E3=83=B3?= =?UTF-8?q?=E3=83=88=E3=83=BC=E3=82=AF=E3=83=B3=E3=81=A7=E5=8B=95=E3=81=8B?= =?UTF-8?q?=E3=81=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 箱を animate-motion-pop-in-small / -out-small で動かし、表示する側に応じてアンカーの側から出す(--motion-pop-from-x / -y) - 文字を data-slot="tooltip-text" の要素で包み、animate-motion-content-in-tooltip で箱より遅れてフェードインさせる - origin-[--radix-…](Tailwind v4 では無効な CSS になる)を origin-(--radix-tooltip-content-transform-origin) に直し、拡大の支点をアンカー側にする - テストを文字の包みに合わせ、アニメーションのクラスと時間を直書きしていないことのテストを追加 - CHANGELOG に追記 Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 5 ++ src/components/ui/tooltip/index.test.tsx | 69 +++++++++++++++++++----- src/components/ui/tooltip/index.tsx | 19 ++++--- 3 files changed, 75 insertions(+), 18 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 38556158..a5ec12d1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,11 @@ - Dialog と Overlay のアニメーションを、モーショントークン(`--motion-*`)で動かすようにしました。`sparkle.config.json` の `motion-weight` で選んだ重さに合わせて動きます。Dialog のパネルは下から出て、中身はパネルより少し遅れてフェードインします。Overlay は閉じるとき、パネルより少し遅れて消えます。sparkle-design-cli の `motion-weight` 対応版で生成した CSS が必要です - Modal のアニメーションも、Dialog と同じくモーショントークンで動かすようにしました。パネルは下から出て、中身(Header・Body・Footer)はパネルより少し遅れてフェードインします +- Tooltip のアニメーションをモーショントークン(Small)で動かすようにしました。表示する側に応じてアンカーの側から出て、文字は箱より少し遅れてフェードインします。文字は `data-slot="tooltip-text"` の要素で包むようになりました + +### Fixed + +- Tooltip の拡大の支点がアンカー側にならず、中央から拡大していた不具合を直しました。`origin-[--radix-…]` は Tailwind v4 では有効な CSS にならないため、`origin-(--radix-tooltip-content-transform-origin)` に書き換えました ## [2.0.0-beta.5] - 2026-10-29 diff --git a/src/components/ui/tooltip/index.test.tsx b/src/components/ui/tooltip/index.test.tsx index 4595cabb..939841e4 100644 --- a/src/components/ui/tooltip/index.test.tsx +++ b/src/components/ui/tooltip/index.test.tsx @@ -45,9 +45,11 @@ describe("Tooltip", () => { await userEvent.hover(trigger); const tooltipContents = await screen.findAllByText("Tooltip Content"); - const visibleTooltip = tooltipContents.find( - content => content.getAttribute("data-state") === "delayed-open" - ); + // 文字は tooltip-text に包まれているので、本体(tooltip-content)までさかのぼる + // en: The text is wrapped in tooltip-text, so walk up to the content element + const visibleTooltip = tooltipContents + .map(text => text.closest('[data-slot="tooltip-content"]')) + .find(content => content?.getAttribute("data-state") === "delayed-open"); expect(visibleTooltip).toBeInTheDocument(); }); @@ -66,9 +68,11 @@ describe("Tooltip", () => { // Then: TooltipContentが表示されることを確認する const tooltipContents = await screen.findAllByText("Tooltip Content"); - const visibleTooltip = tooltipContents.find( - content => content.getAttribute("data-state") === "delayed-open" - ); + // 文字は tooltip-text に包まれているので、本体(tooltip-content)までさかのぼる + // en: The text is wrapped in tooltip-text, so walk up to the content element + const visibleTooltip = tooltipContents + .map(text => text.closest('[data-slot="tooltip-content"]')) + .find(content => content?.getAttribute("data-state") === "delayed-open"); expect(visibleTooltip).toBeVisible(); }); @@ -87,9 +91,11 @@ describe("Tooltip", () => { // Then: TooltipContentのdata-side属性がデフォルト値"top"であることを確認する const tooltipContents = await screen.findAllByText("Tooltip Content"); - const visibleTooltip = tooltipContents.find( - content => content.getAttribute("data-state") === "delayed-open" - ); + // 文字は tooltip-text に包まれているので、本体(tooltip-content)までさかのぼる + // en: The text is wrapped in tooltip-text, so walk up to the content element + const visibleTooltip = tooltipContents + .map(text => text.closest('[data-slot="tooltip-content"]')) + .find(content => content?.getAttribute("data-state") === "delayed-open"); expect(visibleTooltip).toHaveAttribute("data-side", "top"); }); @@ -108,9 +114,11 @@ describe("Tooltip", () => { // Then: TooltipContentのdata-side属性が"right"であることを確認する const tooltipContents = await screen.findAllByText("Tooltip Content"); - const visibleTooltip = tooltipContents.find( - content => content.getAttribute("data-state") === "delayed-open" - ); + // 文字は tooltip-text に包まれているので、本体(tooltip-content)までさかのぼる + // en: The text is wrapped in tooltip-text, so walk up to the content element + const visibleTooltip = tooltipContents + .map(text => text.closest('[data-slot="tooltip-content"]')) + .find(content => content?.getAttribute("data-state") === "delayed-open"); expect(visibleTooltip).toHaveAttribute("data-side", "right"); }); @@ -139,4 +147,41 @@ describe("Tooltip", () => { expect(arrowClass).toContain(cls) ); }); + + it("animates with the Small motion tokens from the anchor side", async () => { + // Given: 上に出る Tooltip + testContainer.render( + + Motion + Motion Content + + ); + + // When: ホバーして開く + await userEvent.hover(screen.getByText("Motion")); + await screen.findAllByText("Motion Content"); + const content = document.querySelector( + '[data-slot="tooltip-content"]' + ) as HTMLElement; + + // Then: 箱は Small のトークンで、アンカーの側(下)から出る + // en: The box uses the Small motion tokens and rises from the anchor side + [ + "animate-motion-pop-in-small", + "data-[state=closed]:animate-motion-pop-out-small", + "data-[side=top]:[--motion-pop-from-y:1]", + "origin-(--radix-tooltip-content-transform-origin)", + ].forEach(cls => expect(content.className).toContain(cls)); + expect(content.className).not.toMatch( + /\b(animate-in|animate-out|duration-\d+)\b/ + ); + + // Then: 文字は箱より遅れてフェードインする + // en: The text fades in after the box + const text = content.querySelector( + '[data-slot="tooltip-text"]' + ) as HTMLElement; + expect(text).toHaveTextContent("Motion Content"); + expect(text.className).toContain("animate-motion-content-in-tooltip"); + }); }); diff --git a/src/components/ui/tooltip/index.tsx b/src/components/ui/tooltip/index.tsx index abe46ab2..7e007806 100644 --- a/src/components/ui/tooltip/index.tsx +++ b/src/components/ui/tooltip/index.tsx @@ -99,17 +99,24 @@ function TooltipContent({ side={side} sideOffset={sideOffset} className={cn( - "bg-surface-inverse shadow-float animate-in fade-in-0 zoom-in-95", - "data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95", - "data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2", - "data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2", - "z-50 w-fit origin-[--radix-tooltip-content-transform-origin] rounded-notice", + "bg-surface-inverse shadow-float", + // アンカーの側から出る(Small)。文字は箱より少し遅れて出る + // en: Pops in from the anchor side (Small); the text lags slightly behind the box + "animate-motion-pop-in-small data-[state=closed]:animate-motion-pop-out-small", + "data-[side=top]:[--motion-pop-from-y:1] data-[side=bottom]:[--motion-pop-from-y:-1]", + "data-[side=left]:[--motion-pop-from-x:1] data-[side=right]:[--motion-pop-from-x:-1]", + "z-50 w-fit origin-(--radix-tooltip-content-transform-origin) rounded-notice", "px-2 py-1 character-2-regular-pro text-text-inverse", className )} {...props} > - {children} + + {children} +