Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change TagsInput onRemove to copy correctly #7105

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ctdunc
Copy link
Contributor

@ctdunc ctdunc commented Nov 9, 2024

Alright so my last commit introduced a new bug where controlled TagsInputs would not have any callbacks triggered when clicking the x button in a pill.

This commit fixes that issue. I tested it in dash-mantine-components as well, and the behavior is now correct.

@ctdunc ctdunc force-pushed the fix/tagsinput-controlled-behavior branch from 7e1e69c to 9af1918 Compare November 9, 2024 19:53
@omerchn
Copy link

omerchn commented Nov 10, 2024

We also encountered this issue. thanks for fixing it.
wouldn't this be more performant? (using only filter instead of splice and then splice)

setValue(_value.filter(_item => _item !== item));

@ctdunc
Copy link
Contributor Author

ctdunc commented Nov 10, 2024

We also encountered this issue. thanks for fixing it.
wouldn't this be more performant? (using only filter instead of splice and then splice)

setValue(_value.filter(_item => _item !== item));

No, as this does not work when allowDuplicates is enabled.

The correct solution here is probably toSpliced, but hasnt caught on in terms of browser compatibility

@omerchn
Copy link

omerchn commented Nov 12, 2024

No, as this does not work when allowDuplicates is enabled.

The correct solution here is probably toSpliced, but hasnt caught on in terms of browser compatibility

Got you. What about:

setValue(_value.filter((_, _index) => _index !== index));

Using splice is prone to cause bugs when used in libraries as it mutates the original array, which is something that consumers of libraries don't expect.
I get that using slice() to create a copy of the array fixes this bug, but it seems more like a hack rather than a correct solutaion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants