fix(webui): stabilize thread during IME input
This commit is contained in:
@@ -441,6 +441,33 @@ describe("ThreadComposer", () => {
|
||||
expect(input.parentElement?.parentElement?.className).toContain("max-w-[58rem]");
|
||||
});
|
||||
|
||||
it("defers textarea autosizing until IME composition commits", () => {
|
||||
render(
|
||||
<ThreadComposer
|
||||
onSend={vi.fn()}
|
||||
placeholder="Type your message..."
|
||||
/>,
|
||||
);
|
||||
const input = screen.getByLabelText("Message input") as HTMLTextAreaElement;
|
||||
Object.defineProperty(input, "scrollHeight", {
|
||||
configurable: true,
|
||||
value: 120,
|
||||
});
|
||||
input.style.height = "50px";
|
||||
|
||||
fireEvent.input(input, {
|
||||
target: { value: "zhongwen" },
|
||||
isComposing: true,
|
||||
});
|
||||
expect(input.style.height).toBe("50px");
|
||||
|
||||
fireEvent.input(input, {
|
||||
target: { value: "中文" },
|
||||
isComposing: false,
|
||||
});
|
||||
expect(input.style.height).toBe("120px");
|
||||
});
|
||||
|
||||
it("lets long model preset labels use their intrinsic width", () => {
|
||||
render(
|
||||
<ThreadComposer
|
||||
|
||||
@@ -1116,6 +1116,36 @@ describe("ThreadViewport", () => {
|
||||
}
|
||||
});
|
||||
|
||||
it("restores thread scroll after the textarea autosize measurement collapses it", () => {
|
||||
let scroller: HTMLElement | null = null;
|
||||
const { container } = render(
|
||||
<ThreadViewport
|
||||
messages={messages}
|
||||
isStreaming={false}
|
||||
composer={(
|
||||
<textarea
|
||||
aria-label="Message input"
|
||||
onInput={() => {
|
||||
if (scroller) scroller.scrollTop = 692;
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
/>,
|
||||
);
|
||||
scroller = getScroller(container);
|
||||
Object.defineProperty(scroller, "scrollTop", {
|
||||
configurable: true,
|
||||
writable: true,
|
||||
value: 700,
|
||||
});
|
||||
|
||||
fireEvent.input(screen.getByLabelText("Message input"), {
|
||||
target: { value: "中文" },
|
||||
});
|
||||
|
||||
expect(scroller.scrollTop).toBe(700);
|
||||
});
|
||||
|
||||
it("keeps the thread scrollport above a mobile soft keyboard", async () => {
|
||||
const visualViewport = stubVisualViewport({ innerHeight: 800, height: 480 });
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user