fix(webui): keep landscape suggestions beside the composer
This commit is contained in:
1 parent
2e334b2250
commit
fc729df9ab
3 files changed
+73
-10
No files matched your search
@@ -2775,6 +2775,47 @@ describe("ThreadComposer", () => {
|
||||
expect(input).not.toHaveValue(trigger);
|
||||
});
|
||||
|
||||
it.each(["/", "@"]) ("keeps %s selectable beside the input in a short landscape frame", (trigger) => {
|
||||
stubVisualViewport({ height: 128, offsetTop: 208 });
|
||||
let landscape = true;
|
||||
vi.spyOn(HTMLFormElement.prototype, "getBoundingClientRect").mockImplementation(
|
||||
() => rect({ top: landscape ? 44 : 274, width: landscape ? 744 : 388, height: 112 }),
|
||||
);
|
||||
vi.spyOn(HTMLDivElement.prototype, "getBoundingClientRect").mockImplementation(function () {
|
||||
return this.id === "root"
|
||||
? rect({ top: 0, width: landscape ? 776 : 420, height: landscape ? 128 : 396 })
|
||||
: rect({ top: landscape ? 44 : 0, width: landscape ? 776 : 420, height: landscape ? 84 : 396 });
|
||||
});
|
||||
const onSend = vi.fn();
|
||||
render(
|
||||
<div id="root" className="visual-viewport short-visual-viewport" style={{ overflowY: "hidden" }}>
|
||||
<div style={{ overflowY: "auto" }}>
|
||||
<ThreadComposer onSend={onSend} slashCommands={COMMANDS} cliApps={CLI_APPS} />
|
||||
</div>
|
||||
</div>,
|
||||
);
|
||||
const input = screen.getByLabelText("Message input");
|
||||
fireEvent.change(input, { target: { value: trigger, selectionStart: 1 } });
|
||||
const palette = screen.getByRole("listbox");
|
||||
expect(palette).toHaveClass("col-start-2");
|
||||
expect(palette).not.toHaveClass("absolute");
|
||||
expect(palette).toHaveStyle({ maxHeight: "84px" });
|
||||
expect(input.closest("form")).toHaveAttribute("data-palette-beside", "true");
|
||||
|
||||
// Rotation restores the ordinary floating menu, without changing the draft.
|
||||
landscape = false;
|
||||
document.getElementById("root")!.classList.remove("short-visual-viewport");
|
||||
Object.assign(window.visualViewport!, { height: 396, offsetTop: 350 });
|
||||
act(() => window.visualViewport!.dispatchEvent(new Event("resize")));
|
||||
expect(palette).toHaveClass("bottom-full");
|
||||
expect(palette).toHaveStyle({ maxHeight: "266px" });
|
||||
expect(input).toHaveValue(trigger);
|
||||
fireEvent.mouseDown(screen.getAllByRole("option")[0]!);
|
||||
expect(screen.queryByRole("listbox")).not.toBeInTheDocument();
|
||||
expect(input.closest("form")).not.toHaveAttribute("data-palette-beside");
|
||||
expect(onSend).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it.each([false, true])("uses visual bounds outside fitting (pinch zoom: %s)", (zoomed) => {
|
||||
stubVisualViewport({ height: 300, offsetTop: 100 });
|
||||
if (zoomed) Object.assign(window.visualViewport!, { scale: 2 });
|
||||
|
||||
Reference in new issue
Block a user