Skip to content

fix(date-range-picker): fix manual date selection in presets example #5477

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: canary
Choose a base branch
from

Conversation

adi-ray
Copy link
Contributor

@adi-ray adi-ray commented Jul 12, 2025

Closes #4941

📝 Description

Fixes the manual date selection issue in the DateRangePicker presets example where clicking on calendar dates was not properly updating both start and end dates.

⛳️ Current behavior (updates)

  • Manual date selection in calendar only updates the start date
  • End date remains unchanged when users click on calendar dates

🚀 New behavior

  • Manual date selection now properly updates both start and end dates
  • Users can click on calendar dates to select complete date ranges
  • Calendar interaction works seamlessly with preset buttons

Summary by CodeRabbit

  • New Features

    • Improved date range picker presets to allow independent control of the calendar's focused date, enhancing usability when selecting preset ranges.
  • Bug Fixes

    • Resolved issues where the calendar focus did not update correctly when choosing preset date ranges.

@adi-ray adi-ray requested a review from jrgarciadev as a code owner July 12, 2025 11:55
Copy link

changeset-bot bot commented Jul 12, 2025

⚠️ No Changeset found

Latest commit: d2593c5

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link

vercel bot commented Jul 12, 2025

@adi-ray is attempting to deploy a commit to the HeroUI Inc Team on Vercel.

A member of the Team first needs to authorize it.

Copy link
Contributor

coderabbitai bot commented Jul 12, 2025

Walkthrough

The code refactors the date range picker preset example by introducing a separate focusedValue state to manage calendar focus independently from the selected date range. Button handlers and calendar props are updated to use this new state, decoupling focus management from the date range selection logic.

Changes

File(s) Change Summary
apps/docs/content/components/date-range-picker/presets.raw.jsx Added focusedValue state; updated preset handlers to set both value and focusedValue; refactored calendar props to use focusedValue and setFocusedValue instead of updating only the start date in onFocusChange.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant App(Component)
    participant DateRangePicker

    User->>App(Component): Clicks preset button ("This week", etc.)
    App(Component)->>App(Component): Sets new date range (value)
    App(Component)->>App(Component): Sets focusedValue to start date of range
    App(Component)->>DateRangePicker: Passes value, focusedValue, and setFocusedValue
    DateRangePicker->>App(Component): Calls setFocusedValue on focus change
    App(Component)->>DateRangePicker: Updates focusedValue only (not value)
Loading

Assessment against linked issues

