mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2026-11-22 01:26:54 +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:
1 parent
70a3cb9ef9
commit
c65210b3ed
1 file changed
+6
@@ -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