|
9 | 9 | FlatSegmentedRow, |
10 | 10 | FlatSelectRow, |
11 | 11 | FlatSlider, |
12 | | - FlatToggle, |
13 | 12 | } from "./propertyPanelFlatPrimitives"; |
14 | 13 |
|
15 | 14 | (globalThis as unknown as { IS_REACT_ACT_ENVIRONMENT: boolean }).IS_REACT_ACT_ENVIRONMENT = true; |
@@ -822,6 +821,55 @@ describe("FlatSlider — Grade extensions", () => { |
822 | 821 | expect(track.getAttribute("aria-valuenow")).toBe("99"); |
823 | 822 | act(() => root.unmount()); |
824 | 823 | }); |
| 824 | + |
| 825 | + it("resyncs immediately from the latest value on lostpointercapture, even when the value changed WHILE still dragging", () => { |
| 826 | + const { host, root } = renderInto( |
| 827 | + <FlatSlider |
| 828 | + label="Opacity" |
| 829 | + value={10} |
| 830 | + min={0} |
| 831 | + max={100} |
| 832 | + tier="explicitCustom" |
| 833 | + displayValue="10%" |
| 834 | + onCommit={vi.fn()} |
| 835 | + />, |
| 836 | + ); |
| 837 | + const track = host.querySelector<HTMLElement>('[data-flat-slider-track="true"]'); |
| 838 | + if (!track) throw new Error("expected a track element"); |
| 839 | + Object.defineProperty(track, "getBoundingClientRect", { |
| 840 | + value: () => ({ left: 0, width: 100, top: 0, height: 20, right: 100, bottom: 20 }), |
| 841 | + }); |
| 842 | + act(() => { |
| 843 | + track.dispatchEvent( |
| 844 | + new PointerEvent("pointerdown", { bubbles: true, clientX: 30, pointerId: 1 }), |
| 845 | + ); |
| 846 | + }); |
| 847 | + expect(track.getAttribute("aria-valuenow")).toBe("30"); |
| 848 | + // Value changes to 99 WHILE still dragging — the [value] sync effect |
| 849 | + // must skip it (draggingRef is still true), so draft stays at 30. |
| 850 | + act(() => { |
| 851 | + root.render( |
| 852 | + <FlatSlider |
| 853 | + label="Opacity" |
| 854 | + value={99} |
| 855 | + min={0} |
| 856 | + max={100} |
| 857 | + tier="explicitCustom" |
| 858 | + displayValue="99%" |
| 859 | + onCommit={vi.fn()} |
| 860 | + />, |
| 861 | + ); |
| 862 | + }); |
| 863 | + expect(track.getAttribute("aria-valuenow")).toBe("30"); |
| 864 | + act(() => { |
| 865 | + // Capture lost with NO further render afterward — if the resync |
| 866 | + // depended on a subsequent [value] effect run rather than reading |
| 867 | + // latestValueRef directly, this would leave the knob stuck at 30. |
| 868 | + track.dispatchEvent(new Event("lostpointercapture", { bubbles: true })); |
| 869 | + }); |
| 870 | + expect(track.getAttribute("aria-valuenow")).toBe("99"); |
| 871 | + act(() => root.unmount()); |
| 872 | + }); |
825 | 873 | }); |
826 | 874 |
|
827 | 875 | describe("FlatSelectRow", () => { |
@@ -967,44 +1015,3 @@ describe("FlatSelectRow — label/value options", () => { |
967 | 1015 | act(() => root.unmount()); |
968 | 1016 | }); |
969 | 1017 | }); |
970 | | - |
971 | | -describe("FlatToggle", () => { |
972 | | - it("renders the off state with a dim label and dim knob, and fires onChange(true) on click", () => { |
973 | | - const onChange = vi.fn(); |
974 | | - const { host, root } = renderInto( |
975 | | - <FlatToggle label="Loop" checked={false} onChange={onChange} />, |
976 | | - ); |
977 | | - const label = host.querySelector('[data-flat-toggle-label="true"]'); |
978 | | - expect(label?.className).toContain("text-panel-text-3"); |
979 | | - const pill = host.querySelector<HTMLButtonElement>('[data-flat-toggle="true"]'); |
980 | | - expect(pill).not.toBeNull(); |
981 | | - act(() => pill?.dispatchEvent(new MouseEvent("click", { bubbles: true }))); |
982 | | - expect(onChange).toHaveBeenCalledWith(true); |
983 | | - act(() => root.unmount()); |
984 | | - }); |
985 | | - |
986 | | - it("renders the on state with an emphasized label and mint knob, and fires onChange(false) on click", () => { |
987 | | - const onChange = vi.fn(); |
988 | | - const { host, root } = renderInto(<FlatToggle label="Loop" checked onChange={onChange} />); |
989 | | - const label = host.querySelector('[data-flat-toggle-label="true"]'); |
990 | | - expect(label?.className).toContain("text-panel-text-2"); |
991 | | - const knob = host.querySelector('[data-flat-toggle-knob="true"]'); |
992 | | - expect(knob?.className).toContain("bg-panel-accent"); |
993 | | - const pill = host.querySelector<HTMLButtonElement>('[data-flat-toggle="true"]'); |
994 | | - act(() => pill?.dispatchEvent(new MouseEvent("click", { bubbles: true }))); |
995 | | - expect(onChange).toHaveBeenCalledWith(false); |
996 | | - act(() => root.unmount()); |
997 | | - }); |
998 | | - |
999 | | - it("does not fire onChange when disabled", () => { |
1000 | | - const onChange = vi.fn(); |
1001 | | - const { host, root } = renderInto( |
1002 | | - <FlatToggle label="Loop" checked={false} disabled onChange={onChange} />, |
1003 | | - ); |
1004 | | - const pill = host.querySelector<HTMLButtonElement>('[data-flat-toggle="true"]'); |
1005 | | - expect(pill?.disabled).toBe(true); |
1006 | | - act(() => pill?.dispatchEvent(new MouseEvent("click", { bubbles: true }))); |
1007 | | - expect(onChange).not.toHaveBeenCalled(); |
1008 | | - act(() => root.unmount()); |
1009 | | - }); |
1010 | | -}); |
|
0 commit comments