Skip to content

Commit dd0626a

Browse files
authored
fix(studio): stop the grouping dialog opening off the bottom of the window (#3421)
Reported as "the grouping button did nothing — I clicked it and nothing happened". The dialog WAS opening. It positioned itself at `anchorRect.bottom + 4` with no flip and no clamp, and this button lives in a track header at the bottom of the studio window, so it opened past the viewport edge. It was the last floating surface in the timeline with no viewport handling at all. It now goes through `resolveFloatingPanelPosition`, the helper the other body portals already position with (`RenderQueue`, `propertyPanelColor`), so it flips above the anchor when there is no room below and clamps so neither edge leaves the viewport. `GROUP_DIALOG_SIZE` is a declared estimate in the same style as `FORMAT_PANEL_SIZE` and `COLOR_PICKER_SIZE`: `w-56` is exact, only the flip decision reads the height, and the clamp keeps the dialog on screen either way. Two tests, at a realistic bottom-of-window anchor and hard against the right edge. Both verified to fail against the raw positioning. Worth noting why this shipped: the existing `group-pointer` test passes with or without the fix. happy-dom reports an all-zero rect for an unlaid-out button, so the dialog landed at top:4 — on screen, and nothing like the real app. A geometry test that never sets a geometry proves nothing. Deliberately NOT included: a toast for the grouping write's silent `elements.length < 2` bail. That path is real in code but I could not reach it from the UI — the button only renders on a track with 2+ ungrouped clips, and sub-composition audio arrives as separate single-clip rows, so the offer never appears there. Adding a message for an unreachable branch, plus the file split it would force to stay under the 600-line studio cap, is not justified by evidence.
1 parent f11b608 commit dd0626a

2 files changed

Lines changed: 55 additions & 1 deletion

File tree

‎packages/studio/src/player/components/TimelineFxButton.test.tsx‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,37 @@ describe("TimelineFxButton", () => {
6868
expect(document.querySelector('[role="dialog"]')).toBeTruthy();
6969
});
7070

71+
// The reported symptom was "the grouping button did nothing". The dialog WAS
72+
// opening — it positioned at `anchorRect.bottom + 4` with no flip and no
73+
// clamp, and this button lives in a track header at the bottom of the studio
74+
// window, so it opened past the viewport edge. The test below it passed
75+
// throughout: happy-dom reports an all-zero rect for an unlaid-out button,
76+
// which lands the dialog at top:4 — on screen, and nothing like the app.
77+
it("flips the group dialog above the anchor when there is no room below", () => {
78+
const host = mount(<TimelineFxButton variant="group-pointer" onGroupClips={vi.fn()} />);
79+
const fx = byTextButton(host, "FX");
80+
// A track header near the bottom edge of the (1024x768) window.
81+
fx!.getBoundingClientRect = () =>
82+
({ left: 300, top: 760, right: 320, bottom: 776, width: 20, height: 16 }) as DOMRect;
83+
act(() => fx?.click());
84+
const dialog = document.querySelector('[role="dialog"]') as HTMLElement;
85+
expect(dialog).toBeTruthy();
86+
// Above the anchor, and fully inside the viewport: 644 + 112 === 756.
87+
expect(dialog.style.top).toBe("644px");
88+
});
89+
90+
it("keeps the group dialog inside the right edge of the window", () => {
91+
const host = mount(<TimelineFxButton variant="group-pointer" onGroupClips={vi.fn()} />);
92+
const fx = byTextButton(host, "FX");
93+
// Hard against the right edge: 224px wide + a 12px margin has to fit.
94+
fx!.getBoundingClientRect = () =>
95+
({ left: 1010, top: 100, right: 1024, bottom: 116, width: 14, height: 16 }) as DOMRect;
96+
act(() => fx?.click());
97+
const dialog = document.querySelector('[role="dialog"]') as HTMLElement;
98+
expect(dialog.style.left).toBe("788px");
99+
expect(dialog.style.top).toBe("120px");
100+
});
101+
71102
it("group-pointer variant offers Group instead of a popover", () => {
72103
const onGroupClips = vi.fn();
73104
const host = mount(<TimelineFxButton variant="group-pointer" onGroupClips={onGroupClips} />);

‎packages/studio/src/player/components/TimelineFxButton.tsx‎

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,24 @@ import {
1818
} from "@hyperframes/core/audio-fx";
1919
import type { HfAudioNameKind } from "@hyperframes/core/audio-carve";
2020
import { TimelineFxPopover } from "../../components/editor/TimelineFxPopover.js";
21+
import { resolveFloatingPanelPosition } from "../../components/editor/floatingPanel.js";
22+
23+
// Estimated, like FORMAT_PANEL_SIZE in RenderQueue: `w-56` is exact, and only
24+
// the flip decision uses the height — the clamp keeps the dialog on screen
25+
// either way.
26+
const GROUP_DIALOG_SIZE = { width: 224, height: 112 };
27+
28+
/** Where the grouping dialog goes: flipped above the anchor when there is no
29+
* room below, and clamped so neither edge leaves the viewport. */
30+
function groupDialogPosition(anchorRect: DOMRect): { left: number; top: number } {
31+
const { left, top } = resolveFloatingPanelPosition(
32+
anchorRect,
33+
{ width: window.innerWidth, height: window.innerHeight },
34+
GROUP_DIALOG_SIZE,
35+
{ offset: 4 },
36+
);
37+
return { left, top };
38+
}
2139

2240
function parseFxChainOrEmpty(raw: string | undefined): HfAudioFxChain {
2341
if (!raw) return { version: 1, nodes: [] };
@@ -80,7 +98,12 @@ export function TimelineFxButton(props: TimelineFxButtonProps) {
8098
role="dialog"
8199
aria-label="Group these clips to add effects"
82100
className="z-[200] w-56 rounded-md border border-white/10 bg-[#1b1b1f] p-2.5 text-[11px] text-white/75 shadow-xl"
83-
style={{ position: "fixed", left: anchorRect.left, top: anchorRect.bottom + 4 }}
101+
// Was `top: anchorRect.bottom + 4` with no flip and no clamp. This
102+
// button lives in a track header at the BOTTOM of the studio
103+
// window, so the dialog opened past the viewport edge and the
104+
// click read as doing nothing at all. Same helper the other body
105+
// portals position with.
106+
style={{ position: "fixed", ...groupDialogPosition(anchorRect) }}
84107
onPointerDown={(event) => event.stopPropagation()}
85108
>
86109
<p>Group these clips to add effects to all of them.</p>

0 commit comments

Comments
 (0)