nextui icon indicating copy to clipboard operation
nextui copied to clipboard

feat(date-picker): added isOpen and onOpenChange

Open ShrinidhiUpadhyaya opened this issue 1 year ago • 9 comments

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 isOpen and onOpenChange functionalities to the DatePicker component for improved control over the date picker's visibility.

ShrinidhiUpadhyaya avatar Jul 15 '24 17:07 ShrinidhiUpadhyaya

🦋 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

changeset-bot[bot] avatar Jul 15 '24 17:07 changeset-bot[bot]

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

vercel[bot] avatar Jul 15 '24 17:07 vercel[bot]

Someone is attempting to deploy a commit to the NextUI Inc Team on Vercel.

A member of the Team first needs to authorize it.

vercel[bot] avatar Jul 15 '24 17:07 vercel[bot]

[!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?

❤️ 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.
    • 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 @coderabbitai in 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 @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 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 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 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.

coderabbitai[bot] avatar Jul 15 '24 17:07 coderabbitai[bot]

@wingkwong For the changeset, should it be a minor or a patch?

ShrinidhiUpadhyaya avatar Jul 16 '24 12:07 ShrinidhiUpadhyaya

mark it patch first

wingkwong avatar Jul 16 '24 12:07 wingkwong

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:-

  1. onOpenChange is not triggered when you click on Button to show the date picker, but the DatePicker is shown.
  2. onOpenChange gets triggered when you click on Button to hide the date picker, but the DatePicker is not hidden, it flickers for a second and stays.

Note:-

  1. You could add the above code to Presets template in DatePicker to test.
  2. I observed similar bug inside the Popover component in the OpenChange template.

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

ShrinidhiUpadhyaya avatar Oct 09 '24 11:10 ShrinidhiUpadhyaya

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.

wingkwong avatar Oct 09 '24 12:10 wingkwong

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.

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 avatar Oct 09 '24 13:10 ShrinidhiUpadhyaya

@ShrinidhiUpadhyaya any updates on this PR?

wingkwong avatar Jan 30 '25 07:01 wingkwong