fix(webui): fit session search above the mobile keyboard
This commit is contained in:
1 parent
fc729df9ab
commit
2442d88b91
6 files changed
+38
-21
No files matched your search
+3
-1
@@ -190,7 +190,9 @@ does not proxy pages or bypass those restrictions; use **Open in browser** inste
|
||||
|
||||
On touch devices with Visual Viewport support, the app follows the visible area
|
||||
when the on-screen keyboard opens or pans the page. Navigation and the composer
|
||||
stay in view while messages scroll independently. The `@` mention and `/` command
|
||||
stay in view while messages scroll independently. Session search also follows
|
||||
the visible area: the search field stays above the keyboard and results scroll
|
||||
inside the dialog. The `@` mention and `/` command
|
||||
menus use the visible app area above or below the composer, including when the
|
||||
keyboard pans the page. Scroll within a menu to reach more results. Mention rows
|
||||
use the app's larger touch targets on phones while retaining desktop density.
|
||||
|
||||
@@ -140,7 +140,7 @@ export function SessionSearchDialog({
|
||||
<DialogContent
|
||||
showCloseButton={false}
|
||||
className={cn(
|
||||
"flex max-h-[min(40rem,calc(100vh-2rem))] w-[calc(100vw-2rem)] max-w-[42rem] flex-col gap-0 overflow-hidden p-0",
|
||||
"flex max-h-[min(40rem,100%)] w-[calc(100vw-2rem)] max-w-[42rem] flex-col gap-0 overflow-hidden p-0",
|
||||
)}
|
||||
>
|
||||
<DialogTitle className="sr-only">{t("sidebar.searchAria")}</DialogTitle>
|
||||
|
||||
@@ -41,7 +41,12 @@ const DialogPositionedContent = React.forwardRef<
|
||||
placement?: "center" | "bottom";
|
||||
}
|
||||
>(({ positionerStyle, placement, ...props }, ref) => (
|
||||
<div className={cn("fixed inset-0 z-50 flex justify-center", placement === "bottom" ? "items-end" : "items-center p-4")} style={positionerStyle}>
|
||||
<div className={cn("fixed inset-0 z-50 flex justify-center", placement === "bottom" ? "items-end" : "items-center p-4")} style={{
|
||||
top: "var(--app-viewport-top, 0px)",
|
||||
height: "var(--app-viewport-height, 100%)",
|
||||
bottom: "auto",
|
||||
...positionerStyle,
|
||||
}}>
|
||||
<DialogPrimitive.Content ref={ref} {...props} />
|
||||
</div>
|
||||
));
|
||||
|
||||
@@ -9,15 +9,17 @@ export function useAppViewport() {
|
||||
const viewport = window.visualViewport;
|
||||
const root = document.getElementById("root");
|
||||
if (!touch || !viewport || !root || isNativeRuntime()) return;
|
||||
// Body portals (for example session search) share the app's viewport owner.
|
||||
const viewportStyle = document.documentElement.style;
|
||||
|
||||
const update = () => {
|
||||
// Pinch zoom pans the existing layout; it must not reflow it or chase the
|
||||
// user's magnified viewport. Resume fitting when the scale returns to 1.
|
||||
if (viewport.scale !== 1) return;
|
||||
root.style.setProperty("--app-viewport-height", `${viewport.height}px`);
|
||||
viewportStyle.setProperty("--app-viewport-height", `${viewport.height}px`);
|
||||
// WebKit can report a negative offset after rotating a focused PWA.
|
||||
// Do not move the navigation above the top edge with that overscroll.
|
||||
root.style.setProperty("--app-viewport-top", `${Math.max(0, viewport.offsetTop)}px`);
|
||||
viewportStyle.setProperty("--app-viewport-top", `${Math.max(0, viewport.offsetTop)}px`);
|
||||
root.classList.add("visual-viewport");
|
||||
// Only the keyboard's shortest layouts need a scrollable composer.
|
||||
// Normal layouts must let the command and mention palettes overflow.
|
||||
@@ -31,8 +33,8 @@ export function useAppViewport() {
|
||||
viewport.removeEventListener("scroll", update);
|
||||
root.classList.remove("visual-viewport");
|
||||
root.classList.remove("short-visual-viewport");
|
||||
root.style.removeProperty("--app-viewport-height");
|
||||
root.style.removeProperty("--app-viewport-top");
|
||||
viewportStyle.removeProperty("--app-viewport-height");
|
||||
viewportStyle.removeProperty("--app-viewport-top");
|
||||
};
|
||||
}, [touch]);
|
||||
}
|
||||
@@ -48,6 +48,14 @@ describe("SessionSearchDialog", () => {
|
||||
expect(dialog).toHaveClass("bg-background");
|
||||
expect(dialog.className).not.toContain("bg-popover/");
|
||||
expect(dialog.className).not.toContain("backdrop-blur");
|
||||
// The body portal must share the app's keyboard-fitted frame. Its list
|
||||
// height is bounded by that frame, not by the layout viewport's 100vh.
|
||||
expect(dialog.parentElement).toHaveStyle({
|
||||
top: "var(--app-viewport-top, 0px)",
|
||||
height: "var(--app-viewport-height, 100%)",
|
||||
bottom: "auto",
|
||||
});
|
||||
expect(dialog).toHaveClass("max-h-[min(40rem,100%)]");
|
||||
expect(screen.getByTestId("session-search-scroll")).toHaveClass("overflow-y-auto");
|
||||
expect(screen.queryByText("/model fast")).not.toBeInTheDocument();
|
||||
fireEvent.change(screen.getByRole("textbox", { name: "Search" }), {
|
||||
|
||||
@@ -39,38 +39,38 @@ describe("app visual viewport", () => {
|
||||
input.focus();
|
||||
resize(396, 350);
|
||||
expect(root).toHaveClass("visual-viewport");
|
||||
expect(root.style.getPropertyValue("--app-viewport-height")).toBe("396px");
|
||||
expect(root.style.getPropertyValue("--app-viewport-top")).toBe("350px");
|
||||
expect(document.documentElement.style.getPropertyValue("--app-viewport-height")).toBe("396px");
|
||||
expect(document.documentElement.style.getPropertyValue("--app-viewport-top")).toBe("350px");
|
||||
act(() => {
|
||||
viewport.offsetTop = 320;
|
||||
viewport.dispatchEvent(new Event("scroll"));
|
||||
});
|
||||
expect(root.style.getPropertyValue("--app-viewport-top")).toBe("320px");
|
||||
expect(document.documentElement.style.getPropertyValue("--app-viewport-top")).toBe("320px");
|
||||
expect(document.activeElement).toBe(input);
|
||||
expect(input).toHaveValue("中文草稿");
|
||||
resize(746, 0);
|
||||
expect(root.style.getPropertyValue("--app-viewport-height")).toBe("746px");
|
||||
expect(root.style.getPropertyValue("--app-viewport-top")).toBe("0px");
|
||||
expect(document.documentElement.style.getPropertyValue("--app-viewport-height")).toBe("746px");
|
||||
expect(document.documentElement.style.getPropertyValue("--app-viewport-top")).toBe("0px");
|
||||
});
|
||||
|
||||
it("does not reflow or chase the viewport during pinch zoom, then resumes on reset", () => {
|
||||
render(<AppSurface />, { container: root });
|
||||
resize(373, 120, 2);
|
||||
expect(root.style.getPropertyValue("--app-viewport-height")).toBe("746px");
|
||||
expect(root.style.getPropertyValue("--app-viewport-top")).toBe("0px");
|
||||
expect(document.documentElement.style.getPropertyValue("--app-viewport-height")).toBe("746px");
|
||||
expect(document.documentElement.style.getPropertyValue("--app-viewport-top")).toBe("0px");
|
||||
resize(320, 0);
|
||||
expect(root.style.getPropertyValue("--app-viewport-height")).toBe("320px");
|
||||
expect(document.documentElement.style.getPropertyValue("--app-viewport-height")).toBe("320px");
|
||||
});
|
||||
|
||||
it("keeps navigation below the top edge when a focused PWA rotates with negative WebKit overscroll", () => {
|
||||
render(<AppSurface />, { container: root });
|
||||
resize(128, -68);
|
||||
expect(root).toHaveClass("short-visual-viewport");
|
||||
expect(root.style.getPropertyValue("--app-viewport-height")).toBe("128px");
|
||||
expect(root.style.getPropertyValue("--app-viewport-top")).toBe("0px");
|
||||
expect(document.documentElement.style.getPropertyValue("--app-viewport-height")).toBe("128px");
|
||||
expect(document.documentElement.style.getPropertyValue("--app-viewport-top")).toBe("0px");
|
||||
resize(428, 416);
|
||||
expect(root).not.toHaveClass("short-visual-viewport");
|
||||
expect(root.style.getPropertyValue("--app-viewport-top")).toBe("416px");
|
||||
expect(document.documentElement.style.getPropertyValue("--app-viewport-top")).toBe("416px");
|
||||
});
|
||||
|
||||
it.each(["desktop", "native", "unsupported"])("leaves %s layout ownership unchanged", (kind) => {
|
||||
@@ -80,7 +80,7 @@ describe("app visual viewport", () => {
|
||||
render(<AppSurface />, { container: root });
|
||||
resize(396, 350);
|
||||
expect(root).not.toHaveClass("visual-viewport");
|
||||
expect(root.style.getPropertyValue("--app-viewport-height")).toBe("");
|
||||
expect(document.documentElement.style.getPropertyValue("--app-viewport-height")).toBe("");
|
||||
});
|
||||
|
||||
it("releases listeners and owned styles when touch layout is disabled or the app unmounts", () => {
|
||||
@@ -89,7 +89,7 @@ describe("app visual viewport", () => {
|
||||
rerender(<AppSurface />);
|
||||
resize(396, 350);
|
||||
expect(root).not.toHaveClass("visual-viewport");
|
||||
expect(root.style.getPropertyValue("--app-viewport-height")).toBe("");
|
||||
expect(document.documentElement.style.getPropertyValue("--app-viewport-height")).toBe("");
|
||||
touch = true;
|
||||
rerender(<AppSurface />);
|
||||
expect(root).toHaveClass("visual-viewport");
|
||||
@@ -97,6 +97,6 @@ describe("app visual viewport", () => {
|
||||
resize(746, 0);
|
||||
expect(root).not.toHaveClass("visual-viewport");
|
||||
expect(root).not.toHaveClass("short-visual-viewport");
|
||||
expect(root.style.getPropertyValue("--app-viewport-top")).toBe("");
|
||||
expect(document.documentElement.style.getPropertyValue("--app-viewport-top")).toBe("");
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user