File tree Expand file tree Collapse file tree 1 file changed +10
-3
lines changed
Expand file tree Collapse file tree 1 file changed +10
-3
lines changed Original file line number Diff line number Diff line change 11import styled from 'styled-components' ;
2+ import { useState } from 'react' ;
23
34import { applyFontStyles } from '../../styles/mixins' ;
45import { ColorTypes , FontTypes } from '../../styles/theme' ;
56import XIcon from '../../assets/images/icons/IC_X.svg' ;
67
78function 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 ) => (
You can’t perform that action at this time.
0 commit comments