Skip to content

fix: preserve Input.OTP digits when pasting formatted text - #59580

Merged
zombieJ merged 1 commit into
ant-design:masterfrom
yunfeizhu:fix/input-otp-filtered-paste
Oct 15, 2026
Merged

zombieJ merged 1 commit into
ant-design:masterfrom
yunfeizhu:fix/input-otp-filtered-paste

Conversation

@yunfeizhu

Copy link
Copy Markdown
Contributor

中文版模板 / Chinese template

🤔 This is a ...

  • 🆕 New feature
  • 🐞 Bug fix
  • 📝 Site / documentation improvement
  • 📽️ Demo improvement
  • 💄 Component style improvement
  • 🤖 TypeScript definition improvement
  • 📦 Bundle size optimization
  • ⚡️ Performance optimization
  • ⭐️ Feature enhancement
  • 🌐 Internationalization
  • 🛠 Refactoring
  • 🎨 Code style optimization
  • ✅ Test Case
  • 🔀 Branch merge
  • ⏩ Workflow
  • ⌨️ Accessibility improvement
  • ❓ Other (about what?)

🔗 Related Issues

Fixes #59579

Minimal reproduction on StackBlitz · Standalone source

The reproduction uses published [email protected] and intentionally shows the bug. Run npm install and npm run dev if the online preview is unavailable.

💡 Background and Solution

When a six-cell Input.OTP uses a formatter that removes non-digits, pasting 123 456 produces only 12345. The raw input is truncated before formatting, so the separator consumes a slot and the final digit is discarded. Pasting 1 2 3 4 5 6 loses even more digits.

Apply the existing formatter before limiting the resulting cells to length. This preserves valid characters and keeps the final cell count bounded. The existing focus handling and callback flow remain in place; there is no public API change.

Regression tests cover spaces and hyphens, multiple separators, pasting into a middle cell, callback values, focus, and the final length limit. The PR is limited to the OTP implementation and its existing test file. The repository's pre-commit formatter also wrapped one existing separator assertion without changing it.

Screenshots

The same six-cell example after inserting 123 456: before uses published [email protected]; after uses this branch's source.

Before After
Before: the last digit is lost and onChange is not called After: all six digits are preserved and onChange receives 123456

Narrow viewport: before / after.

Verification

  • OTP suite: 36 tests and 1 snapshot passed. With the new tests applied to the unchanged base implementation, 5 cases fail; all pass with this fix.
  • Browser checks at 1000 px and 390 px: 56 before/after scenarios passed, checking values, callbacks, focus, length limits, reset, typing/deletion, controlled input, masking, RTL, and horizontal overflow. Multi-character insertion uses CDP Input.insertText, not the OS clipboard.
  • The standalone published-package demo builds successfully. Eight additional browser scenarios confirm the reported failures, the unseparated control case, and reset at both widths.
  • ESLint, Biome, repository pre-commit hooks, and git diff --check passed.
  • A simulated merge with current feature (fcfd9e5414b6251894111874c424fc5abf2aa388) completed without conflicts; this PR targets master.

Broader checks have existing failures, reproduced against the unchanged base (05140c7f82c3c776bb7ed61272a070f9db403fc5):

  • Full Input suite: 289 passed, 2 skipped, and 3 snapshot failures in the compact-style, align, and addon extended-context demos. The same three failures occur on the base.
  • Full-repository TypeScript checking reports the same 3 diagnostics with either the base or fixed OTP source/tests; no additional diagnostics were introduced.

Those unrelated failures and snapshots are left unchanged. Browser production bundles were built; a full package build was not run.

📝 Change Log

Language Changelog
🇺🇸 English 🐞 Fix Input.OTP dropping valid characters when pasting text with a filtering formatter.
🇨🇳 Chinese 🐞 修复 Input.OTP 使用过滤格式化函数时粘贴文本会丢失有效字符的问题。

@bolt-new-by-stackblitz

Copy link
Copy Markdown

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

@github-actions

github-actions Bot commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

👁 Visual Regression Report for PR #59580 Passed ✅

🎯 Target branch: master (8d56c3e)
⚠️ Baseline may be stale: no snapshot for the PR's base commit was found, so an older branch snapshot was used. Some diffs below may come from changes already merged into master rather than this PR.
📖 View Full Report ↗︎
📖 Alternative Report ↗︎

🎊 Congrats! No visual-regression diff found.

📖 中文报告

👁 PR #59580 视觉回归报告 通过 ✅

