mantinedev / mantine

A fully featured React components library
https://mantine.dev
MIT License
26.26k stars 1.86k forks source link

Deleting element in TagsInput with allowDuplicates=True deletes all duplicate elements #6873

Open ctdunc opened 3 days ago

ctdunc commented 3 days ago

Dependencies check up

What version of @mantine/* packages do you have in package.json?

^7.6.2

What package has an issue?

@mantine/core

What framework do you use?

Other, I will specify in the bug description

In which browsers you can reproduce the issue?

All

Describe the bug

I am using mantine through dash-mantine-components, but have confirmed that this issue also appears on the mantine website.

For example, given a tags input containing items=['a','b','a'], clicking delete on items[2] also deletes items[0].

If possible, include a link to a codesandbox with a minimal reproduction

https://mantine.dev/core/tags-input/#allow-duplicates

Possible fix

Clicking delete on a tag should delete only that tag.

Possibly here https://github.com/mantinedev/mantine/blob/00a94ceefc22c80ad08af73acb943f8f0c01d662/packages/%40mantine/core/src/components/TagsInput/TagsInput.tsx#L339

Maybe something like this? If duplicates aren't allowed, the behavior will be identical. If duplicates are allowed, it will only remove the desired element.

 onRemove={() => {
        let _ = _value.splice(index, 1)
        setValue(_value);
        onRemove?.(item);
      }}

Self-service

ctdunc commented 16 hours ago

If this is expected behavior, ill close this issue. Otherwise happy to submit a fix, just let me know.

Thanks!

rtivital commented 16 hours ago

You are welcome to submit a PR with a fix