fix(TimeField,DateField): avoid changing focus prematurely with previous segment value of 0#2568
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughFixes a focus-navigation bug in date/time field segments by clearing the Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
packages/core/src/shared/date/useDateField.ts (1)
368-371: Apply the same reset in day/month to avoid stale zero-state there too.
updateDayOrMonthresetshasLeftFocus/prevbut notlastKeyZero; this leaves parity gap versus the updated time paths and can still trigger early segment advance after refocus.Suggested parity patch
if (props.hasLeftFocus.value) { props.hasLeftFocus.value = false + props.lastKeyZero.value = false prev = null }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/core/src/shared/date/useDateField.ts` around lines 368 - 371, In updateDayOrMonth (in useDateField.ts) the block that clears props.hasLeftFocus.value and prev must also reset lastKeyZero to match the time-path behavior; update the branch where props.hasLeftFocus.value is set to false (the same spot that sets prev = null) to also set lastKeyZero = false (or its equivalent reactive ref reset) so day/month doesn't retain a stale zero state and prematurely advance segments after refocus.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@packages/core/src/shared/date/useDateField.ts`:
- Around line 368-371: In updateDayOrMonth (in useDateField.ts) the block that
clears props.hasLeftFocus.value and prev must also reset lastKeyZero to match
the time-path behavior; update the branch where props.hasLeftFocus.value is set
to false (the same spot that sets prev = null) to also set lastKeyZero = false
(or its equivalent reactive ref reset) so day/month doesn't retain a stale zero
state and prematurely advance segments after refocus.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: b7d1c481-04a3-4a00-b782-8b8fa89ccf12
📒 Files selected for processing (1)
packages/core/src/shared/date/useDateField.ts
commit: |
|
Thanks for the fix! The root cause diagnosis is correct and the changes in One thing worth addressing in this same PR: The fix would be one additional line at useDateField.ts ~L368: if (props.hasLeftFocus.value) {
props.hasLeftFocus.value = false
props.lastKeyZero.value = false // add this
prev = null
}Also, a regression test covering the scenario (segment value is |
|
I've added the test cases and extended the fix to the DateField component as requested. While adding the tests I noticed a related issue, when using a 12 hour locale the hour segment doesn't change focus when pressing the 0 key more than once, it doesn't seem like its intended... Since the root cause has nothing to do with the current issue I'll address it in another PR if thats ok. |
|
LGTM! Thanks @zomakus ! |
🔗 Linked issue
Fixes #2567
❓ Type of change
📚 Description
In
updateHourandupdateMinuteOrSecondfunctions theprops.lastKeyZerovalue was not being resetted when changing focus, it has been fixed so that context is always clean when starting to work on a segment.📝 Checklist
Summary by CodeRabbit
Bug Fixes
Tests