Skip to content

fix: commit a RangePicker range when only one field was typed and the picker is left - #1031

Open
kfylaktopoulos wants to merge 1 commit into
react-component:masterfrom
kfylaktopoulos:fix/range-commit-single-field-edit
Open

kfylaktopoulos wants to merge 1 commit into
react-component:masterfrom
kfylaktopoulos:fix/range-commit-single-field-edit

Conversation

@kfylaktopoulos

@kfylaktopoulos kfylaktopoulos commented Dec 4, 2026 •

Copy link
Copy Markdown

Problem: in a RangePicker without needConfirm, typing a new start or end date into a filled range and then leaving the picker (blur / click outside) never fires onChange. The input shows the new date, but the value (and any Form) keeps the old one.

Steps (antd DatePicker.RangePicker in a Form, or @rc-component/picker directly):

  1. Value [2000-01-01, 2000-01-05].
  2. Focus the end input, type 2000-01-09.
  3. Click outside.

Expected: onChange with ['2000-01-01', '2000-01-09']. Actual: no onChange; the form still submits 2000-01-05.

Why: useRangeValueChange only emits the final change once every field took part in the interaction. A popup close after input only part-submits the current field and moves the expected index to the other field, but focus has already left the picker, so that visit never comes and the round is dropped.

Fix: without needConfirm, a popup close that follows input finishes the round when every other field already has a value or allows empty (canFinishEarly). If that final submit is rejected (disabledDate, empty required field), all temporary values are reset so the input doesn't keep text the value never got. FlushSubmit now returns whether the submit passed, for that check.

Unchanged on purpose:

  • Enter still moves to the other field (auto open tests in range.spec.tsx).
  • needConfirm, Escape, panel selection and Tab keep their current flow.
  • An empty required other field still waits for it (no early finish).
  • Single pickers: they always have every field triggered, so nothing changes there.

Tests: tests/range-commit.spec.tsx (8 cases). 5 fail on master and pass with the fix (typed start, typed end, allowEmpty end, disabledDate rejection then a valid edit, order={false}); 3 pass on both and guard Enter, Escape and the required-empty case. The full suite has the same 11 failures as on master in this environment (classNames/time step in picker.spec.tsx, panelRender/dateRender snapshots in range.spec.tsx).

Related: #1020 (rejected value on popup close) touches the same path for a different case.

Summary by CodeRabbit

  • 问题修复
    • 修复范围日期选择器单字段编辑后的提交行为:失焦或按 Enter 后会按校验结果提交;不符合条件的输入不会提交,并恢复原值。
    • 支持在允许结束日期为空时提交;必填结束日期为空时不会提交。按 Escape 可放弃当前输入。

@vercel

vercel Bot commented Dec 4, 2026

Copy link
Copy Markdown

@kfylaktopoulos is attempting to deploy a commit to the afc163's projects Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai

coderabbitai Bot commented Dec 4, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

范围选择器的提交函数现在返回提交校验结果。无需触发变更时,提交函数返回 true。范围输入在满足条件时可于弹层关闭后完成提交;新增测试覆盖相关输入和取消场景。

Changes

范围选择器提交流程

Layer / File(s) Summary
提交结果返回
src/PickerInput/hooks/useRangeValue.ts, src/PickerInput/hooks/useRangeValueChange.ts, src/PickerInput/RangePicker.tsx, src/PickerInput/SinglePicker.tsx
flushSubmit、FlushSubmit 和调用方现在返回布尔结果。需要提交时返回校验结果;无需触发变更时返回 true。
范围输入提前完成
src/PickerInput/hooks/useRangeValueChange.ts, tests/range-commit.spec.tsx
弹层因输入而关闭时,如果其他字段已有值或允许为空,提交流程可以提前完成。提前提交未通过时会重置临时值。新增测试覆盖失焦提交、Enter、Escape、空值、disabledDate 和 order={false}。

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

Change: Bug fix

Possibly related PRs

Suggested reviewers: zombiej

Merge Risk: Minimal · up to aa8b0

Typing into only one field of a filled range picker and leaving it now commits the range, and rejected edits are reset. The change is narrowly scoped, with tests for the main paths. No concrete merge-blocking risk was found.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed 标题描述了主要变更:当仅在 RangePicker 的一个字段中输入内容并离开选择器时,提交范围值。变更摘要中的 useRangeValueChange.ts 新增 canFinishEarly 逻辑、FlushSubmit 返回 boolean,以及 tests/range-commit.spec.tsx 中的相关测试,均与该标题一致。标题为单句,未包含文件列表或表情符号,类型前缀 fix: 也…
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.
Full details: Title check

Explanation

标题描述了主要变更:当仅在 RangePicker 的一个字段中输入内容并离开选择器时,提交范围值。变更摘要中的 useRangeValueChange.ts 新增 canFinishEarly 逻辑、FlushSubmit 返回 boolean,以及 tests/range-commit.spec.tsx 中的相关测试,均与该标题一致。标题为单句,未包含文件列表或表情符号,类型前缀 fix: 也符合修复类变更。

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
Fix failing CI checks

  • 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

兔子轻敲日期格,
输入落下新月色。
失焦之后看校验,
允许空值也能写。
按下 Escape 收回笔,
窗边萝卜庆提交。

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: aa23627d-73d2-4394-bbf6-912819dd696a
Commits

Reviewing files that changed from the base of the PR and between b92dd5b and aa8b07e.

Files selected for processing: 5

  • src/PickerInput/RangePicker.tsx
  • src/PickerInput/SinglePicker.tsx
  • src/PickerInput/hooks/useRangeValue.ts
  • src/PickerInput/hooks/useRangeValueChange.ts
  • tests/range-commit.spec.tsx

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

@kfylaktopoulos

Copy link
Copy Markdown
Author

cc @kliakos — this is the upstream fix for the RangePicker commit issue we patched locally (typed edit of one field lost on blur).

This branch has not been deployed

No deployments
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.

1 participant