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:
@@ -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>
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user