0
0
mirror of https://github.com/naturalcrit/homebrewery.git synced 2025-12-26 16:02:38 +00:00

Set new tag input to clear itself after submission

Now whenever a new tag is submitted, the input element is cleared and ready for the next tag.

Whitespace cleanup.
This commit is contained in:
Gazook89
2024-09-18 23:39:26 -05:00
parent c1288ce4bb
commit a54adc1e4b

View File

@@ -16,19 +16,17 @@ const TagInput = ({ unique = true, values = [], ...props }) => {
})
};
const handleInputKeyDown = (evt, value) => {
const handleInputKeyDown = (evt, value, clear = false) => {
if (evt.key === 'Enter') {
submitTag(evt.target.value, value);
}
if(clear){ setTemporaryValue(''); }
};
};
const submitTag = (newValue, originalValue, index) => {
setValueContext((prevContext) => {
// remove existing tag
if(newValue === null){
console.log('remove');
return [...prevContext].filter((context, i)=>i !== index);
}
// add new tag
@@ -90,7 +88,7 @@ const TagInput = ({ unique = true, values = [], ...props }) => {
placeholder={props.placeholder}
value={temporaryValue}
onChange={(e) => setTemporaryValue(e.target.value)}
onKeyDown={(evt) => handleInputKeyDown(evt, null)} />
onKeyDown={(evt) => handleInputKeyDown(evt, null, true)} />
</div>
</div>
);