Skip to content

fix: datepicker to emit onErrorChange instead of built-in error UI - #881

Open
rohanchkrabrty wants to merge 5 commits into
mainfrom
remove-datepicker-stale-error
Open

fix: datepicker to emit onErrorChange instead of built-in error UI#881
rohanchkrabrty wants to merge 5 commits into
mainfrom
remove-datepicker-stale-error

Conversation

@rohanchkrabrty

Copy link
Copy Markdown
Contributor

Summary

  • Add onErrorChange?: (error: string | undefined) => void to DatePicker — fires on typed-input validity transitions only (a message when the text stops parsing as a valid in-bounds date, undefined when it recovers or the picker commits/closes), mirroring the onOpenChange convention.
  • Remove DatePicker's built-in error presentation — the inline "Invalid date" role="alert" span, its reserved-line CSS, and the aria-invalid/aria-describedby wiring. Error display is now consumer-owned: lift the callback into Field's error prop (which also wires aria-invalid via Base UI) or a form library. Breaking for consumers relying on the built-in message.
  • Track the error in a ref instead of state (nothing renders from it anymore), which also removes the stale-error closure read in the outside-click commit path.
  • Rework tests to assert through onErrorChange and add coverage for transition-only firing, clearing on recovery/commit, and a no-error-UI regression test.
  • Docs: document onErrorChange in the props reference and add a "With Field" live example to the DatePicker demos.

@vercel

vercel Bot commented Aug 4, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
apsara Ready Ready Preview Aug 6, 2026 7:24am

@rohanchkrabrty
rohanchkrabrty requested a review from rsbh August 4, 2026 09:20
@coderabbitai

coderabbitai Bot commented Aug 4, 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: 56db536b-b28d-4edd-95a4-5f7da8ef6787

📥 Commits

Reviewing files that changed from the base of the PR and between 0f00b0a and 0c19a67.

📒 Files selected for processing (8)
  • apps/www/src/content/docs/components/calendar/demo.ts
  • apps/www/src/content/docs/components/calendar/index.mdx
  • apps/www/src/content/docs/components/calendar/props.ts
  • packages/raystack/components/calendar/__tests__/data-slots.test.tsx
  • packages/raystack/components/calendar/__tests__/date-picker.test.tsx
  • packages/raystack/components/calendar/calendar.module.css
  • packages/raystack/components/calendar/date-picker.tsx
  • packages/raystack/components/filter-chip/filter-chip.module.css
💤 Files with no reviewable changes (4)
  • apps/www/src/content/docs/components/calendar/index.mdx
  • packages/raystack/components/calendar/calendar.module.css
  • packages/raystack/components/filter-chip/filter-chip.module.css
  • packages/raystack/components/calendar/tests/data-slots.test.tsx
🚧 Files skipped from review as they are similar to previous changes (4)
  • apps/www/src/content/docs/components/calendar/props.ts
  • apps/www/src/content/docs/components/calendar/demo.ts
  • packages/raystack/components/calendar/tests/date-picker.test.tsx
  • packages/raystack/components/calendar/date-picker.tsx

📝 Walkthrough

Walkthrough

DatePicker now exposes an optional onErrorChange callback for typed-input validation. It reports "Invalid date" and clears the error with undefined. DatePicker no longer renders error text or sets aria-invalid. It suppresses onSelect when closing with invalid input. Tests cover validation transitions and commit behavior. Documentation adds integration with Field.

Sequence Diagram(s)

sequenceDiagram
  participant User
  participant DatePicker
  participant Consumer
  participant Field
  User->>DatePicker: Type date
  DatePicker->>Consumer: onErrorChange("Invalid date")
  Consumer->>Field: Set error
  User->>DatePicker: Correct date or select date
  DatePicker->>Consumer: onErrorChange(undefined)
  Consumer->>Field: Clear error
Loading

Suggested reviewers: rsbh, shreyag02, paansinghcoder

