Skip to content

Commit facdf92

Browse files
committed
feat: tag 등록 후 input 비우기
1 parent 3a01ea9 commit facdf92

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

src/components/UI/Taginput.jsx

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,21 @@
11
import styled from 'styled-components';
2+
import { useState } from 'react';
23

34
import { applyFontStyles } from '../../styles/mixins';
45
import { ColorTypes, FontTypes } from '../../styles/theme';
56
import XIcon from '../../assets/images/icons/IC_X.svg';
67

78
function TagInput({ tags, setTags }) {
9+
const [inputValue, setInputValue] = useState('');
10+
811
const handleTagChange = (e) => {
912
if (e.key === 'Enter') {
10-
const newTag = e.target.value.trim();
11-
if (newTag === '') return;
13+
const trimmed = inputValue.trim();
14+
if (trimmed === '') return;
15+
const newTag = `#${trimmed}`;
1216
if (tags.includes(newTag)) return;
1317
setTags([...tags, newTag]);
18+
setInputValue('');
1419
}
1520
};
1621

@@ -26,7 +31,9 @@ function TagInput({ tags, setTags }) {
2631
id="tag"
2732
type="text"
2833
placeholder="태그를 입력해주세요"
29-
onKeyDown={handleTagChange}
34+
onKeyUp={handleTagChange}
35+
value={inputValue}
36+
onChange={(e) => setInputValue(e.target.value)}
3037
/>
3138
<TagList>
3239
{tags.map((tag) => (

0 commit comments

Comments
 (0)