Objective Addressed Explanation
Decouple onFocusChange from only updating the start date; allow end date to change as needed (#4941)

Assessment against linked issues: Out-of-scope changes

No out-of-scope changes found.


📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6b28b61 and d2593c5.

📒 Files selected for processing (1)
  • apps/docs/content/components/date-range-picker/presets.raw.jsx (3 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (5)
  • GitHub Check: ESLint
  • GitHub Check: Tests
  • GitHub Check: Build
  • GitHub Check: Continuous Release
  • GitHub Check: TypeScript
🔇 Additional comments (5)
apps/docs/content/components/date-range-picker/presets.raw.jsx (5)

19-19: LGTM: Proper focus state initialization.

The focusedValue state is correctly initialized to defaultDate.start, which ensures the calendar starts with proper focus on the beginning of the default date range.


86-94: LGTM: Consistent state updates in "This week" handler.

The button handler correctly updates both the selected date range and the focused value, ensuring proper synchronization between preset selection and calendar focus.


98-105: LGTM: Consistent state updates in "Next week" handler.

The handler follows the same pattern as the "This week" button, properly updating both states for consistent behavior.


106-113: LGTM: Consistent state updates in "Next month" handler.

All preset buttons now follow the same pattern of updating both the date range value and focused value, ensuring consistent behavior across all presets.


117-118: Excellent fix: Decoupled focus management from date selection.

The calendar props now use the dedicated focusedValue state and setFocusedValue callback. This decoupling resolves the issue where manual calendar date selection was interfering with proper date range selection. The DateRangePicker can now handle both start and end date updates correctly when users click on calendar dates.

✨ Finishing Touches
  • 📝 Generate Docstrings

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

pkg-pr-new bot commented Jul 12, 2025

Open in StackBlitz

@heroui/accordion

npm i https://pkg.pr.new/@heroui/accordion@5477

@heroui/alert

npm i https://pkg.pr.new/@heroui/alert@5477

@heroui/autocomplete

npm i https://pkg.pr.new/@heroui/autocomplete@5477

@heroui/avatar

npm i https://pkg.pr.new/@heroui/avatar@5477

@heroui/badge

npm i https://pkg.pr.new/@heroui/badge@5477

@heroui/breadcrumbs

npm i https://pkg.pr.new/@heroui/breadcrumbs@5477

@heroui/button

npm i https://pkg.pr.new/@heroui/button@5477

@heroui/calendar

npm i https://pkg.pr.new/@heroui/calendar@5477

@heroui/card

npm i https://pkg.pr.new/@heroui/card@5477

@heroui/checkbox

npm i https://pkg.pr.new/@heroui/checkbox@5477

@heroui/chip

npm i https://pkg.pr.new/@heroui/chip@5477

@heroui/code

npm i https://pkg.pr.new/@heroui/code@5477

@heroui/date-input

npm i https://pkg.pr.new/@heroui/date-input@5477

@heroui/date-picker

npm i https://pkg.pr.new/@heroui/date-picker@5477

@heroui/divider

npm i https://pkg.pr.new/@heroui/divider@5477

@heroui/drawer

npm i https://pkg.pr.new/@heroui/drawer@5477

@heroui/dropdown

npm i https://pkg.pr.new/@heroui/dropdown@5477

@heroui/form

npm i https://pkg.pr.new/@heroui/form@5477

@heroui/image

npm i https://pkg.pr.new/@heroui/image@5477

@heroui/input

npm i https://pkg.pr.new/@heroui/input@5477

@heroui/input-otp

npm i https://pkg.pr.new/@heroui/input-otp@5477

@heroui/kbd

npm i https://pkg.pr.new/@heroui/kbd@5477

@heroui/link

npm i https://pkg.pr.new/@heroui/link@5477

@heroui/listbox

npm i https://pkg.pr.new/@heroui/listbox@5477

@heroui/menu

npm i https://pkg.pr.new/@heroui/menu@5477

@heroui/modal

npm i https://pkg.pr.new/@heroui/modal@5477

@heroui/navbar

npm i https://pkg.pr.new/@heroui/navbar@5477

@heroui/number-input

npm i https://pkg.pr.new/@heroui/number-input@5477

@heroui/pagination

npm i https://pkg.pr.new/@heroui/pagination@5477

@heroui/popover

npm i https://pkg.pr.new/@heroui/popover@5477

@heroui/progress

npm i https://pkg.pr.new/@heroui/progress@5477

@heroui/radio

npm i https://pkg.pr.new/@heroui/radio@5477

@heroui/ripple

npm i https://pkg.pr.new/@heroui/ripple@5477

@heroui/scroll-shadow

npm i https://pkg.pr.new/@heroui/scroll-shadow@5477

@heroui/select

npm i https://pkg.pr.new/@heroui/select@5477

@heroui/skeleton

npm i https://pkg.pr.new/@heroui/skeleton@5477

@heroui/slider

npm i https://pkg.pr.new/@heroui/slider@5477

@heroui/snippet

npm i https://pkg.pr.new/@heroui/snippet@5477

@heroui/spacer

npm i https://pkg.pr.new/@heroui/spacer@5477

@heroui/spinner

npm i https://pkg.pr.new/@heroui/spinner@5477

@heroui/switch

npm i https://pkg.pr.new/@heroui/switch@5477

@heroui/table

npm i https://pkg.pr.new/@heroui/table@5477

@heroui/tabs

npm i https://pkg.pr.new/@heroui/tabs@5477

@heroui/toast

npm i https://pkg.pr.new/@heroui/toast@5477

@heroui/tooltip

npm i https://pkg.pr.new/@heroui/tooltip@5477

@heroui/user

npm i https://pkg.pr.new/@heroui/user@5477

@heroui/react

npm i https://pkg.pr.new/@heroui/react@5477

@heroui/system

npm i https://pkg.pr.new/@heroui/system@5477

@heroui/system-rsc

npm i https://pkg.pr.new/@heroui/system-rsc@5477

@heroui/theme

npm i https://pkg.pr.new/@heroui/theme@5477

@heroui/use-aria-accordion

npm i https://pkg.pr.new/@heroui/use-aria-accordion@5477

@heroui/use-aria-accordion-item

npm i https://pkg.pr.new/@heroui/use-aria-accordion-item@5477

@heroui/use-aria-button

npm i https://pkg.pr.new/@heroui/use-aria-button@5477

@heroui/use-aria-link

npm i https://pkg.pr.new/@heroui/use-aria-link@5477

@heroui/use-aria-modal-overlay

npm i https://pkg.pr.new/@heroui/use-aria-modal-overlay@5477

@heroui/use-aria-multiselect

npm i https://pkg.pr.new/@heroui/use-aria-multiselect@5477

@heroui/use-callback-ref

npm i https://pkg.pr.new/@heroui/use-callback-ref@5477

@heroui/use-clipboard

npm i https://pkg.pr.new/@heroui/use-clipboard@5477

@heroui/use-data-scroll-overflow

npm i https://pkg.pr.new/@heroui/use-data-scroll-overflow@5477

@heroui/use-disclosure

npm i https://pkg.pr.new/@heroui/use-disclosure@5477

@heroui/use-draggable

npm i https://pkg.pr.new/@heroui/use-draggable@5477

@heroui/use-image

npm i https://pkg.pr.new/@heroui/use-image@5477

@heroui/use-infinite-scroll

npm i https://pkg.pr.new/@heroui/use-infinite-scroll@5477

@heroui/use-intersection-observer

npm i https://pkg.pr.new/@heroui/use-intersection-observer@5477

@heroui/use-is-mobile

npm i https://pkg.pr.new/@heroui/use-is-mobile@5477

@heroui/use-is-mounted

npm i https://pkg.pr.new/@heroui/use-is-mounted@5477

@heroui/use-measure

npm i https://pkg.pr.new/@heroui/use-measure@5477

@heroui/use-pagination

npm i https://pkg.pr.new/@heroui/use-pagination@5477

@heroui/use-real-shape

npm i https://pkg.pr.new/@heroui/use-real-shape@5477

@heroui/use-ref-state

npm i https://pkg.pr.new/@heroui/use-ref-state@5477

@heroui/use-resize

npm i https://pkg.pr.new/@heroui/use-resize@5477

@heroui/use-safe-layout-effect

npm i https://pkg.pr.new/@heroui/use-safe-layout-effect@5477

@heroui/use-scroll-position

npm i https://pkg.pr.new/@heroui/use-scroll-position@5477

@heroui/use-ssr

npm i https://pkg.pr.new/@heroui/use-ssr@5477

@heroui/use-theme

npm i https://pkg.pr.new/@heroui/use-theme@5477

@heroui/use-update-effect

npm i https://pkg.pr.new/@heroui/use-update-effect@5477

@heroui/aria-utils

npm i https://pkg.pr.new/@heroui/aria-utils@5477

@heroui/dom-animation

npm i https://pkg.pr.new/@heroui/dom-animation@5477

@heroui/framer-utils

npm i https://pkg.pr.new/@heroui/framer-utils@5477

@heroui/react-rsc-utils

npm i https://pkg.pr.new/@heroui/react-rsc-utils@5477

@heroui/react-utils

npm i https://pkg.pr.new/@heroui/react-utils@5477

@heroui/shared-icons

npm i https://pkg.pr.new/@heroui/shared-icons@5477

@heroui/shared-utils

npm i https://pkg.pr.new/@heroui/shared-utils@5477

@heroui/stories-utils

npm i https://pkg.pr.new/@heroui/stories-utils@5477

@heroui/test-utils

npm i https://pkg.pr.new/@heroui/test-utils@5477

commit: d2593c5

Copy link

vercel bot commented Jul 12, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
heroui ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 12, 2025 0:06am
heroui-sb ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 12, 2025 0:06am

@adi-ray
Copy link
Contributor Author

adi-ray commented Jul 12, 2025

@wingkwong During the fix, I encountered YAML parsing errors when running the docs locally on Windows.
image

This appears to be related to the Contentlayer/YAML parsing issues discussed in GitHub Community Discussion #109713

Had to use GitHub Codespaces as an alt.

Copy link
Member

@wingkwong wingkwong left a comment

Choose a reason for hiding this comment

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

Select start day as 2nd, then hover on 19th. The end date is still 07/23/2025 until the end date is selected. With this PR changes, start & end dates are no longer interactive.

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] - onFocusChange in date range picker preset example
2 participants