🚥 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%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: DatePicker now emits onErrorChange instead of rendering built-in error UI.
Description check ✅ Passed The description accurately explains the callback, removed error presentation, test updates, and documentation changes.
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.

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 Aug 4, 2026

Copy link
Copy Markdown

Open in StackBlitz

pnpm add https://pkg.pr.new/raystack/apsara/@raystack/apsara@881

commit: 0c19a67

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Nitpick comments (1)
packages/raystack/components/calendar/__tests__/date-picker.test.tsx (1)

556-568: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Assert onSelect suppression for an invalid Enter commit.

This test verifies error clearing only. Pass an onSelect spy and assert that it has no calls. Otherwise, a regression in if (!hadError && committedDate) can pass this test.

Proposed test update
 it('fires with undefined when the picker commits via Enter with invalid text', () => {
   const onErrorChange = vi.fn();
+  const onSelect = vi.fn();
   render(
-    <DatePicker dateFormat='DD/MM/YYYY' onErrorChange={onErrorChange} />
+    <DatePicker
+      dateFormat='DD/MM/YYYY'
+      onErrorChange={onErrorChange}
+      onSelect={onSelect}
+    />
   );

   // ...
   expect(onErrorChange).toHaveBeenLastCalledWith(undefined);
+  expect(onSelect).not.toHaveBeenCalled();
 });
🤖 Prompt for 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.

In `@packages/raystack/components/calendar/__tests__/date-picker.test.tsx` around
lines 556 - 568, Update the invalid-Enter test around the DatePicker render to
provide an onSelect spy, then assert that it has not been called after
submitting invalid text. Keep the existing onErrorChange assertion so the test
covers both error clearing and suppression of selection for an invalid commit.
🤖 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 `@packages/raystack/components/calendar/date-picker.tsx`:
- Around line 100-106: Update the controlled value synchronization path in
date-picker.tsx to clear the existing error via updateError(undefined) when a
new value replaces invalid typed text. Add a test in
packages/raystack/components/calendar/__tests__/date-picker.test.tsx covering
invalid input followed by rerendering with a new controlled value and asserting
onErrorChange(undefined).
- Around line 50-58: Wire DatePicker’s onErrorChange state through the trigger
input so Field’s invalid/error state reaches the rendered input, including the
required aria-invalid/aria-describedby behavior; update the DatePicker
implementation at packages/raystack/components/calendar/date-picker.tsx lines
221-240 and its API documentation/examples at
apps/www/src/content/docs/components/calendar/props.ts lines 268-276 and
apps/www/src/content/docs/components/calendar/demo.ts lines 187-206. If this
integration cannot be completed, remove the onErrorChange guarantee from the
API/docs and examples at all listed sites.

---

Nitpick comments:
In `@packages/raystack/components/calendar/__tests__/date-picker.test.tsx`:
- Around line 556-568: Update the invalid-Enter test around the DatePicker
render to provide an onSelect spy, then assert that it has not been called after
submitting invalid text. Keep the existing onErrorChange assertion so the test
covers both error clearing and suppression of selection for an invalid commit.
🪄 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 Plus

Run ID: 9dad2056-24b9-4e04-95db-62fdb7fde279

📥 Commits

Reviewing files that changed from the base of the PR and between 453c4ea and 14c415c.

📒 Files selected for processing (5)
  • apps/www/src/content/docs/components/calendar/demo.ts
  • apps/www/src/content/docs/components/calendar/props.ts
  • packages/raystack/components/calendar/__tests__/date-picker.test.tsx
  • packages/raystack/components/calendar/calendar.module.css
  • packages/raystack/components/calendar/date-picker.tsx
💤 Files with no reviewable changes (1)
  • packages/raystack/components/calendar/calendar.module.css

Comment thread packages/raystack/components/calendar/date-picker.tsx
Comment thread packages/raystack/components/calendar/date-picker.tsx
Comment thread apps/www/src/content/docs/components/calendar/demo.ts
Comment thread packages/raystack/components/calendar/calendar.module.css
@coderabbitai

coderabbitai Bot commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

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