Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(ui): preserve label activation after cancelled Switch drag
kirozeng749500365ded
diff --git a/apps/desktop/src/renderer/components/ui/__tests__/switch.test.tsx b/apps/desktop/src/renderer/components/ui/__tests__/switch.test.tsxindex 4e0ef5396b..07499e0657 100644--- a/apps/desktop/src/renderer/components/ui/__tests__/switch.test.tsx+++ b/apps/desktop/src/renderer/components/ui/__tests__/switch.test.tsx@@ -207,6 +207,27 @@ describe('Switch input compatibility', () => {expect((track as HTMLButtonElement).hasPointerCapture(1)).toBe(false);});+ it('does not swallow a later label activation after pointer cancellation', () => {+ const changed = vi.fn();+ render(+ <>+ <label htmlFor="cancelled-switch">Notifications</label>+ <Switch id="cancelled-switch" onCheckedChange={changed} />+ </>,+ );+ const track = prepare(screen.getByRole('switch'));+ fireEvent.pointerDown(track, { clientX: 106 });+ fireEvent.pointerMove(track, { clientX: 130 });+ fireEvent.pointerCancel(track);+ // Browsers do not dispatch click after pointercancel. The next label+ // activation is a separate interaction, with no pointerdown on the Switch.+ const label = screen.getByText('Notifications');+ fireEvent.pointerDown(label);+ fireEvent.pointerUp(label);+ fireEvent.click(label, { detail: 1 });+ expect(changed.mock.calls).toEqual([[true]]);+ });+it('respects consumer event cancellation for pointer gestures and clicks', () => {const changed = vi.fn();const { rerender } = render(diff --git a/apps/desktop/src/renderer/components/ui/switch.tsx b/apps/desktop/src/renderer/components/ui/switch.tsxindex cf893f099d..07cfa945a7 100644--- a/apps/desktop/src/renderer/components/ui/switch.tsx+++ b/apps/desktop/src/renderer/components/ui/switch.tsx@@ -52,11 +52,27 @@ const Switch = React.forwardRef<) => {const thumbRef = React.useRef<HTMLSpanElement>(null);const gesture = React.useRef<Gesture | null>(null);- const suppressPointerClick = React.useRef(false);+ const suppressPointerClick = React.useRef<(() => void) | null>(null);const [hovered, setHovered] = React.useState(false);const [pressed, setPressed] = React.useState(false);const [dragX, setDragX] = React.useState<number | null>(null);+ const clearClickSuppression = () => {+ suppressPointerClick.current?.();+ suppressPointerClick.current = null;+ };+ const suppressGestureClick = (button: HTMLButtonElement) => {+ clearClickSuppression();+ const document = button.ownerDocument;+ // A cancelled gesture may produce no click. A new interaction, including+ // one on an associated label, must always be allowed to activate Radix.+ document.addEventListener('pointerdown', clearClickSuppression, {+ capture: true,+ once: true,+ });+ suppressPointerClick.current = () =>+ document.removeEventListener('pointerdown', clearClickSuppression, true);+ };const releaseCapture = () => {const active = gesture.current;gesture.current = null;@@ -65,7 +81,7 @@ const Switch = React.forwardRef<}};const cancel = () => {- if (gesture.current) suppressPointerClick.current = true;+ if (gesture.current) suppressGestureClick(gesture.current.button);releaseCapture();setPressed(false);setDragX(null);@@ -76,7 +92,13 @@ const Switch = React.forwardRef<setHovered(false);}}, [disabled]);- React.useEffect(() => () => releaseCapture(), []);+ React.useEffect(+ () => () => {+ releaseCapture();+ clearClickSuppression();+ },+ [],+ );const thumbWidth =!disabled && pressed ? PRESS_WIDTH : !disabled && hovered ? HOVER_WIDTH : THUMB_SIZE;@@ -103,7 +125,7 @@ const Switch = React.forwardRef<// Drag release invokes the ordinary Radix click once. Suppress only the// subsequent native pointer click, never keyboard or label activation.if (suppressPointerClick.current && event.detail > 0) {- suppressPointerClick.current = false;+ clearClickSuppression();event.preventDefault();event.stopPropagation();return;@@ -143,7 +165,7 @@ const Switch = React.forwardRef<(thumb.getBoundingClientRect().left - bounds.left) / scale - button.clientLeft,),);- suppressPointerClick.current = false;+ clearClickSuppression();gesture.current = {id: event.pointerId,button,@@ -176,7 +198,7 @@ const Switch = React.forwardRef<setDragX(null);if (event.pointerType !== 'mouse') setHovered(false);if (active.dragging) {- suppressPointerClick.current = true;+ suppressGestureClick(active.button);const next = active.x > active.maxX / 2;if (!event.defaultPrevented &&diff --git a/docs/design-evidence/2026-09-16/cindy-switch-style.md b/docs/design-evidence/2026-09-16/cindy-switch-style.mdindex 08ddfacf16..dc76ce90f2 100644--- a/docs/design-evidence/2026-09-16/cindy-switch-style.md+++ b/docs/design-evidence/2026-09-16/cindy-switch-style.md@@ -69,3 +69,7 @@ Switch 补丁可无冲突应用;本分支仅收录 Switch 代码、主题与- client-ci 静态预检:设计台账、端点、i18n / 品牌 / 术语、Mobile 类型与 scope、migration、scheduler,以及 device-link 编译与集成测试均通过。- 新分支未重启宿主;上方实机证据对应相同 Switch 实现,不能当作新 main/preload 构建的证明。- 可交互确认稿:https://cindy-design-lab.workers.xd.team/#/switch ,这是设计稿,非实机截图。++提交前按用户要求由主 Agent 自查,取消本地双审。自查复现并修复了取消拖动后残留点击抑制+导致下一次关联标签点击失效的问题;新增回归测试,Switch 输入测试共 12 项通过。+该修复只清理交互标记,不改变上方已目检的配色、尺寸和动效;修复后的标签路径通过组件测试验证。