@devries-cameron20 / t3code Mirror · read-only / commits / e71f414cb0
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 22, 08:15 UTC

fix(web): Esc in the theme color picker restores the previous color (#27472)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>

Einar Andersson committed Nov 1, 2026 at 03:38 UTC e71f414cb0d934fbc66c55b9497d2cc9e6b5feb0
3 files changed +93 -6
apps/web/src/components/settings/ThemeColorPicker.tsx
+25 -4
@@ -1,4 +1,4 @@
1 -import { memo, useEffect, useState } from "react";
1 +import { memo, useEffect, useRef, useState } from "react";
2 import { isThemeColor, themeColorToHex, type ThemeColorRole } from "../../themePalette";
3 import { cn } from "../../lib/utils";
4 import { hexToHsv, hsvToHex, type HsvColor } from "../../lib/color";
@@ -240,21 +240,34 @@ function ThemeColorPicker({
240 label,
241 value,
242 onChange,
243 + onEditStart,
244 + onEditCancel,
245 onInteract,
246 }: {
247 label: string;
248 value: string;
249 onChange: (value: string) => void;
250 + onEditStart?: () => void;
251 + onEditCancel?: () => void;
252 onInteract?: () => void;
253 }) {
254 const [committer] = useState(createFrameCommitter);
255 + // Escape reverts the edit, so commits after it (the pending frame flushed on close, or a drag
256 + // still firing through the exit animation) are dropped instead of landing on the restored colors.
257 + const cancelledRef = useRef(false);
258 // Unmounting with the popover open (the editor closes mid-drag) never fires onOpenChange.
259 // oxlint-disable-next-line t3code/no-unreasoned-state-sync -- flushes the frame committer on unmount, since an open popover never fires onOpenChange
260 useEffect(() => committer.flush, [committer]);
261 return (
262 <Popover
256 - onOpenChange={(open) => {
257 - if (!open) committer.flush();
263 + onOpenChange={(open, eventDetails) => {
264 + cancelledRef.current = !open && eventDetails.reason === "escape-key";
265 + if (open) {
266 + onEditStart?.();
267 + return;
268 + }
269 + committer.flush();
270 + if (cancelledRef.current) onEditCancel?.();
271 }}
272 >
273 <Tooltip>
@@ -290,7 +303,9 @@ function ThemeColorPicker({
303 <ThemeColorPickerPanel
304 committer={committer}
305 label={label}
293 - onChange={onChange}
306 + onChange={(nextValue) => {
307 + if (!cancelledRef.current) onChange(nextValue);
308 + }}
309 value={value}
310 />
311 </PopoverPopup>
@@ -302,6 +317,8 @@ export const ThemeColorField = memo(function ThemeColorField({
317 role,
318 value,
319 onChange,
320 + onEditStart,
321 + onEditCancel,
322 onSelect,
323 onToggleSelected,
324 selected = false,
@@ -310,6 +327,8 @@ export const ThemeColorField = memo(function ThemeColorField({
327 role: ThemeColorRole;
328 value: string;
329 onChange: (role: ThemeColorRole, value: string) => void;
330 + onEditStart?: (role: ThemeColorRole) => void;
331 + onEditCancel?: (role: ThemeColorRole) => void;
332 onSelect?: (role: ThemeColorRole) => void;
333 onToggleSelected?: (role: ThemeColorRole) => void;
334 selected?: boolean;
@@ -350,6 +369,8 @@ export const ThemeColorField = memo(function ThemeColorField({
369 <ThemeColorPicker
370 label={label}
371 onChange={(nextValue) => onChange(role, nextValue)}
372 + onEditCancel={() => onEditCancel?.(role)}
373 + onEditStart={() => onEditStart?.(role)}
374 onInteract={() => onSelect?.(role)}
375 value={swatchValue}
376 />
apps/web/src/components/settings/ThemeEditorPanel.browser.test.tsx
+40 -2
@@ -1,7 +1,7 @@
1 import { describe, expect, it, vi } from "vite-plus/test";
2 -import { page } from "vite-plus/test/browser";
2 +import { page, userEvent } from "vite-plus/test/browser";
3
4 -import { render } from "../../../test/render";
4 +import { act, render } from "../../../test/render";
5 import { ThemeEditorPanel } from "./ThemeEditorPanel";
6
7 function dragHeader(panel: HTMLElement, toX: number, toY: number) {
@@ -32,6 +32,19 @@ function dragResizeHandle(panel: HTMLElement, byX: number) {
32 handle.dispatchEvent(new PointerEvent("pointerup", init));
33 }
34
35 +function pointerAt(target: HTMLElement, type: string, xFraction: number) {
36 + const rect = target.getBoundingClientRect();
37 + target.dispatchEvent(
38 + new PointerEvent(type, {
39 + bubbles: true,
40 + button: 0,
41 + pointerId: 3,
42 + clientX: rect.left + rect.width * xFraction,
43 + clientY: rect.top + rect.height / 2,
44 + }),
45 + );
46 +}
47 +
48 async function renderPanel() {
49 await page.viewport(1280, 900);
50 const stack = new AsyncDisposableStack();
@@ -110,4 +123,29 @@ describe("ThemeEditorPanel", () => {
123 await page.viewport(1280, 900);
124 await expect.poll(() => (panel.element() as HTMLElement).style.left).toBe("700px");
125 });
126 +
127 + it("restores the colors from before the picker opened when Escape closes it", async () => {
128 + await using _view = await renderPanel();
129 + const hex = page.getByRole("textbox", { name: "Accent hex value" });
130 + const original = (hex.element() as HTMLInputElement).value;
131 + await userEvent.click(page.getByRole("button", { name: "Choose Accent color" }));
132 + const hue = page.getByRole("slider", { name: "Accent hue" });
133 + await expect.element(hue).toBeInTheDocument();
134 + const hueSlider = hue.element() as HTMLElement;
135 +
136 + await act(async () => {
137 + pointerAt(hueSlider, "pointerdown", 0.5);
138 + pointerAt(hueSlider, "pointerup", 0.5);
139 + });
140 + await expect.element(hex).not.toHaveValue(original);
141 +
142 + await act(async () => {
143 + pointerAt(hueSlider, "pointerdown", 0.25);
144 + hueSlider.dispatchEvent(new KeyboardEvent("keydown", { bubbles: true, key: "Escape" }));
145 + // The drag keeps going while the picker animates out.
146 + pointerAt(hueSlider, "pointermove", 0.75);
147 + pointerAt(hueSlider, "pointerup", 0.75);
148 + });
149 + expect((hex.element() as HTMLInputElement).value).toBe(original);
150 + });
151 });
apps/web/src/components/settings/ThemeEditorPanel.tsx
+28
@@ -354,6 +354,11 @@ export function ThemeEditorPanel({
354 const [position, setPosition] = useState<{ x: number; y: number; width: number } | null>(null);
355 const [size, setSize] = useState<{ width: number; height: number } | null>(null);
356 const panelRef = useRef<HTMLDivElement>(null);
357 + const colorEditSnapshotRef = useRef<{
358 + colorsByAppearance: ThemeEditorColorsByAppearance;
359 + simpleColorsDirtyByAppearance: Record<ThemeAppearance, boolean>;
360 + shouldRegenerateGuidedColors: boolean;
361 + } | null>(null);
362 const dragOffsetRef = useRef<{ dx: number; dy: number; width: number } | null>(null);
363 const resizeStartRef = useRef<{
364 pointerX: number;
@@ -472,6 +477,25 @@ export function ThemeEditorPanel({
477 if (isAdvanced) setShouldRegenerateGuidedColors(true);
478 };
479
480 + // A color edit also rewrites derived roles, so cancelling restores the whole snapshot rather than
481 + // replaying the previous value through updateColor.
482 + const startColorEdit = () => {
483 + colorEditSnapshotRef.current = {
484 + colorsByAppearance,
485 + simpleColorsDirtyByAppearance,
486 + shouldRegenerateGuidedColors,
487 + };
488 + };
489 +
490 + const cancelColorEdit = () => {
491 + const snapshot = colorEditSnapshotRef.current;
492 + colorEditSnapshotRef.current = null;
493 + if (!snapshot) return;
494 + setColorsByAppearance(snapshot.colorsByAppearance);
495 + setSimpleColorsDirtyByAppearance(snapshot.simpleColorsDirtyByAppearance);
496 + setShouldRegenerateGuidedColors(snapshot.shouldRegenerateGuidedColors);
497 + };
498 +
499 const selectThemeRole = (role: ThemeColorRole, reveal = false) => {
500 const visibleRole = getThemeEditorColorFamily(role)?.role ?? role;
501 setSelectedRole(visibleRole);
@@ -947,6 +971,8 @@ export function ThemeEditorPanel({
971 key={family.id}
972 label={family.label}
973 onChange={updateColor}
974 + onEditCancel={cancelColorEdit}
975 + onEditStart={startColorEdit}
976 onSelect={selectThemeRole}
977 onToggleSelected={toggleThemeRole}
978 role={family.role}
@@ -986,6 +1012,8 @@ export function ThemeEditorPanel({
1012 <ThemeColorField
1013 key={role}
1014 onChange={updateColor}
1015 + onEditCancel={cancelColorEdit}
1016 + onEditStart={startColorEdit}
1017 onSelect={selectThemeRole}
1018 onToggleSelected={toggleThemeRole}
1019 role={role}