diff --git a/packages/studio/src/components/editor/propertyPanelFlatPrimitives.test.tsx b/packages/studio/src/components/editor/propertyPanelFlatPrimitives.test.tsx index 8b2e2fef5..2eea86d44 100644 --- a/packages/studio/src/components/editor/propertyPanelFlatPrimitives.test.tsx +++ b/packages/studio/src/components/editor/propertyPanelFlatPrimitives.test.tsx @@ -7,6 +7,7 @@ import { FlatGroup, FlatRow, FlatSegmentedRow, + FlatSelectRow, FlatSlider, PinnedZoneDivider, } from "./propertyPanelFlatPrimitives"; @@ -226,3 +227,62 @@ describe("FlatSlider", () => { act(() => root.unmount()); }); }); + +describe("FlatSelectRow", () => { + it("renders the default tier with no reset button", () => { + const { host, root } = renderInto( + , + ); + const select = host.querySelector("select"); + expect(select?.value).toBe("normal"); + expect(host.querySelector('[data-flat-select-reset="true"]')).toBeNull(); + act(() => root.unmount()); + }); + + it("renders the explicitCustom tier with a reset button and fires onReset", () => { + const onReset = vi.fn(); + const { host, root } = renderInto( + , + ); + const select = host.querySelector("select"); + expect(select?.className).toContain("text-panel-accent"); + const reset = host.querySelector('[data-flat-select-reset="true"]'); + act(() => reset?.dispatchEvent(new MouseEvent("click", { bubbles: true }))); + expect(onReset).toHaveBeenCalledTimes(1); + act(() => root.unmount()); + }); + + it("fires onChange when the select value changes", () => { + const onChange = vi.fn(); + const { host, root } = renderInto( + , + ); + const select = host.querySelector("select"); + if (!select) throw new Error("expected a select"); + act(() => { + select.value = "hidden"; + select.dispatchEvent(new Event("change", { bubbles: true })); + }); + expect(onChange).toHaveBeenCalledWith("hidden"); + act(() => root.unmount()); + }); +}); diff --git a/packages/studio/src/components/editor/propertyPanelFlatPrimitives.tsx b/packages/studio/src/components/editor/propertyPanelFlatPrimitives.tsx index a4b69df14..6cc221735 100644 --- a/packages/studio/src/components/editor/propertyPanelFlatPrimitives.tsx +++ b/packages/studio/src/components/editor/propertyPanelFlatPrimitives.tsx @@ -311,3 +311,67 @@ export function FlatSlider({ ); } + +/* ------------------------------------------------------------------ */ +/* FlatSelectRow — label/value row backed by a native onChange(e.target.value)} + className={`appearance-none bg-transparent text-right font-mono text-[11px] outline-none disabled:cursor-not-allowed ${VALUE_TIER_VALUE_CLASS[tier]}`} + > + {options.map((option) => ( + + ))} + + + + + + {tier === "explicitCustom" && onReset && ( + + )} + + + ); +}