Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.
Go
fix(ui): CollapsibleContent keeps focus rings at rest; motion.md lists Wave 2 primitives (MUL-9973) (#11309)
Jiayuan Zhangc29853a79945
diff --git a/AGENTS.md b/AGENTS.mdindex 17dec3d897..f883dc3333 100644--- a/AGENTS.md+++ b/AGENTS.md@@ -119,7 +119,7 @@ Workspace-scoped queries filter by `workspace_id`; membership gates access and `## Web/Desktop UI Rules- For Button and Dialog usage, read `packages/ui/docs/button.md` and `packages/ui/docs/dialog.md`.-- Before building or reviewing an interaction that changes layout (overlays, expand/collapse, list rows, content switches, selection indicators, value feedback), read `packages/ui/docs/motion.md`: tokens, reduced motion, where not to animate, and the shared primitives. Such a PR attaches a GIF and the frame-sampling results from `scripts/motion/capture.mjs`.+- Before building or reviewing an interaction that changes layout (overlays, expand/collapse, list rows, drag and drop, content switches, selection indicators, value feedback), read `packages/ui/docs/motion.md`: tokens, reduced motion, where not to animate, and the shared primitives. Such a PR attaches a GIF and the frame-sampling results from `scripts/motion/capture.mjs`.- Prefer existing shadcn/Base UI primitives. Add components with `pnpm ui:add <component>`.- For `pnpm ui:add @reui/<name>`, decline overwrite prompts. Keep `REUI_LICENSE_KEY` in the environment, never in repo files. Adapt vendored primitives into `packages/ui/components/ui/` and compositions into `packages/views/`.- Import icons from `@multica/ui/icons`; no icon library is installed. If the icon you need is missing, draw it by following `.agents/skills/multica-icons/SKILL.md`. Do not substitute an inline SVG or an emoji. Rewrite icon imports in `ui:add` output before committing. Exception: proportional-width optical keycap glyphs live exclusively in `KBD_GLYPHS` inside `packages/ui/components/ui/kbd.tsx` and are only for `<Kbd>`.diff --git a/packages/ui/components/ui/__tests__/collapsible.test.tsx b/packages/ui/components/ui/__tests__/collapsible.test.tsxnew file mode 100644index 0000000000..b685ddaa5d--- /dev/null+++ b/packages/ui/components/ui/__tests__/collapsible.test.tsx@@ -0,0 +1,38 @@+import { createRef } from "react";+import { cleanup, render, screen, waitFor } from "@testing-library/react";+import { afterEach, describe, expect, it } from "vitest";+import { Collapsible, CollapsibleContent } from "../collapsible";++afterEach(cleanup);++describe("CollapsibleContent", () => {+ it("marks the panel settled only while its height is auto", async () => {+ render(+ <Collapsible open>+ <CollapsibleContent>Row</CollapsibleContent>+ </Collapsible>,+ );+ const panel = screen.getByText("Row");+ expect(panel).toHaveAttribute("data-slot", "collapsible-content");+ expect(panel).toHaveAttribute("data-settled");++ panel.style.setProperty("--collapsible-panel-height", "40px");+ await waitFor(() => expect(panel).not.toHaveAttribute("data-settled"));++ panel.style.setProperty("--collapsible-panel-height", "auto");+ await waitFor(() => expect(panel).toHaveAttribute("data-settled"));+ });++ it("forwards its ref to the panel", () => {+ const ref = createRef<HTMLDivElement>();+ const { rerender } = render(+ <Collapsible open>+ <CollapsibleContent ref={ref}>Row</CollapsibleContent>+ </Collapsible>,+ );+ expect(ref.current).toBe(screen.getByText("Row"));++ rerender(<Collapsible open={false}>{null}</Collapsible>);+ expect(ref.current).toBeNull();+ });+});diff --git a/packages/ui/components/ui/collapsible.tsx b/packages/ui/components/ui/collapsible.tsxindex 38894c08ee..e2845c6e7f 100644--- a/packages/ui/components/ui/collapsible.tsx+++ b/packages/ui/components/ui/collapsible.tsx@@ -1,5 +1,6 @@"use client"+import * as React from "react"import { Collapsible as CollapsiblePrimitive } from "@base-ui/react/collapsible"import { cn } from "@multica/ui/lib/utils"@@ -18,15 +19,50 @@ function CollapsibleTrigger({ ...props }: CollapsiblePrimitive.Trigger.Props) {)}+/**+ * Base UI keeps `--collapsible-panel-height` in px while the panel animates and+ * sets it to `auto` once the panel rests open. `data-settled` mirrors that, so+ * the panel clips only while its height moves and rows' focus rings are not+ * cut off at rest.+ */+function observeSettled(panel: HTMLDivElement) {+ const update = () =>+ panel.toggleAttribute(+ "data-settled",+ panel.style.getPropertyValue("--collapsible-panel-height") === "auto"+ )+ update()+ const observer = new MutationObserver(update)+ observer.observe(panel, { attributes: true, attributeFilter: ["style"] })+ return () => observer.disconnect()+}+function CollapsibleContent({className,+ ref,...props}: CollapsiblePrimitive.Panel.Props) {+ const panelRef = React.useCallback(+ (panel: HTMLDivElement | null) => {+ if (typeof ref === "function") ref(panel)+ else if (ref) ref.current = panel+ if (!panel) return+ const disconnect = observeSettled(panel)+ return () => {+ disconnect()+ if (typeof ref === "function") ref(null)+ else if (ref) ref.current = null+ }+ },+ [ref]+ )return (<CollapsiblePrimitive.Panel+ ref={panelRef}data-slot="collapsible-content"className={cn(- "h-(--collapsible-panel-height) overflow-hidden transition-[height,opacity] duration-[180ms] ease-[cubic-bezier(0.23,1,0.32,1)] data-starting-style:h-0 data-starting-style:opacity-0 data-ending-style:h-0 data-ending-style:opacity-0 motion-reduce:transition-none",+ // `flow-root` keeps child margins inside the panel once it stops clipping.+ "flow-root h-(--collapsible-panel-height) overflow-hidden transition-[height,opacity] duration-[180ms] ease-[cubic-bezier(0.23,1,0.32,1)] data-settled:overflow-visible data-starting-style:h-0 data-starting-style:opacity-0 data-ending-style:h-0 data-ending-style:opacity-0 motion-reduce:transition-none",className)}{...props}diff --git a/packages/ui/docs/motion.md b/packages/ui/docs/motion.mdindex 1dc04aa199..dfb6a1fa95 100644--- a/packages/ui/docs/motion.md+++ b/packages/ui/docs/motion.md@@ -37,7 +37,10 @@ Sections, tree nodes, disclosures, "Show N more", inline hints.- Animate height and opacity together, 150–200ms, `UI_EASE_OUT`. The content below moves with the change; it never jumps.- Rotate one `ChevronRight` by 90° on the same duration. Do not swap two icons.-- Use `CollapsibleContent`. For a conditional block outside a Collapsible, use a `grid-rows-[0fr]` → `grid-rows-[1fr]` transition, as `CreateRunHint` in `packages/views/modals/create-issue.tsx` does, or motion's `height: "auto"`.+- Inside a Base UI `Collapsible`, use `CollapsibleContent`: the issue sidebar sections, chat tool rows, sections in a dialog. `Collapsible` wires the trigger's `aria-expanded` and `aria-controls` to it.+- Where an `open` prop drives the section and there is no `Collapsible`, use `PanelDisclosure`, as the left panels and object pages do: `PanelSection`, the tree rows in `work-tree.tsx` and `views-section.tsx`, the groups in `object-page.tsx`. It makes the exiting content `inert`, and under reduced motion unmounts it in the same frame.+- Both unmount the content once it is closed, so a collapsed list releases its queries; do not pass `keepMounted` or `hiddenUntilFound` to a panel whose content subscribes to data. Both clip only while the height moves: a resting section must not cut off its rows' focus rings.+- For a conditional block with nothing focusable in it, such as an inline hint, use a `grid-rows-[0fr]` → `grid-rows-[1fr]` transition, as `CreateRunHint` in `packages/views/modals/create-issue.tsx` does. Its inner `overflow-hidden` clips at rest too.### List rows added and removed@@ -47,6 +50,14 @@ Archive, complete, snooze, a new notification, a new run.- A row the user just added, or one that arrived live, fades in, with at most 4px of upward movement, 150ms.- Rows on first render and rows a virtual list mounts while scrolling never animate.+### Drag and drop++Moving issues on the board, in the list, and between swimlanes.++- While dragging, the overlay is lifted with `ISSUE_DRAG_OVERLAY_CLASS`: tilted 1°, scaled to 101%, with a shadow. It follows the pointer with no easing.+- On drop, `createIssueDropAnimation` glides the overlay into its new slot and straightens it, 170ms, `UI_EASE_OUT`. The slot stays hidden with `visibility` until the overlay lands; hiding it with `opacity` would set off the slot's own opacity transition and flash it.+- A cancelled drop, an intercepted one (a workflow block or handoff, an archived status, a no-op in a sort-locked view), and any drop under reduced motion skip the glide. Clear the ref you pass to `createIssueDropAnimation` in `onDragStart`, and set it in `onDragEnd` or `onDragCancel` when the move does not land.+### Content switchTabs, views, a filter that changes a list, the next or previous item in a detail pane.@@ -102,7 +113,9 @@ These stay instant:| --- | --- | --- || Durations and curves | `UI_MOTION_DURATION`, `UI_EASE_OUT`, `UI_EASE_IN`, `UI_INDICATOR_SPRING` (selected-state indicators) | `packages/ui/lib/motion.ts` || Overlay enter and exit | The overlay components; Dialog's `--dialog-*` tokens | `packages/ui/components/ui/`, `packages/ui/styles/tokens.css` |-| Expand and collapse | `CollapsibleContent` | `packages/ui/components/ui/collapsible.tsx` |+| Expand and collapse inside a `Collapsible` | `CollapsibleContent` | `packages/ui/components/ui/collapsible.tsx` |+| Expand and collapse driven by an `open` prop (panel sections, tree rows, object page groups) | `PanelDisclosure` | `packages/views/layout/panel-nav.tsx` |+| Issue drag lift and drop settle (board, list, swimlanes) | `ISSUE_DRAG_OVERLAY_CLASS`, `createIssueDropAnimation` | `packages/views/issues/components/drag-drop-animation.ts` || Tabs indicator | `Tabs` | `packages/ui/components/ui/tabs.tsx` || Segmented control indicator | `SegmentedToggle` | `packages/views/common/segmented-toggle.tsx` || Reduced motion for motion/react | `MotionProvider` (mounted at the web and desktop roots) | `packages/views/common/motion-provider.tsx` |@@ -122,6 +135,12 @@ Add a row when you add a primitive, and point the rules above at it.jsdom has no layout, so unit tests cover wiring and the reduced-motion branch, not the animation. A static screenshot cannot show a jump or an overshoot either.+Testing motion/react in jsdom:++- Run tests that wait for an animation with real timers and `waitFor`. Motion's frame loop is shared by the whole test file: when it first starts under `vi.useFakeTimers()`, it stays stuck after `vi.useRealTimers()`, and later animations in that file never finish either. Keep fake timers to the reduced-motion branch, which does not animate.+- A `duration: 0` value reaches the element's style on Motion's next frame, not in the same commit. Wait a frame before asserting it.+- jsdom never applies discrete values from `transitionEnd`, such as `overflow` or `display`. Check those in the real app.+A UI PR whose interaction changes size, position, or what is on screen attaches a GIF of it and the results of a frame-by-frame sample from the real app. `scripts/motion/capture.mjs` does both against a `make up` environment; `scripts/motion/inbox-tabs.mjs` is a complete scenario to copy:```bashdiff --git a/packages/ui/docs/motion.zh.md b/packages/ui/docs/motion.zh.mdindex 5f9f49b3c0..5fdb660f4b 100644--- a/packages/ui/docs/motion.zh.md+++ b/packages/ui/docs/motion.zh.md@@ -37,7 +37,10 @@ Dialog、AlertDialog、Sheet、Popover、DropdownMenu、ContextMenu、Select、H- 高度和透明度一起过渡,150–200ms,`UI_EASE_OUT`。下方内容跟着移动,不跳变。- 用同样的时长把一个 `ChevronRight` 旋转 90°,不要切换两个图标。-- 使用 `CollapsibleContent`。不在 Collapsible 中的条件内容,用 `grid-rows-[0fr]` → `grid-rows-[1fr]` 过渡(参考 `packages/views/modals/create-issue.tsx` 中的 `CreateRunHint`),或 motion 的 `height: "auto"`。+- 在 Base UI 的 `Collapsible` 里,使用 `CollapsibleContent`:Issue 侧栏的各个区块、聊天里的工具调用行、对话框里的区块。`Collapsible` 会把触发按钮的 `aria-expanded` 和 `aria-controls` 关联到它。+- 由 `open` prop 控制、没有 `Collapsible` 的区块,使用 `PanelDisclosure`,左侧面板和对象页都是这样用的:`PanelSection`、`work-tree.tsx` 和 `views-section.tsx` 中的树节点、`object-page.tsx` 中的分组。退场中的内容会设为 `inert`;开启减少动态效果时,同一帧内卸载。+- 两者在收起后都会卸载内容,收起的列表会释放它的查询;内容会订阅数据的面板,不要传 `keepMounted` 或 `hiddenUntilFound`。两者都只在高度变化时裁切:静止的区块不能裁掉行的焦点描边。+- 内部没有可聚焦元素的条件内容(比如行内提示),用 `grid-rows-[0fr]` → `grid-rows-[1fr]` 过渡,参考 `packages/views/modals/create-issue.tsx` 中的 `CreateRunHint`。它内层的 `overflow-hidden` 在静止时也会裁切。### 列表增删行@@ -47,6 +50,14 @@ Dialog、AlertDialog、Sheet、Popover、DropdownMenu、ContextMenu、Select、H- 用户刚添加或实时到达的行淡入,最多向上移动 4px,150ms。- 首次渲染的行,以及虚拟列表滚动时挂载的行,一律不加动效。+### 拖拽++在看板、列表和泳道之间移动 Issue。++- 拖拽过程中,浮层用 `ISSUE_DRAG_OVERLAY_CLASS` 抬起:倾斜 1°,放大到 101%,带阴影。它跟随指针,不加缓动。+- 放下时,`createIssueDropAnimation` 让浮层滑入新位置并摆正,170ms,`UI_EASE_OUT`。浮层落定前,目标位置用 `visibility` 隐藏;用 `opacity` 隐藏会触发该位置自身的透明度过渡,造成闪烁。+- 取消的拖拽、被拦截的拖拽(工作流阻止或交接、归档状态、按排序锁定视图中的无效移动),以及开启减少动态效果时的任何拖拽,都跳过滑入。在 `onDragStart` 中清除传给 `createIssueDropAnimation` 的 ref,移动没有生效时在 `onDragEnd` 或 `onDragCancel` 中设置它。+### 内容切换标签、视图、改变列表的筛选、详情面板的上一项和下一项。@@ -102,7 +113,9 @@ Dialog、AlertDialog、Sheet、Popover、DropdownMenu、ContextMenu、Select、H| --- | --- | --- || 时长和曲线 | `UI_MOTION_DURATION`、`UI_EASE_OUT`、`UI_EASE_IN`、`UI_INDICATOR_SPRING`(选中态指示器) | `packages/ui/lib/motion.ts` || 浮层进退场 | 浮层组件;Dialog 的 `--dialog-*` token | `packages/ui/components/ui/`、`packages/ui/styles/tokens.css` |-| 展开折叠 | `CollapsibleContent` | `packages/ui/components/ui/collapsible.tsx` |+| `Collapsible` 中的展开折叠 | `CollapsibleContent` | `packages/ui/components/ui/collapsible.tsx` |+| 由 `open` prop 控制的展开折叠(面板区块、树节点、对象页分组) | `PanelDisclosure` | `packages/views/layout/panel-nav.tsx` |+| Issue 拖拽抬起和放下落位(看板、列表、泳道) | `ISSUE_DRAG_OVERLAY_CLASS`、`createIssueDropAnimation` | `packages/views/issues/components/drag-drop-animation.ts` || 标签指示器 | `Tabs` | `packages/ui/components/ui/tabs.tsx` || 分段控件指示器 | `SegmentedToggle` | `packages/views/common/segmented-toggle.tsx` || motion/react 的减少动态效果 | `MotionProvider`(挂在 web 和桌面端根部) | `packages/views/common/motion-provider.tsx` |@@ -122,6 +135,12 @@ Dialog、AlertDialog、Sheet、Popover、DropdownMenu、ContextMenu、Select、Hjsdom 没有布局,单元测试只能覆盖接线和减少动态效果的分支,测不了动画本身。静态截图也看不出跳变和冲过头。+在 jsdom 中测试 motion/react:++- 需要等动画结束的测试,用真实计时器配合 `waitFor`。Motion 的帧循环由整个测试文件共享:如果它第一次是在 `vi.useFakeTimers()` 下启动的,切回 `vi.useRealTimers()` 后仍会卡住,这个文件里之后的动画也都不会结束。假计时器只用于减少动态效果的分支,那里没有动画。+- `duration: 0` 的值在 Motion 的下一帧才写到元素的 style 上,不在同一次提交里。断言前先等一帧。+- jsdom 从不应用 `transitionEnd` 中的离散值,比如 `overflow`、`display`。这部分在真实应用里检查。+UI PR 只要包含改变尺寸、位置或显示内容的交互,就附上这段交互的 GIF,以及在真实应用中逐帧采样的结果。`scripts/motion/capture.mjs` 在 `make up` 环境中完成这两件事;`scripts/motion/inbox-tabs.mjs` 是可以照着写的完整场景:```bash