Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.
Go
fix(ui): stop tooltips staying on screen after an instant hand-off (MUL-9998) (#11334)
Jiayuan Zhangabdf8a1cb87b
diff --git a/packages/ui/components/ui/__tests__/tooltip.test.tsx b/packages/ui/components/ui/__tests__/tooltip.test.tsxnew file mode 100644index 0000000000..2a5586250e--- /dev/null+++ b/packages/ui/components/ui/__tests__/tooltip.test.tsx@@ -0,0 +1,31 @@+import { cleanup, render, screen } from "@testing-library/react";+import { afterEach, describe, expect, it } from "vitest";+import { Tooltip, TooltipContent, TooltipTrigger } from "../tooltip";++afterEach(cleanup);++// jsdom runs no CSS animations, so these check the popup's classes. In a+// browser, a closing tooltip that turns instant mid-exit stayed on screen when+// the instant rule removed the exit animation (MUL-9998).+describe("TooltipContent", () => {+ function popupClasses() {+ render(+ <Tooltip open>+ <TooltipTrigger>Trigger</TooltipTrigger>+ <TooltipContent>Tip</TooltipContent>+ </Tooltip>,+ );+ const popup = screen.getByText("Tip").closest("[data-slot='tooltip-content']");+ return (popup?.getAttribute("class") ?? "").split(/\s+/);+ }++ it("ends an instant tooltip's animation instead of removing it", () => {+ const classes = popupClasses();+ expect(classes).toContain("data-[instant]:animation-duration-0!");+ expect(classes.filter((c) => c.startsWith("data-[instant]:animate-"))).toEqual([]);+ });++ it("has no CSS transitions for the unmount to wait on", () => {+ expect(popupClasses()).toContain("transition-none");+ });+});diff --git a/packages/ui/components/ui/tooltip.tsx b/packages/ui/components/ui/tooltip.tsxindex 6b6b8d19a0..6406678602 100644--- a/packages/ui/components/ui/tooltip.tsx+++ b/packages/ui/components/ui/tooltip.tsx@@ -88,6 +88,14 @@ function TooltipContent({// page themes. Its own fill and shadow are resolved on the positioner, which// is still in the page theme. A theme's --tooltip-foreground is never// declared by `.dark`, so it reaches the text from either mode.+ //+ // An instant tooltip zeroes its animation's duration instead of removing the+ // animation. The delay group marks a tooltip instant while its exit may still+ // be playing, and Base UI 1.3 unmounts a closing popup only once its+ // animations finish: a removed animation never finishes, so the popup would+ // stay on screen after the pointer has left. `duration-100` would also give+ // every property a transition (scrollbar-color among them) that the unmount+ // waits on, so transitions are off.return (<TooltipPrimitive.Portal><TooltipPrimitive.Positioner@@ -101,7 +109,7 @@ function TooltipContent({<TooltipPrimitive.Popupdata-slot="tooltip-content"className={cn(- "dark z-50 inline-flex w-fit max-w-xs origin-(--transform-origin) items-center gap-1.5 rounded-tooltip bg-(--tooltip-fill) px-2.5 py-1 text-caption text-tooltip-foreground shadow-(--tooltip-elevation) duration-100 ease-[cubic-bezier(0.23,1,0.32,1)] has-data-[slot=kbd]:pr-1.5 data-[side=bottom]:slide-in-from-top-2 data-[side=inline-end]:slide-in-from-left-2 data-[side=inline-start]:slide-in-from-right-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 **:data-[slot=kbd]:relative **:data-[slot=kbd]:isolate **:data-[slot=kbd]:z-50 **:data-[slot=kbd]:rounded-sm data-[state=delayed-open]:animate-in data-[state=delayed-open]:fade-in-0 data-[state=delayed-open]:zoom-in-95 data-open:animate-in data-open:fade-in-0 data-open:zoom-in-95 data-closed:animate-out data-closed:fade-out-0 data-closed:zoom-out-95 data-[instant]:animate-none! motion-reduce:animate-none!",+ "dark z-50 inline-flex w-fit max-w-xs origin-(--transform-origin) items-center gap-1.5 rounded-tooltip bg-(--tooltip-fill) px-2.5 py-1 text-caption text-tooltip-foreground shadow-(--tooltip-elevation) transition-none duration-100 ease-[cubic-bezier(0.23,1,0.32,1)] has-data-[slot=kbd]:pr-1.5 data-[side=bottom]:slide-in-from-top-2 data-[side=inline-end]:slide-in-from-left-2 data-[side=inline-start]:slide-in-from-right-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 **:data-[slot=kbd]:relative **:data-[slot=kbd]:isolate **:data-[slot=kbd]:z-50 **:data-[slot=kbd]:rounded-sm data-[state=delayed-open]:animate-in data-[state=delayed-open]:fade-in-0 data-[state=delayed-open]:zoom-in-95 data-open:animate-in data-open:fade-in-0 data-open:zoom-in-95 data-closed:animate-out data-closed:fade-out-0 data-closed:zoom-out-95 data-[instant]:animation-duration-0! motion-reduce:animate-none!",className)}{...props}diff --git a/packages/ui/docs/motion.md b/packages/ui/docs/motion.mdindex 07b5d2e0a6..82354ca955 100644--- a/packages/ui/docs/motion.md+++ b/packages/ui/docs/motion.md@@ -29,7 +29,7 @@ Dialog, AlertDialog, Sheet, Popover, DropdownMenu, ContextMenu, Select, HoverCar- Use the components in `packages/ui/components/ui/` as they are. Dialog timing lives in the `--dialog-*` tokens (`dialog.md`); do not override an overlay's animation at a call site.- Keep the content mounted until the exit finishes. Do not gate the popup's children with `{open && …}`, and do not unmount the root when it closes. Base UI's Portal unmounts after the exit. A host that renders one modal at a time keeps the last modal and its data until `onOpenChangeComplete(false)`.- Keep the content and its data unchanged during the exit, too. `open` turns false on the exit's first frame: do not pass it to a data hook, a query's `enabled`, or an effect that resets state, or the list empties and the panel shrinks while it fades. Use `open` only to stop input, such as key listeners. The palette in `packages/views/search/search-command.tsx` calls `useRootModel(…, { active: true })` and lets the Portal unmount it after the exit.-- Tooltips that open instantly while the pointer moves across a toolbar skip their animation (`data-[instant]:animate-none`).+- Tooltips that open instantly while the pointer moves across a toolbar skip their animation by zeroing its duration (`data-[instant]:animation-duration-0`). Never remove an exit animation while it plays (`animate-none` on a state that can turn on mid-exit): Base UI then never unmounts the popup, and it stays on screen.### Expand and collapsediff --git a/packages/ui/docs/motion.zh.md b/packages/ui/docs/motion.zh.mdindex 09b5aaa0bf..8237d279a2 100644--- a/packages/ui/docs/motion.zh.md+++ b/packages/ui/docs/motion.zh.md@@ -29,7 +29,7 @@ Dialog、AlertDialog、Sheet、Popover、DropdownMenu、ContextMenu、Select、H- 直接使用 `packages/ui/components/ui/` 中的组件。Dialog 的时长和曲线在 `--dialog-*` token 中(见 `dialog.md`);不要在调用处覆盖浮层动画。- 退场结束前保持内容挂载。不要用 `{open && …}` 包住弹层内容,也不要在关闭时卸载根组件;Base UI 的 Portal 会在退场后卸载。一次只渲染一个弹窗的宿主,要保留上一个弹窗及其数据,直到 `onOpenChangeComplete(false)`。- 退场期间,内容和数据也要保持不变。`open` 在退场第一帧就变为 false:不要把它传给数据 hook、查询的 `enabled` 或会重置状态的 effect,否则列表会被清空,面板在淡出过程中变矮。`open` 只用来停掉输入,比如键盘监听。`packages/views/search/search-command.tsx` 中的命令面板调用 `useRootModel(…, { active: true })`,由 Portal 在退场后卸载它。-- 指针扫过工具栏时立即打开的 Tooltip 跳过动画(`data-[instant]:animate-none`)。+- 指针扫过工具栏时立即打开的 Tooltip 把动画时长归零来跳过动画(`data-[instant]:animation-duration-0`)。不要在退场动画播放中移除它(在可能于退场中途生效的状态上用 `animate-none`):Base UI 会因此永远不卸载弹层,弹层一直留在屏幕上。### 展开折叠