Skip to content

Commit 706f67e

Browse files
committed
[#43] ✨ Complete basic functionality for TagInput component
1 parent 5995ce2 commit 706f67e

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import { IcSearch } from '@/assets/IconList'
2+
import { useState } from 'react'
3+
import { Controller, useFormContext } from 'react-hook-form'
4+
5+
import { DeletableChip } from '../chip'
6+
import { TextInput, TextInputProps } from './TextInput'
7+
8+
interface TagInputProps extends Omit<TextInputProps, 'endAdornment'> {
9+
name: string
10+
}
11+
12+
export const TagInput = ({ name, ...props }: TagInputProps) => {
13+
const { control, setValue, getValues } = useFormContext()
14+
const [inputValue, setInputValue] = useState<string>('')
15+
16+
const handleKeyDown = (event: React.KeyboardEvent<HTMLInputElement>) => {}
17+
18+
const handleTagDelete = (id: string) => {}
19+
20+
return (
21+
<div>
22+
<Controller
23+
name={name}
24+
control={control}
25+
render={({ field: { value, onChange } }) => (
26+
<TextInput
27+
value={inputValue}
28+
onChange={e => setInputValue(e.target.value)}
29+
onKeyDown={handleKeyDown}
30+
endAdornment={
31+
<IcSearch width={24} height={24} aria-label='검색 아이콘' />
32+
}
33+
/>
34+
)}
35+
/>
36+
<div className='mt-10 flex flex-wrap gap-2'>
37+
{getValues(name)?.map((tag: { id: string; label: string }) => (
38+
<DeletableChip
39+
key={tag.id}
40+
label={tag.label}
41+
onDelete={() => handleTagDelete(tag.id)}
42+
/>
43+
))}
44+
</div>
45+
</div>
46+
)
47+
}

0 commit comments

Comments
 (0)