Skip to content

fix: preserve alternate format input while typing - #1008

Open
nrps9909 wants to merge 1 commit into
react-component:masterfrom
nrps9909:codex/mixed-year-input
Open

fix: preserve alternate format input while typing#1008
nrps9909 wants to merge 1 commit into
react-component:masterfrom
nrps9909:codex/mixed-year-input

Conversation

@nrps9909

@nrps9909 nrps9909 commented Aug 27, 2026

Copy link
Copy Markdown

Summary

  • keep the focused raw input when an alternate format parses to the same value that the picker just formatted
  • allow a longer format to continue receiving characters after a shorter format becomes valid
  • continue syncing the input immediately when a panel or controlled update selects a different date

Regression

With format={['DD-MM-YYYY', 'DD-MM-YY']}, exact base 16084b6a1593d8815a6ae65cba4e6f7ce8d48c9a rewrites the typed prefix 01-12-20 to 01-12-2020, preventing normal continuation to a four-digit year.

The new regression types 01-12-2024 character by character, asserts that the ambiguous short prefix remains untouched, submits the completed value, and then verifies that a controlled update to a different date still replaces the input.

Validation

  • full test suite: 15 suites, 469 passed, 2 skipped, 29 snapshots passed
  • complete Picker scope: 110 passed, 1 skipped, 5 snapshots passed
  • complete RangePicker scope: 123 passed, 1 skipped, 6 snapshots passed
  • ESM, CJS, and declaration build passed
  • source ESLint: 0 errors, 16 existing hook warnings
  • focused Prettier and diff checks passed

Overlap audit

Current open PRs #1005, #1006, #986, and #947 touch one or more of the same selector files for Android IME handling, manual clearing, or keyboard semantics. None addresses alternate-format input normalization or the YY / YYYY boundary. This PR stays scoped to that distinct state-synchronization behavior.

Fixes #956.
Related to #911.

AI assistance disclosure: Codex was used to trace the input/value synchronization path, construct the causal regression, run the validation matrix, audit open changed-file overlap, and draft this description. I verified the base failure, head behavior, test results, diff, and signed commit before submission.

Summary by CodeRabbit

  • 新功能
    • 新增输入内容保留选项,可在外部值变化时根据条件保留用户当前输入。
    • 优化日期输入解析,支持同时配置四位和两位年份格式。
  • 问题修复
    • 改善受控日期选择器的输入同步,避免有效输入在重新渲染时被不必要地覆盖。
    • 修复部分匹配日期格式时的输入显示与变更触发问题。
  • 测试
    • 新增多日期格式、部分输入及受控值更新场景的覆盖。

@vercel

vercel Bot commented Aug 27, 2026

Copy link
Copy Markdown

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

A member of the Team first needs to authorize it.

@coderabbitai

coderabbitai Bot commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

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 Plus

Run ID: 9a9374d0-026b-467b-8526-891fa35cf3b9

📥 Commits

Reviewing files that changed from the base of the PR and between 16084b6 and 3782bfb.

📒 Files selected for processing (3)
  • src/PickerInput/Selector/Input.tsx
  • src/PickerInput/Selector/hooks/useInputProps.ts
  • tests/picker.spec.tsx

Included review availability: Your plan provides up to 2 included reviews per hour; 0 remain after this review.


Walkthrough

组件新增输入文本保留判断。输入状态统一通过更新函数维护。日期选择器现在支持在短日期格式匹配时继续输入四位年份,并验证受控值变化行为。

Changes

输入值保留流程

Layer / File(s) Summary
输入保留契约与解析判断
src/PickerInput/Selector/Input.tsx, src/PickerInput/Selector/hooks/useInputProps.ts
InputProps 新增 preserveInputOnValueChangegetInputProps 根据当前文本的解析结果和下一个值判断是否保留输入。
输入状态同步与场景验证
src/PickerInput/Selector/Input.tsx, tests/picker.spec.tsx
组件使用 inputValueRefupdateInputValue 统一同步输入状态。测试覆盖 DD-MM-YYYYDD-MM-YY 并存时输入四位年份,以及受控值重新渲染。

Estimated code review effort: 3 (Moderate) | ~20 minutes

Merge Risk: ⚪ Minimal · up to 3782b

The picker preserves equivalent alternate-format text while typing while continuing to apply different controlled date updates normally. No actionable merge-blocking risk remains after normal checks and review.

Suggested reviewers: zombiej, qdyanbing, afc163

Poem

小兔敲键盘,年份继续长
短格式相遇,输入不慌张
数值同步稳,文本仍清亮
回车日期定,测试来鼓掌
月光下提交,代码闪银光

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 3 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed 标题准确概括了主要变更:用户输入过程中保留备用格式的原始文本。
Linked Issues check ✅ Passed 变更满足问题 #956 的要求。preserveInputOnValueChange 会在备用格式解析为相同值时保留当前输入,因此用户可以继续输入四位年份。受控值更新为其他日期时,组件仍会同步输入框内容。新增测试覆盖了 01-12-2024 场景。
Out of Scope Changes check ✅ Passed 所有代码变更和测试变更都围绕问题 #956 的日期输入保留行为。未发现与目标无关的代码或测试变更。
  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
🛠️ Fix failing CI checks 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

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.

enter date manually in format YY prevent the user to add YYYY

1 participant