Skip to content

feat: support tokenize prop for custom multi-tag tokenization#1220

Open
ZQDesigned wants to merge 4 commits intoreact-component:masterfrom
ZQDesigned:master
Open

feat: support tokenize prop for custom multi-tag tokenization#1220
ZQDesigned wants to merge 4 commits intoreact-component:masterfrom
ZQDesigned:master

Conversation

@ZQDesigned
Copy link
Copy Markdown

@ZQDesigned ZQDesigned commented May 7, 2026

Summary

  • Add tokenize?: (input: string) => string[] to BaseSelect and prioritize it over tokenSeparators in token split logic.
  • Keep existing behaviors for IME composition and maxCount, and allow tokenize to opt out of split by returning [input].
  • Add quote-aware demo and test coverage for tags/multiple tokenization behavior.

Related

Test plan

  • npm test -- tests/Tags.test.tsx tests/Multiple.test.tsx

Summary by CodeRabbit

发布说明

  • 新功能

    • 增加可定制的令牌分割(tokenize)支持,允许以自定义逻辑将输入拆分为多个标签/选项,兼容多选与标签模式并尊重最大数量限制。
  • 文档

    • 新增演示页面与示例代码,展示基于引号感知的令牌分割用法与占位提示。
  • 测试

    • 补充多项自动化测试,验证 tokenize 在多选、标签、IME 组合输入和最大数量截断等场景的行为。

Copilot AI review requested due to automatic review settings May 7, 2026 06:23
@vercel
Copy link
Copy Markdown

vercel Bot commented May 7, 2026

@ZQDesigned is attempting to deploy a commit to the React Component Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 7, 2026

Review Change Stack
No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 91d0936c-38a4-4809-a469-26aa7985dde6

📥 Commits

Reviewing files that changed from the base of the PR and between 88c5cc9 and 39ed520.

📒 Files selected for processing (1)
  • src/BaseSelect/index.tsx
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/BaseSelect/index.tsx

演练

此PR为rc-component/select添加了tokenize属性,允许使用自定义分词函数。新属性在BaseSelectProps中定义,通过条件逻辑在搜索处理中应用,支持quote-aware分词,并通过文档示例和五个新测试用例验证功能在multiple和tags模式下的行为。

变更

自定义分词功能

层级 / 文件(s) 总结
类型和公共API
src/BaseSelect/index.tsx
BaseSelectProps新增可选属性tokenize?: (input: string) => string[],用于覆盖tokenSeparators的分词行为,并约定单元素且等于输入表示不分词。
核心实现
src/BaseSelect/index.tsx
BaseSelect组件属性解构中读取tokenize,将其纳入tokenWithEnter的memo依赖;在onInternalSearch中优先使用tokenize(searchText),对单一未变更token判定为“无分词”,否则对结果应用maxCount截断;未提供时回退到getSeparatedContent
文档和示例
docs/demo/custom-tokenize.md, docs/examples/custom-tokenize.tsx
新增文档页面并嵌入示例文件,示例实现了quote-aware的tokenize函数并在mode="tags"的Select中演示使用。
测试覆盖
tests/Multiple.test.tsx, tests/Tags.test.tsx
为multiple模式添加1个测试;为tags模式添加4个测试(覆盖tokenize覆盖分隔符、maxCount限制、IME组合期间跳过、单token不分词等场景)。

预估代码审查工作量

🎯 3 (中等) | ⏱️ ~25 分钟

可能相关的PR

建议的审查者

  • zombieJ

诗歌

🐰 一只兔子的祝贺:
引号围词莫分离,
tokenize 轻盈又细心,
tags 与 multiple 同欢喜,
IME 时刻亦知礼,
兔儿跳跃共庆此。

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed 标题准确概括了本PR的主要变更:为select组件添加tokenize属性以支持自定义多标签分词功能。
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Tip

💬 Introducing Slack Agent: The best way for teams to turn conversations into code.

Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.

  • Generate code and open pull requests
  • Plan features and break down work
  • Investigate incidents and troubleshoot customer tickets together
  • Automate recurring tasks and respond to alerts with triggers
  • Summarize progress and report instantly

Built for teams:

  • Shared memory across your entire org—no repeating context
  • Per-thread sandboxes to safely plan and execute work
  • Governance built-in—scoped access, auditability, and budget controls

One agent for your entire SDLC. Right inside Slack.

👉 Get started


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/BaseSelect/index.tsx`:
- Around line 398-408: When isCompositing is true we must avoid calling
tokenize(searchText) (and also avoid getSeparatedContent) to prevent side
effects; change the logic in the separatedList computation so that the first
branch checks isCompositing and sets separatedList = null when true, otherwise
proceed to call tokenize(searchText) and evaluate isUnchanged, and in the
fallback branch do not call getSeparatedContent when isCompositing is true.
Update the code paths that reference tokenize, getSeparatedContent,
tokenSeparators, cap, searchText and onSearchSplit so composition short-circuits
before any tokenization or split logic runs.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 9be0b77f-b180-42d5-b2bc-4816ac255f7f

📥 Commits

Reviewing files that changed from the base of the PR and between 740b93b and 88c5cc9.

📒 Files selected for processing (5)
  • docs/demo/custom-tokenize.md
  • docs/examples/custom-tokenize.tsx
  • src/BaseSelect/index.tsx
  • tests/Multiple.test.tsx
  • tests/Tags.test.tsx

Comment thread src/BaseSelect/index.tsx Outdated
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a new tokenize prop to BaseSelect to allow custom tokenization logic (taking precedence over tokenSeparators) for tags/multiple modes, along with new demos and tests covering quote-aware splitting, IME composition behavior, and maxCount.

Changes:

  • Introduce tokenize?: (input: string) => string[] in BaseSelect and apply it in the token split path ahead of tokenSeparators.
  • Add tests for custom tokenization behavior in both tags and multiple modes (including composition + maxCount).
  • Add a new demo showcasing quote-aware tokenization.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.

Show a summary per file
File Description
tests/Tags.test.tsx Adds coverage for tokenize precedence, maxCount, composition handling, and opt-out behavior.
tests/Multiple.test.tsx Adds coverage ensuring tokenized inputs in multiple only select matching options.
src/BaseSelect/index.tsx Implements the tokenize prop and integrates it into search split logic.
docs/examples/custom-tokenize.tsx Adds a quote-aware tokenization demo implementation.
docs/demo/custom-tokenize.md Registers the new demo page in dumi.
Comments suppressed due to low confidence (1)

src/BaseSelect/index.tsx:415

  • patchLabels can be null (when composing or when no split is detected), but it is annotated as string[]. This makes the type inaccurate and can break builds that enable strictNullChecks (or make later refactors unsafe). Consider typing it as string[] | null (or removing the explicit annotation and letting inference produce string[] | null).
    // Check if match the `tokenSeparators` or custom `tokenize`
    const patchLabels: string[] = isCompositing ? null : separatedList;

    // Ignore combobox since it's not split-able
    if (mode !== 'combobox' && patchLabels) {
      newSearchText = '';

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a new tokenize prop to the BaseSelect component, allowing for custom tokenization logic that takes precedence over tokenSeparators. The changes include updated logic in BaseSelect/index.tsx to handle this new prop, along with comprehensive test cases in Multiple.test.tsx and Tags.test.tsx to verify the functionality, including quote-aware splitting and composition handling. A review comment was provided suggesting a refactor of the separatedList logic to improve readability, which is a valid improvement opportunity.

Comment thread src/BaseSelect/index.tsx
@ZQDesigned
Copy link
Copy Markdown
Author

ZQDesigned commented May 7, 2026

@zombieJ @afc163 麻烦两位大佬在有空时帮忙做一下人工 review,感谢!

@codecov
Copy link
Copy Markdown

codecov Bot commented May 7, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.44%. Comparing base (740b93b) to head (39ed520).

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #1220   +/-   ##
=======================================
  Coverage   99.44%   99.44%           
=======================================
  Files          31       31           
  Lines        1256     1267   +11     
  Branches      437      444    +7     
=======================================
+ Hits         1249     1260   +11     
  Misses          7        7           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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