-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3d41a9c
commit 2e7e77c
Showing
5 changed files
with
147 additions
and
102 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
46 changes: 46 additions & 0 deletions
46
src/app/(use-header)/codes/_components/view/SearchSection/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
'use client'; | ||
|
||
import { useAtom } from 'jotai'; | ||
import { type KeyboardEvent, type ChangeEvent, useState } from 'react'; | ||
import styles from './index.module.scss'; | ||
import { searchTagWordsAtom } from '@/stores/postListAtom'; | ||
|
||
export default function SearchSection() { | ||
const [searchWords, setSearchWords] = useAtom(searchTagWordsAtom); | ||
const [value, setValue] = useState(''); | ||
const [isComposing, setIsComposing] = useState(false); | ||
|
||
const onReturnKeyDown = (e: KeyboardEvent<HTMLInputElement>) => { | ||
if (e.key !== 'Enter') return; | ||
if (isComposing) return; | ||
|
||
setSearchWords([...searchWords, value]); | ||
setValue(''); | ||
}; | ||
|
||
const onChange = (e: ChangeEvent<HTMLInputElement>) => { | ||
setValue(e.target.value); | ||
}; | ||
|
||
return ( | ||
<section className={styles.section}> | ||
<p> | ||
{searchWords.map((w) => ( | ||
<span key={w}>{w}</span> | ||
))} | ||
</p> | ||
<input | ||
onChange={onChange} | ||
onCompositionEnd={() => { | ||
setIsComposing(false); | ||
}} | ||
onCompositionStart={() => { | ||
setIsComposing(true); | ||
}} | ||
onKeyDown={onReturnKeyDown} | ||
type="text" | ||
value={value} | ||
/> | ||
</section> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.