Skip to content

fix: calendar picker open/close flicker and chevron buttons#827

Merged
rohanchkrabrty merged 2 commits into
mainfrom
fix-calendar
Jun 3, 2026
Merged

fix: calendar picker open/close flicker and chevron buttons#827
rohanchkrabrty merged 2 commits into
mainfrom
fix-calendar

Conversation

@rohanchkrabrty
Copy link
Copy Markdown
Contributor

Summary

  • Ignore Base UI trigger-press close events in usePickerPopover so the date picker no longer flickers shut on the first input click (focus opened it, then the same click's trigger toggle closed it).
  • Thread the open-change reason through DatePickerusePickerPopover.onOpenChange so close ownership stays with outside-click/blur/Enter/day-select logic while Escape and outside-press still flow through.
  • Migrate calendar nav from the deprecated Chevron component to dedicated PreviousMonthButton/NextMonthButton, preserving disabled-state styling and respecting RDP's own disabled flag.
  • Remove stale captionLayout/required comments from DatePicker after the calendar prop wiring change.
  • Add a regression test verifying the picker opens and stays open on the first click of the input.

@vercel
Copy link
Copy Markdown

vercel Bot commented Jun 3, 2026

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

Project Deployment Actions Updated (UTC)
apsara Ready Ready Preview, Comment Jun 3, 2026 4:55am

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jun 3, 2026

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

Run ID: 04bcc1bf-4f0e-4cb4-a4d2-3e9672a2cb88

📥 Commits

Reviewing files that changed from the base of the PR and between 2ea7b0a and 7911a41.

📒 Files selected for processing (1)
  • packages/raystack/components/calendar/calendar.tsx
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/raystack/components/calendar/calendar.tsx

📝 Walkthrough

Walkthrough

This PR routes Popover event reasons through DatePicker into usePickerPopover and adds logic to ignore trigger-press close events to prevent the popover from flickering closed on the initial trigger click. DatePicker forwards the event reason to the hook; the hook's onOpenChange signature and logic are updated. Calendar navigation buttons were refactored into dedicated Previous/Next components with adjusted disabled logic. A test was added to assert the popover stays open after the first trigger click.

Sequence Diagram(s)

sequenceDiagram
  participant Input as DatePicker Trigger
  participant Popover as Popover
  participant Hook as usePickerPopover

  Input->>Popover: click -> Popover.onOpenChange(open=true,eventDetails{reason:'trigger-press'})
  Popover->>Hook: onOpenChange(open=true, reason='trigger-press')
  alt open === true
    Hook-->>Popover: accept open (no suppression)
  else open === false and reason === 'trigger-press'
    Hook-->>Popover: ignore close (suppress)
  end
Loading

Suggested reviewers

  • paanSinghCoder
  • rsbh
  • rohilsurana
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.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 accurately summarizes the two main changes: fixing a calendar picker flicker issue and updating chevron buttons, which matches the primary objectives of the changeset.
Description check ✅ Passed The description is directly related to the changeset, detailing the specific fixes for the flicker issue, the reason threading, the chevron component migration, and the regression test.
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.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


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 and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
packages/raystack/components/calendar/use-picker-popover.ts (1)

141-167: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Tear down engagement on real close events.

onOpenChange(false, ...) now closes the popover without calling disengage(). If the picker was already engaged, isEngagedRef stays true and the document mouseup listener stays armed, so the next input focus is ignored by handleInputFocus() and keyboard reopen-on-focus breaks after an Escape/outside close.

Suggested fix
-  const onOpenChange = useCallback((open?: boolean, reason?: string) => {
+  const onOpenChange = useCallback((open?: boolean, reason?: string) => {
     // Year/month dropdown opening inside the popover triggers an open-change
     // we don't want; swallow it and consume the flag.
     if (isDropdownOpenRef.current) {
       isDropdownOpenRef.current = false;
       return;
     }
@@
     if (reason === 'trigger-press' && open === false) return;
@@
     if (open === true && isEngagedRef.current && isOpenRef.current) return;
+    if (open === false) {
+      disengage();
+      return;
+    }
     setIsOpen(Boolean(open));
-  }, []);
+  }, [disengage]);
🤖 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/use-picker-popover.ts` around lines 141
- 167, onOpenChange currently closes the popover (setIsOpen(false)) without
calling disengage(), leaving isEngagedRef true and the document mouseup listener
active; update onOpenChange to call disengage() whenever the popover is actually
being closed (i.e., when open is false and the close isn't an ignored
trigger-press or dropdown swallow) so that isEngagedRef is reset and the mouseup
listener is removed; locate the onOpenChange callback and invoke the disengage()
helper immediately before or instead of setIsOpen(false) for real close events
(but keep the existing early returns for isDropdownOpenRef and the trigger-press
ignore).
🤖 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/calendar.tsx`:
- Line 129: The disabled prop currently uses nullish coalescing
(disabled={loadingData ?? props.disabled}) which always returns loadingData
(false) and ignores props.disabled; change both PreviousMonthButton and
NextMonthButton to combine conditions so the button is disabled when either
loadingData is true or props.disabled is true (i.e., use a logical OR between
loadingData and props.disabled) to ensure DayPicker’s disabled state is
respected.
- Line 130: The disabled visual state only checks loadingData but the actual
disabled prop is computed as loadingData || props.disabled, so update the
className logic in both PreviousMonthButton and NextMonthButton to use the same
combined disabled value (e.g., the existing disabled variable or compute
disabled = loadingData || props.disabled) instead of only loadingData so the
styles.disabled class is applied whenever the button is disabled by either
condition.

In `@packages/raystack/components/calendar/use-picker-popover.ts`:
- Around line 148-159: The unconditional early return for reason ===
'trigger-press' in usePickerPopover changes behavior for all consumers; make
this behavior opt-in by adding a hook option (e.g., ignoreTriggerPress: boolean,
default false) to usePickerPopover and guard the existing if (reason ===
'trigger-press' && open === false) return; behind that option, then update
DatePicker to call usePickerPopover({ ..., ignoreTriggerPress: true }) so only
the DatePicker opts into ignoring trigger-press closes.

---

Outside diff comments:
In `@packages/raystack/components/calendar/use-picker-popover.ts`:
- Around line 141-167: onOpenChange currently closes the popover
(setIsOpen(false)) without calling disengage(), leaving isEngagedRef true and
the document mouseup listener active; update onOpenChange to call disengage()
whenever the popover is actually being closed (i.e., when open is false and the
close isn't an ignored trigger-press or dropdown swallow) so that isEngagedRef
is reset and the mouseup listener is removed; locate the onOpenChange callback
and invoke the disengage() helper immediately before or instead of
setIsOpen(false) for real close events (but keep the existing early returns for
isDropdownOpenRef and the trigger-press ignore).
🪄 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

Run ID: 3604b79b-ac91-4bb5-a013-0327e3752b56

📥 Commits

Reviewing files that changed from the base of the PR and between c0bc3a0 and 2ea7b0a.

📒 Files selected for processing (4)
  • packages/raystack/components/calendar/__tests__/date-picker.test.tsx
  • packages/raystack/components/calendar/calendar.tsx
  • packages/raystack/components/calendar/date-picker.tsx
  • packages/raystack/components/calendar/use-picker-popover.ts

Comment thread packages/raystack/components/calendar/calendar.tsx Outdated
Comment thread packages/raystack/components/calendar/calendar.tsx
Comment thread packages/raystack/components/calendar/use-picker-popover.ts
Comment thread packages/raystack/components/calendar/calendar.tsx
@rohanchkrabrty rohanchkrabrty merged commit 3e4d932 into main Jun 3, 2026
5 checks passed
@rohanchkrabrty rohanchkrabrty deleted the fix-calendar branch June 3, 2026 04:56
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