mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2025-12-25 14:02:40 +00:00
Use index to find and remove tags
Fixes issue in last commit, so removing a tag that has duplicate value of other tags only removes the correct one, not the others as well.
This commit is contained in:
@@ -24,12 +24,12 @@ const TagInput = ({ unique = true, values = [], ...props }) => {
|
||||
|
||||
|
||||
|
||||
const submitTag = (newValue, originalValue) => {
|
||||
const submitTag = (newValue, originalValue, index) => {
|
||||
setValueContext((prevContext) => {
|
||||
// remove existing tag
|
||||
if(newValue === null){
|
||||
console.log('remove');
|
||||
return [...prevContext].filter((context)=>context.value !== originalValue);
|
||||
return [...prevContext].filter((context, i)=>i !== index);
|
||||
}
|
||||
// add new tag
|
||||
if(originalValue === null){
|
||||
@@ -63,7 +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>
|
||||
<button onClick={(evt)=>{evt.stopPropagation(); submitTag(null, context.value, index)}}><i className='fa fa-times fa-fw'/></button>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user