feat(date-picker): added isOpen and onOpenChange
Closes #3457
📝 Description
Added isOpen prop and onOpenChange event, so that they could be used to control visibility of the DatePicker popover.
⛳️ Current behavior (updates)
🚀 New behavior
💣 Is this a breaking change (Yes/No):
📝 Additional Information
If the PR gets accepted please use my GitHub email-id ([email protected]) instead of my other email-id for the Co-authored-by: message.
Summary by CodeRabbit
-
New Features
- Added
isOpenandonOpenChangefunctionalities to the DatePicker component for improved control over the date picker's visibility.
- Added
🦋 Changeset detected
Latest commit: 67af7103019bc1a7de3929f66fb16966467632be
The changes in this PR will be included in the next version bump.
This PR includes changesets to release 2 packages
| Name | Type |
|---|---|
| @nextui-org/date-picker | Patch |
| @nextui-org/react | Patch |
Not sure what this means? Click here to learn what changesets are.
Click here if you're a maintainer who wants to add another changeset to this PR
The latest updates on your projects. Learn more about Vercel for Git ↗︎
| Name | Status | Preview | Comments | Updated (UTC) |
|---|---|---|---|---|
| nextui-storybook-v2 | ✅ Ready (Inspect) | Visit Preview | 💬 Add feedback | Jul 16, 2024 2:32pm |
Someone is attempting to deploy a commit to the NextUI Inc Team on Vercel.
A member of the Team first needs to authorize it.
[!CAUTION]
Review failed
The head commit changed during the review from 5b9a42dcc0dc44e05385b6d40f8b7c7bdc11ac6e to 67af7103019bc1a7de3929f66fb16966467632be.
Walkthrough
The changes introduce the ability to manage the visibility state of the DatePicker component in the @nextui-org/date-picker package. This includes adding isOpen state management and onOpenChange handlers to control and respond to the opening and closing of the date picker. These updates aim to enhance user interaction, especially addressing issues where the DatePicker would not dismiss after selecting a date from a preset.
Changes
| File Path | Change Summary |
|---|---|
.../date-picker/src/use-date-picker-base.ts |
Added onOpenChange property to the props object and destructured object. |
.../date-picker/src/use-date-picker.ts |
Included handling for onOpenChange with the isOpen parameter and exposed them in the return object. |
.changeset/silent-countries-drum.md |
Documented the addition of isOpen and onOpenChange functionalities to the DatePicker component. |
.../date-picker/stories/date-picker.stories.tsx |
Added isOpen state and setIsOpen handler for visibility management of the date picker. Modified button handlers to update isOpen state. |
.../docs/content/components/date-picker/preset.ts |
Added isOpen state management and modified button onPress handlers to set isOpen to false after updating the value. Included the onOpenChange handler. |
Sequence Diagram(s)
N/A
Assessment against linked issues
| Objective (Issue) | Addressed | Explanation |
|---|---|---|
| Fix bug where DatePicker does not dismiss after selecting a date from Preset (#3457) | ✅ | |
Ensure onOpenChange triggers properly when DatePicker visibility changes (#3457) |
✅ |
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?
🪧 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. -
Generate unit testing code for this file. -
Open a follow-up GitHub issue for this discussion.
-
- Files and specific lines of code (under the "Files changed" tab): Tag
@coderabbitaiin a new review comment at the desired location with your query. Examples:-
@coderabbitai generate unit testing code for this file. -
@coderabbitai modularize this function.
-
- PR comments: Tag
@coderabbitaiin 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 generate unit testing code. -
@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.
-
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 pauseto pause the reviews on a PR. -
@coderabbitai resumeto resume the paused reviews. -
@coderabbitai reviewto trigger an incremental review. This is useful when automatic reviews are disabled for the repository. -
@coderabbitai full reviewto do a full review from scratch and review all the files again. -
@coderabbitai summaryto regenerate the summary of the PR. -
@coderabbitai resolveresolve all the CodeRabbit review comments. -
@coderabbitai configurationto show the current CodeRabbit configuration for the repository. -
@coderabbitai helpto get help.
Other keywords and placeholders
- Add
@coderabbitai ignoreanywhere in the PR description to prevent this PR from being reviewed. - Add
@coderabbitai summaryto generate the high-level summary at a specific location in the PR description. - Add
@coderabbitaianywhere 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.
@wingkwong For the changeset, should it be a minor or a patch?
mark it patch first
please include test cases
I was testing while adding the test cases and i noticed a bug. Consider the below code where you toggle isOpen using a component like Button in the below code.
const [isOpen, setIsOpen] = React.useState<boolean>(false);
<Button
onClick={() => {
console.log("Toggle Outside", isOpen);
setIsOpen(!isOpen);
}}
>
Toggle Outside
</Button>
Bugs:-
-
onOpenChangeis not triggered when you click onButtonto show the date picker, but theDatePickeris shown. -
onOpenChangegets triggered when you click onButtonto hide the date picker, but theDatePickeris not hidden, it flickers for a second and stays.
Note:-
- You could add the above code to
Presetstemplate inDatePickerto test. - I observed similar bug inside the
Popovercomponent in theOpenChangetemplate.
Could you tell me how you want me to proceed further? Do we need to fix this or do you want me to write the test cases only for the rendering of DatePicker
Please fix the bug as well.
I observed similar bug inside the Popover component in the OpenChange template.
I couldn't reproduce in canary branch nor production. onOpenChange is triggered no matter I open it or close it.
Please fix the bug as well.
I observed similar bug inside the Popover component in the OpenChange template.
I couldn't reproduce in canary branch nor production.
onOpenChangeis triggered no matter I open it or close it.
Could you please check by changing the OpenChangeTemplate in popover.stories.tsx.
The code looks something like this
const OpenChangeTemplate = (args: PopoverProps) => {
const [isOpen, setIsOpen] = React.useState(false);
return (
<div className="flex flex-col gap-2">
<Button
className="mb-10"
onClick={() => {
console.log("Toggle Outside", isOpen);
setIsOpen(!isOpen);
}}
>
Toggle Outside
</Button>
<Popover
{...args}
isOpen={isOpen}
style={{
zIndex: 10,
}}
onOpenChange={(open) => {
console.log("Popover: onOpenChange", open);
setIsOpen(open);
}}
>
<PopoverTrigger>
<Button>Open Popover</Button>
</PopoverTrigger>
<PopoverContent>
<div className="px-1 py-2">
<div className="text-sm font-bold">Popover Content</div>
<div className="text-xs">This is a content of the popover</div>
</div>
</PopoverContent>
</Popover>
<p className="text-sm">isOpen: {isOpen ? "true" : "false"}</p>
</div>
);
};
@ShrinidhiUpadhyaya any updates on this PR?