Skip to content

Commit 75b5896

Browse files
committed
Implement height adjustment for textarea on mount
Add useEffect to adjust textarea height on mount Issue : #647
1 parent ce97048 commit 75b5896

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/components/EditorCanvas/Note.jsx

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useMemo, useState, useRef } from "react";
1+
import { useMemo, useState, useRef, useEffect } from "react";
22
import { Action, ObjectType, Tab, State } from "../../data/constants";
33
import { Input, Button, Popover } from "@douyinfe/semi-ui";
44
import ColorPicker from "../EditorSidePanel/ColorPicker";
@@ -179,6 +179,14 @@ export default function Note({ data, onPointerDown }) {
179179
const width = data.width ?? noteWidth;
180180
const MIN_NOTE_WIDTH = 120;
181181

182+
useEffect(() => {
183+
const textarea = document.getElementById(`note_${data.id}`);
184+
textarea.style.height = "0";
185+
textarea.style.height = textarea.scrollHeight + "px";
186+
const newHeight = textarea.scrollHeight + 42;
187+
updateNote(data.id, { height: newHeight });
188+
});
189+
182190
return (
183191
<g
184192
onPointerEnter={(e) => e.isPrimary && setHovered(true)}
@@ -506,4 +514,4 @@ export default function Note({ data, onPointerDown }) {
506514
</foreignObject>
507515
</g>
508516
);
509-
}
517+
}

0 commit comments

Comments
 (0)