diff --git a/src/components/image-editor/EditorAgentConversation/EditorAgentDraftTextarea.test.tsx b/src/components/image-editor/EditorAgentConversation/EditorAgentDraftTextarea.test.tsx
index 75f3cf433..dc2a572c2 100644
--- a/src/components/image-editor/EditorAgentConversation/EditorAgentDraftTextarea.test.tsx
+++ b/src/components/image-editor/EditorAgentConversation/EditorAgentDraftTextarea.test.tsx
@@ -18,12 +18,7 @@ describe('EditorAgentDraftTextarea', () => {
vi.stubGlobal('CSS', { supports });
vi.stubGlobal('ResizeObserver', resizeObserver);
- render(
- ,
- );
+ render();
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(() => {
diff --git a/src/components/image-editor/EditorAgentConversation/EditorAgentDraftTextarea.tsx b/src/components/image-editor/EditorAgentConversation/EditorAgentDraftTextarea.tsx
index 80e601846..e2be04ffe 100644
--- a/src/components/image-editor/EditorAgentConversation/EditorAgentDraftTextarea.tsx
+++ b/src/components/image-editor/EditorAgentConversation/EditorAgentDraftTextarea.tsx
@@ -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({