🎯 目标分支: master (8d56c3e)
⚠️ 基线可能已过期: 未找到该 PR 基准提交对应的快照,因此回退使用了较旧的分支快照。下方部分差异可能来自已合并到 master 的改动,而非本 PR。

🎊 恭喜!未发现视觉回归差异。

@github-actions

github-actions Bot commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

Preview is ready

@coderabbitai

coderabbitai Bot commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 54cb7b7d-a332-40cb-993d-ac905fe9b3e1
📥 Commits

Reviewing files that changed from the base of the PR and between 05140c7 and 257ebed.

📒 Files selected for processing: 2
  • components/input/OTP/index.tsx
  • components/input/__tests__/otp.test.tsx

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

📝 Summary

Summary by CodeRabbit

  • Bug 修复
    • 修复 OTP 粘贴处理:先格式化完整输入,再按 OTP 长度截断,避免有效字符丢失。
    • 从中间单元格粘贴时保留前置值,并确保输入、变更回调及焦点位置符合预期。

OTP.patchValue 现在先格式化完整候选值,再按 OTP 长度截断。新增测试覆盖分隔符过滤、中间单元格粘贴、回调、焦点位置和长度限制。

Changes: OTP 粘贴处理

Layer / File(s) Summary
格式化后限制 OTP 长度
components/input/OTP/index.tsx, components/input/__tests__/otp.test.tsx
粘贴候选值在格式化前不再截断,格式化结果返回前按 OTP 长度截断。新增测试检查过滤分隔符后的单元格值、onInput 和 onChange 回调、焦点位置及长度限制。数字零分隔符测试的预期值未变。

Priority: ⬇️ Low

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Low

Suggested reviewers: qdyanbing, ye-yichen

Merge Risk: ⚪ Minimal · up to 257eb

Formatted pastes retain valid digits within the configured length. No merge-blocking issue was established.

Pre-merge checks: Passed 5
Passed Passed checks: 5 passed
Check name Status Explanation
Title check Passed 标题准确概括了主要变更:修复格式化文本粘贴到 Input.OTP 时有效数字丢失的问题。
Description check Passed 描述与变更内容直接相关,并说明了问题、修复方案、测试结果和已知的无关失败。
Linked Issues check Passed 直接关联的开放 issue #59579 要求先执行 formatter,再按 OTP length 截断,并覆盖 123 456、123-456、1 2 3 4 5 6、中间单元格粘贴、回调值、焦点和长度上限。components/input/OTP/index.tsx 的 patchValue 先调用 internalFormatter,再执行 `slice(0, le…
Out of Scope Changes check Passed 变更摘要显示改动仅涉及 components/input/OTP/index.tsx 和其现有测试文件。实现变更直接修复 #59579。新增测试验证该修复。数字零分隔符断言仅改变格式,不改变断言内容。未发现与 issue 目标无关的代码变更。
Docstring Coverage Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 2…
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

@pkg-pr-new

pkg-pr-new Bot commented Oct 15, 2026

Copy link
Copy Markdown
More templates

npm i https://pkg.pr.new/antd@59580

commit: 257ebed

@codecov

codecov Bot commented Oct 15, 2026 •

Copy link
Copy Markdown

Bundle Report

Changes will decrease total bundle size by 39.63kB (-1.21%) ⬇️. This is within the configured threshold ✅

Detailed changes
Bundle name Size Change
antd.min-array-push 3.24MB -39.63kB (-1.21%) ⬇️

Affected Assets, Files, and Routes:

view changes for bundle: antd.min-array-push

Assets Changed:

Asset Name Size Change Total Size Change (%)
antd-with-locales.min.js -31.52kB 1.81MB -1.71%
antd.min.js -8.11kB 1.43MB -0.56%

@codecov

codecov Bot commented Oct 15, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (05140c7) to head (257ebed).

Additional details and impacted files
@@             Coverage Diff             @@
##            master    #59580     +/-   ##
===========================================
  Coverage   100.00%   100.00%             
===========================================
  Files          835       833      -2     
  Lines        17689     16053   -1636     
  Branches      4863      4211    -652     
===========================================
- Hits         17689     16053   -1636     

☔ View full report in Codecov by Harness.
📢 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.

@zombieJ
zombieJ merged commit d52f7a8 into ant-design:master Oct 15, 2026
44 checks passed
@MadCcc MadCcc mentioned this pull request Oct 19, 2026
1 of 17 tasks
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.

Input.OTP drops valid digits when pasting text with a filtering formatter

2 participants