タグの確定時に空白文字を置換する

from 978eccd643
This commit is contained in:
shibafu 2020-08-12 23:06:17 +09:00
parent ae79f0225e
commit 969ddb94a9

View File

@ -24,20 +24,21 @@ const TagInput: React.FC<TagInputProps> = ({ id, name, value, isInvalid }) => {
case 'Enter':
case ' ':
if ((event as any).isComposing !== true) {
setTags(tags.concat(buffer.trim()));
setTags(tags.concat(buffer.trim().replace(/\s+/g, '_')));
setBuffer('');
}
event.preventDefault();
break;
case 'Unidentified':
case 'Unidentified': {
// 実際にテキストボックスに入力されている文字を見に行く (フォールバック処理)
const nativeEvent = event.nativeEvent;
if (nativeEvent.srcElement && (nativeEvent.srcElement as HTMLInputElement).value.slice(-1) == ' ') {
setTags(tags.concat(buffer.trim()));
setTags(tags.concat(buffer.trim().replace(/\s+/g, '_')));
setBuffer('');
event.preventDefault();
}
break;
}
}
} else if (event.key === 'Enter') {
// 誤爆防止