Skip to content

Commit 7271b72

Browse files
authored
Merge pull request #248 from boostcampwm-2024/feature-input-fe
[Feature-input-fe] input ν™œμ„±ν™” μ‹œ μš”μ†Œ 전체선택 ( μˆ˜μ • λ°”λ‘œ ν•  수 μžˆλ„λ‘ )
2 parents 7b2dece + 791ee9e commit 7271b72

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-1
lines changed

β€Žclient/src/components/MindMapHeader/index.tsxβ€Ž

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,25 @@ import Profile from "@/components/MindMapHeader/Profile";
33
import { useNodeListContext } from "@/store/NodeListProvider";
44
import { useConnectionStore } from "@/store/useConnectionStore";
55
import { Input } from "@headlessui/react";
6-
import { useState } from "react";
6+
import { useEffect, useRef, useState } from "react";
77
import { FaPencilAlt } from "react-icons/fa";
88

99
export default function MindMapHeader() {
1010
const { title, updateTitle } = useNodeListContext();
1111
const originalContent = title;
12+
const inputRef = useRef<HTMLInputElement | null>(null);
1213
const [editMode, setEditMode] = useState(false);
1314
const handleSocketEvent = useConnectionStore((state) => state.handleSocketEvent);
1415
const role = useConnectionStore((state) => state.currentRole);
1516
const currentJobStatus = useConnectionStore((state) => state.currentJobStatus);
1617

18+
useEffect(() => {
19+
if (editMode && inputRef.current) {
20+
inputRef.current.focus();
21+
inputRef.current.select();
22+
}
23+
}, [editMode]);
24+
1725
function handleInputBlur() {
1826
if (!title.length) {
1927
setEditMode(false);
@@ -48,6 +56,7 @@ export default function MindMapHeader() {
4856
<MindMapHeaderButtons />
4957
{editMode ? (
5058
<Input
59+
ref={inputRef}
5160
className="flex w-80 items-center bg-transparent text-center"
5261
value={title}
5362
onChange={(e) => updateTitle(e.target.value)}

β€Žclient/src/components/MindMapMainSection/ControlSection/ListView/NodeItem.tsxβ€Ž

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,13 @@ export default function NodeItem({ node, parentNodeId, open, handleAccordion, op
4747
if (isSelected) openAccordion();
4848
}, [isSelected]);
4949

50+
useEffect(() => {
51+
if (isEditing && inputRef.current) {
52+
inputRef.current.focus();
53+
inputRef.current.select();
54+
}
55+
}, [isEditing]);
56+
5057
function handleAddButton() {
5158
selectNode({ nodeId: node.id, parentNodeId: parentNodeId });
5259
addNode(data, { nodeId: node.id, parentNodeId: parentNodeId }, overrideNodeData, (newNodeId) => {

β€Žclient/src/konva_mindmap/components/EditableTextInput.tsxβ€Ž

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { useEffect, useRef } from "react";
12
import { Html } from "react-konva-utils";
23

34
interface EditableTextInputProps {
@@ -23,11 +24,19 @@ export default function EditableTextInput({
2324
focus,
2425
scale,
2526
}: EditableTextInputProps) {
27+
const inputRef = useRef<HTMLInputElement | null>(null);
2628
const fontSize = scale >= 1 ? 16 : 16 / scale;
2729

30+
useEffect(() => {
31+
if (inputRef.current && focus) {
32+
inputRef.current.select();
33+
}
34+
}, [focus]);
35+
2836
return (
2937
<Html groupProps={{ offset: { x: offsetX, y: offsetY } }}>
3038
<input
39+
ref={inputRef}
3140
autoFocus={focus}
3241
value={value}
3342
onChange={onChange}

0 commit comments

Comments
Β (0)