mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2025-12-26 00:52:48 +00:00
Add 'remove' button and method
New button that triggers `submitTag()` method directly (rather than throw onKeyDown event) and passes `null` as the newValue. New `if` condition checks for null on newValue and if true, removes the tag that matches the originalValue. This *does* currently delete all duplicate tags if they match the one you are deleting. Not sure when you'd ever want duplicate tags, but regardless i'll likely switch this to work via Index, not value.
This commit is contained in:
@@ -26,6 +26,11 @@ const TagInput = ({ unique = true, values = [], ...props }) => {
|
||||
|
||||
const submitTag = (newValue, originalValue) => {
|
||||
setValueContext((prevContext) => {
|
||||
// remove existing tag
|
||||
if(newValue === null){
|
||||
console.log('remove');
|
||||
return [...prevContext].filter((context)=>context.value !== originalValue);
|
||||
}
|
||||
// add new tag
|
||||
if(originalValue === null){
|
||||
return [...prevContext, { value: newValue, editing: false }]
|
||||
@@ -58,6 +63,7 @@ const TagInput = ({ unique = true, values = [], ...props }) => {
|
||||
className='tag'
|
||||
onClick={() => editTag(context.value)}>
|
||||
{context.value}
|
||||
<button onClick={(evt)=>{evt.stopPropagation(); submitTag(null, context.value)}}><i className='fa fa-times fa-fw'/></button>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user