Repository navigation
fix: do not trigger onSelect for already selected values on token split - #1265
mokshupadhyay wants to merge 2 commits into
Conversation
|
@mokshupadhyay is attempting to deploy a commit to the React Component Team on Vercel. A member of the Team first needs to authorize it. |
|
No actionable comments were generated in the recent review. Walkthrough分隔输入生成的值仍会合并并触发变更回调。选择回调现在只针对本次输入中去重后的 token 触发。新增测试验证选择回调和变更回调的值。 Changes分隔输入的选择回调
Estimated code review effort: 2 (Simple) | ~8 minutes Change: Bug fix · Severity of issue fixed: Low Suggested reviewers: Merge Risk:
|
|
Hi @zombieJ, the CI workflows on this PR are waiting for approval to run (first contribution to this repo). Could you approve them when you have a moment, and take a look at the change? Happy to adjust anything. Thanks! |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #1265 +/- ##
=======================================
Coverage 99.46% 99.46%
=======================================
Files 31 31
Lines 1304 1305 +1
Branches 454 477 +23
=======================================
+ Hits 1297 1298 +1
Misses 7 7 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
Could we limit the fix to emitting once per valid token from the current input? That would avoid re-emitting unrelated selected values and preserve the callback for explicitly re-entered tags. |
… values Re-selecting an already selected tag by typing it is still reported, while unrelated selected values are no longer reported again.
|
Thanks, that makes sense. I changed it as you suggested in ddb6018: The tests now cover both sides: the unrelated-values test fails on |
|
Thanks for the update. I need to correct my earlier suggestion: each tokenized selection should fire For example, with |
|
Thanks for taking the time to think it through, and for the correction. With that rule the original behaviour is already right: on |
With
mode="tags"andtokenSeparators, typing or pasting a list callsonSelectfor values that are not part of the input at all:onSelectgets"a","b","2"and"3", althoughaandbwere not typed and were not selected again (onChangereports the right list,['a', 'b', '2', '3']).onInternalSearchSplitrantriggerSelectover the whole merged list ([...rawValues, ...patchValues]). It now runs it once for each unique token of the current input only (patchValues). A token that is typed again, even if it is already selected (for example1in1,2,), still triggersonSelect, in line with how Enter and clicking the same option behave. (This is the narrower behaviour suggested in review; my first version also silenced already selected tokens that were typed.)Tests (
tests/Tags.test.tsx):master(it receives the extra"a"and"b").masterand this branch (it pins the behaviour that is preserved).The full suite (468 tests) and
tscpass;eslinthas no errors andprettier --checkis clean.An AI coding assistant (Claude Code) helped me find and fix this; I reviewed the change and the test.
Summary by CodeRabbit