Skip to content

Commit

Permalink
fix:배포 시 edit창 inpu두번 입력 에러
Browse files Browse the repository at this point in the history
  • Loading branch information
jongse7 committed Oct 16, 2024
1 parent 68152a7 commit 6dcbd6d
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions src/pages/notice/noticeEdit/container/noticeEditTitleSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,27 @@ export function NoticeEditTitleSection({
}: NoticeEditTitleSectionProps) {
const [title, setTitle] = useState<string>(initialTitle);
const [isUrgent, setIsUrgent] = useState<boolean>(false);
const [isComposing, setIsComposing] = useState<boolean>(false);

const handleTitleChange = (event: React.ChangeEvent<HTMLInputElement>) => {
const newTitle = event.target.value;
if (newTitle.length <= 50) {
setTitle(newTitle);
onTitleChange(newTitle);
if (!isComposing) {
const newTitle = event.target.value;
if (newTitle.length <= 50) {
setTitle(newTitle);
onTitleChange(newTitle);
}
}
};

const handleCompositionStart = () => {
setIsComposing(true);
};

const handleCompositionEnd = (event: React.CompositionEvent<HTMLInputElement>) => {
setIsComposing(false);
handleTitleChange(event as unknown as React.ChangeEvent<HTMLInputElement>); // composition 끝난 후 onChange 처리
};

const handleCheckboxChange = (event: React.ChangeEvent<HTMLInputElement>) => {
const newValue = event.target.checked;
setIsUrgent(newValue);
Expand All @@ -38,6 +50,8 @@ export function NoticeEditTitleSection({
id="title"
value={title}
onChange={handleTitleChange}
onCompositionStart={handleCompositionStart}
onCompositionEnd={handleCompositionEnd}
className="w-full flex-1 rounded-xs border-[0.125rem] border-gray-300 px-3 py-[0.4rem] shadow-sm focus:border-blue-500 focus:outline-none focus:ring-1 focus:ring-blue-500 sm:text-sm"
placeholder="제목을 입력하세요"
/>
Expand Down

0 comments on commit 6dcbd6d

Please sign in to comment.