fix: textarea fallback 高度加入 offsetHeight - clientHeight 的边框差,溢出判断也改用完整 border-box 高度。
Project CI / Backend tests (pull_request) Failing after 11s
Project CI / Repository checks (pull_request) Failing after 12s
Project CI / Frontend tests (pull_request) Successful in 30s
Project CI / Native shell tests (pull_request) Successful in 1m59s

This commit is contained in:
2026-07-23 13:41:12 +08:00
parent c6d98ebd5c
commit 62bbd3876a
2 changed files with 21 additions and 9 deletions
@@ -18,12 +18,7 @@ describe('EditorAgentDraftTextarea', () => {
vi.stubGlobal('CSS', { supports });
vi.stubGlobal('ResizeObserver', resizeObserver);
render(
<EditorAgentDraftTextarea
value=""
onChange={onChange}
/>,
);
render(<EditorAgentDraftTextarea value="" onChange={onChange} />);
const input = screen.getByLabelText(
'发送给画布 Agent',
@@ -65,6 +60,17 @@ describe('EditorAgentDraftTextarea', () => {
) as HTMLTextAreaElement;
expect(observe).toHaveBeenCalledWith(input);
let contentHeight = 92;
Object.defineProperty(input, 'offsetHeight', {
configurable: true,
get: () => {
const styleHeight = Number.parseFloat(input.style.height);
return Number.isNaN(styleHeight) ? 42 : styleHeight;
},
});
Object.defineProperty(input, 'clientHeight', {
configurable: true,
get: () => input.offsetHeight - 2,
});
Object.defineProperty(input, 'scrollHeight', {
configurable: true,
get: () => contentHeight,
@@ -76,8 +82,9 @@ describe('EditorAgentDraftTextarea', () => {
onChange={vi.fn()}
/>,
);
expect(input.style.height).toBe('92px');
expect(input.style.height).toBe('94px');
expect(input.style.overflowY).toBe('hidden');
expect(input.scrollHeight).toBeLessThanOrEqual(input.clientHeight);
contentHeight = 180;
act(() => {
@@ -20,13 +20,18 @@ function supportsNativeFieldSizing() {
function resizeFallbackTextarea(textarea: HTMLTextAreaElement) {
textarea.style.height = 'auto';
const contentHeight = textarea.scrollHeight;
const borderHeight = Math.max(
0,
textarea.offsetHeight - textarea.clientHeight,
);
const borderBoxContentHeight = contentHeight + borderHeight;
const nextHeight = Math.min(
Math.max(contentHeight, DRAFT_MIN_HEIGHT_PX),
Math.max(borderBoxContentHeight, DRAFT_MIN_HEIGHT_PX),
DRAFT_MAX_HEIGHT_PX,
);
textarea.style.height = `${nextHeight}px`;
textarea.style.overflowY =
contentHeight > DRAFT_MAX_HEIGHT_PX ? 'auto' : 'hidden';
borderBoxContentHeight > DRAFT_MAX_HEIGHT_PX ? 'auto' : 'hidden';
}
export function EditorAgentDraftTextarea({