url입력 정제 추가

main
김성경 2026-07-22 15:52:45 +09:00
parent 5512d90a9e
commit a853c714fd
1 changed files with 21 additions and 1 deletions

View File

@ -174,6 +174,26 @@ const SearchInputForm: React.FC<SearchInputFormProps> = ({
}
};
// 모바일 키보드 클립보드 추천 등 paste 이벤트 없이 여러 글자가 한 번에 들어오는 경우 처리
const handleChange = (value: string) => {
const isBulkInsert = value.length - inputValue.length > 1;
if (isBulkInsert) {
const extracted = extractUrl(value);
if (extracted && extracted !== value.trim()) {
applyInputChange(sanitizeUrlInput(extracted));
return;
}
if (isUrlLike(value)) {
const sanitized = sanitizeUrlInput(value);
if (sanitized !== value) {
applyInputChange(sanitized);
return;
}
}
}
applyInputChange(value);
};
const handlePaste = (e: React.ClipboardEvent<HTMLInputElement>) => {
const pastedText = e.clipboardData.getData('text');
@ -227,7 +247,7 @@ const SearchInputForm: React.FC<SearchInputFormProps> = ({
<input
type="text"
value={inputValue}
onChange={(e) => applyInputChange(e.target.value)}
onChange={(e) => handleChange(e.target.value)}
onPaste={handlePaste}
onFocus={() => {
setIsFocused(true);