Skip to content
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

fix(datePicker): prevent year, month change in showMonthAndYearPickers mode #3088

Merged
merged 7 commits into from
Jul 8, 2024

Conversation

KumJungMin
Copy link
Contributor

@KumJungMin KumJungMin commented May 27, 2024

📝 Description

fix issue (#3072)

  • There is an issue that the year and month change when repeatedly opening and closing the datePicker component in showMonthAndYearPickers mode.
  • This issue occurs when opening and closing the datePicker, causing the month and year information to be lost and default values to be set.

Summary by CodeRabbit

  • Bug Fixes

    • Resolved issues with hours and month clearing in showMonthAndYearPickers mode for @nextui-org/calendar and @nextui-org/date-picker packages.
    • Ensured the selected date remains unchanged when the picker is toggled in showMonthAndYearPickers mode.
  • Improvements

    • Added a conditional check to prevent unnecessary scrolling to the selected month/year when the calendar component is mounted/opened/closed.

Copy link

changeset-bot bot commented May 27, 2024

⚠️ No Changeset found

Latest commit: 30e4f3c

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.

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 May 27, 2024

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 May 27, 2024 1:48pm

Copy link

vercel bot commented May 27, 2024

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

A member of the Team first needs to authorize it.

Copy link
Contributor

coderabbitai bot commented May 27, 2024

Walkthrough

The changes primarily address issues related to the showMonthAndYearPickers mode in the @nextui-org/calendar and @nextui-org/date-picker packages. A new conditional check was added to the useCalendarPicker function to prevent unnecessary scrolling. Additionally, new test cases were introduced to ensure the selected date remains unchanged when toggling the picker in the specified mode. These modifications enhance the stability and functionality of the date and calendar pickers.

Changes

Files Change Summary
packages/components/calendar/src/use-calendar-picker.ts Added a conditional check to prevent scrolling when the header is not expanded.
packages/components/date-picker/__tests__/date-picker.test.tsx Introduced a new test case to ensure the selected date remains unchanged when toggling the picker in specific modes.
.changeset/tidy-squids-knock.md Introduced a patch for @nextui-org/calendar and @nextui-org/date-picker to fix issues with hours and month clearing.

Sequence Diagram(s) (Beta)

sequenceDiagram
    participant User
    participant DatePickerComponent
    participant CalendarComponent
    participant useCalendarPicker

    User->>DatePickerComponent: Open Date Picker
    DatePickerComponent->>useCalendarPicker: Initialize
    useCalendarPicker->>useCalendarPicker: Check if header is expanded
    alt Header is not expanded
        useCalendarPicker-->>DatePickerComponent: Skip scrolling
    else Header is expanded
        useCalendarPicker-->>DatePickerComponent: Scroll to selected month/year
    end
    DatePickerComponent-->>User: Display Date Picker

    User->>DatePickerComponent: Toggle Picker
    DatePickerComponent->>CalendarComponent: Toggle Month/Year Picker
    CalendarComponent-->>DatePickerComponent: Update view
    DatePickerComponent-->>User: Display updated picker
Loading

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>.
    • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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.

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 as 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 full the 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 help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

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

Outside diff range and nitpick comments (2)
packages/components/calendar/src/use-calendar-picker.ts (2)

Line range hint 86-86: Correct dependencies in useCallback hook.

The useCallback hook at line 86 specifies isHeaderExpanded as a dependency, which is not used within the callback. Additionally, it does not include getItemsRefMap. Update the dependencies to ensure correct behavior:

-  }, [state, isHeaderExpanded]);
+  }, [state, getItemsRefMap]);

Line range hint 184-184: Update dependencies for keyboard navigation handling.

The useCallback hook at line 184 is missing several dependencies which are crucial for its operation. It also includes state which is not directly used. Update the dependencies to ensure that all necessary values are tracked:

-  }, [state]);
+  }, [getItemsRefMap, months.length, headerRef, setIsHeaderExpanded]);
Review Details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits Files that changed from the base of the PR and between 5194a02 and 30e4f3c.
Files selected for processing (1)
  • packages/components/calendar/src/use-calendar-picker.ts (1 hunks)
Additional Context Used
Biome (13)
packages/components/calendar/src/use-calendar-picker.ts (13)

4-5: All these imports are only used as types.


86-86: This hook does not specify all of its dependencies: getItemsRefMap


86-86: This hook specifies more dependencies than necessary: isHeaderExpanded


109-109: This let declares a variable that is only assigned once.


117-117: This hook does not specify all of its dependencies: date.month


117-117: This hook does not specify all of its dependencies: date.year


172-172: This hook does not specify all of its dependencies: scrollTo


172-172: This hook specifies more dependencies than necessary: state


184-184: This hook does not specify all of its dependencies: getItemsRefMap


184-184: This hook does not specify all of its dependencies: months.length


184-184: This hook specifies more dependencies than necessary: state


184-184: This hook does not specify all of its dependencies: headerRef?.current?.focus


184-184: This hook does not specify all of its dependencies: setIsHeaderExpanded

Additional comments not posted (1)
packages/components/calendar/src/use-calendar-picker.ts (1)

118-119: Ensure proper handling of component state when header is not expanded.

The addition of the conditional check if (!isHeaderExpanded) return; effectively prevents unnecessary operations when the header is not expanded, aligning with the PR's objective to maintain correct month and year information.

@KumJungMin KumJungMin changed the title fix: prevent year, month change error in showMonthAndYearPickers mode (#3059) fix: prevent year, month change error in showMonthAndYearPickers mode 3059 May 27, 2024
@KumJungMin KumJungMin changed the title fix: prevent year, month change error in showMonthAndYearPickers mode 3059 fix: prevent year, month change error in showMonthAndYearPickers mode #3059 May 27, 2024
@KumJungMin KumJungMin changed the title fix: prevent year, month change error in showMonthAndYearPickers mode #3059 fix(calendar): prevent year, month change error in showMonthAndYearPickers mode #3059 May 27, 2024
@KumJungMin KumJungMin changed the title fix(calendar): prevent year, month change error in showMonthAndYearPickers mode #3059 fix(calendar): prevent year, month change in showMonthAndYearPickers mode #3059 May 27, 2024
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.

  1. please add the changeset file
  2. please add the test

@KumJungMin KumJungMin changed the title fix(calendar): prevent year, month change in showMonthAndYearPickers mode #3059 fix(calendar): prevent year, month change in showMonthAndYearPickers mode #3072 May 27, 2024
Copy link
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: 0

Review Details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits Files that changed from the base of the PR and between 30e4f3c and c13401b.
Files selected for processing (1)
  • .changeset/tidy-squids-knock.md (1 hunks)
Additional comments not posted (1)
.changeset/tidy-squids-knock.md (1)

1-5: The changeset file is well-formed and clearly documents the patch.

@KumJungMin KumJungMin changed the title fix(calendar): prevent year, month change in showMonthAndYearPickers mode #3072 fix(datePicker): prevent year, month change in showMonthAndYearPickers mode #3072 May 27, 2024
Copy link
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: 0

Review Details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits Files that changed from the base of the PR and between c13401b and 4ef3a89.
Files selected for processing (1)
  • .changeset/tidy-squids-knock.md (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • .changeset/tidy-squids-knock.md

Copy link
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: 0

Outside diff range and nitpick comments (1)
packages/components/date-picker/__tests__/date-picker.test.tsx (1)

461-461: Improve the test case description for clarity.

Consider enhancing the description of the test case to explicitly state what is being tested and expected, such as "Ensure the selected date remains unchanged when toggling the date picker in showMonthAndYearPickers mode."

Review Details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits Files that changed from the base of the PR and between 4ef3a89 and ac31e00.
Files selected for processing (1)
  • packages/components/date-picker/tests/date-picker.test.tsx (1 hunks)
Additional Context Used
Biome (20)
packages/components/date-picker/__tests__/date-picker.test.tsx (20)

27-27: Unexpected any. Specify a different type.


41-41: This variable implicitly has the any type.


67-100: This function expression can be turned into an arrow function.


102-163: This function expression can be turned into an arrow function.


164-169: This function expression can be turned into an arrow function.


170-175: This function expression can be turned into an arrow function.


192-234: This function expression can be turned into an arrow function.


235-268: This function expression can be turned into an arrow function.


269-294: This function expression can be turned into an arrow function.


295-343: This function expression can be turned into an arrow function.


344-370: This function expression can be turned into an arrow function.


373-424: This function expression can be turned into an arrow function.


425-460: This function expression can be turned into an arrow function.


461-484: This function expression can be turned into an arrow function.


372-485: This function expression can be turned into an arrow function.


7-8: Some named imports are only used as types.


68-68: This let declares a variable that is only assigned once.


70-70: This let declares a variable that is only assigned once.


76-76: This let declares a variable that is only assigned once.


103-103: This let declares a variable that is only assigned once.

Additional comments not posted (1)
packages/components/date-picker/__tests__/date-picker.test.tsx (1)

462-482: The implementation of the test case looks solid.

The test case effectively simulates the user interaction and correctly checks the expected outcomes. Good use of triggerPress and visibility checks.

@KumJungMin
Copy link
Contributor Author

KumJungMin commented May 27, 2024

i added the changelog and test code :)

스크린샷 2024-05-27 오후 10 20 31

@wingkwong

@KumJungMin KumJungMin requested a review from wingkwong May 27, 2024 13:10
@jrgarciadev
Copy link
Member

Thank you! @KumJungMin

Copy link
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: 0

Outside diff range and nitpick comments (3)
packages/components/date-picker/__tests__/date-picker.test.tsx (3)

Line range hint 67-100: Convert traditional function expressions to arrow functions for consistency and conciseness.

Consider refactoring the traditional function expressions into arrow functions. This will not only make the code more consistent with modern JavaScript practices but also enhance readability. Here's an example of how you can refactor one of the functions:

- it("should render a datepicker with a specified date", function () {
+ it("should render a datepicker with a specified date", () => {

Repeat this pattern for other function expressions throughout the file.

Also applies to: 102-163, 164-169, 170-175, 192-234, 235-268, 269-294, 295-343, 344-370, 373-424, 425-460, 461-482, 372-483


Line range hint 27-27: Improve type safety by specifying explicit types instead of any.

The use of any type reduces type safety and can lead to maintenance issues. Consider specifying more explicit types for better type checking and code clarity. For instance:

- function getTextValue(el: any) {
+ function getTextValue(el: HTMLElement) {

Also applies to: 41-41


Line range hint 68-68: Use const for variables that are not reassigned.

Variables that are not reassigned after their initial assignment should be declared with const instead of let for better code clarity and to enforce immutability where applicable. For example:

- let combobox = getAllByRole("group")[0];
+ const combobox = getAllByRole("group")[0];

Apply this change to similar cases in the file.

Also applies to: 70-70, 76-76, 103-103

Review Details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits Files that changed from the base of the PR and between ac31e00 and 56207f4.
Files selected for processing (1)
  • packages/components/date-picker/tests/date-picker.test.tsx (1 hunks)
Additional Context Used
Biome (20)
packages/components/date-picker/__tests__/date-picker.test.tsx (20)

27-27: Unexpected any. Specify a different type.


41-41: This variable implicitly has the any type.


67-100: This function expression can be turned into an arrow function.


102-163: This function expression can be turned into an arrow function.


164-169: This function expression can be turned into an arrow function.


170-175: This function expression can be turned into an arrow function.


192-234: This function expression can be turned into an arrow function.


235-268: This function expression can be turned into an arrow function.


269-294: This function expression can be turned into an arrow function.


295-343: This function expression can be turned into an arrow function.


344-370: This function expression can be turned into an arrow function.


373-424: This function expression can be turned into an arrow function.


425-460: This function expression can be turned into an arrow function.


461-482: This function expression can be turned into an arrow function.


372-483: This function expression can be turned into an arrow function.


7-8: Some named imports are only used as types.


68-68: This let declares a variable that is only assigned once.


70-70: This let declares a variable that is only assigned once.


76-76: This let declares a variable that is only assigned once.


103-103: This let declares a variable that is only assigned once.

Additional comments not posted (1)
packages/components/date-picker/__tests__/date-picker.test.tsx (1)

461-482: Ensure the new test case correctly verifies the date remains unchanged in showMonthAndYearPickers mode.

This test case effectively checks that the selected date is maintained when the picker is opened in showMonthAndYearPickers mode, aligning with the PR's objective to fix the issue where the month and year were being reset.

@wingkwong wingkwong changed the title fix(datePicker): prevent year, month change in showMonthAndYearPickers mode #3072 fix(datePicker): prevent year, month change in showMonthAndYearPickers mode May 27, 2024
Copy link
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: 0

Review Details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits Files that changed from the base of the PR and between 56207f4 and 339a7b9.
Files selected for processing (1)
  • .changeset/tidy-squids-knock.md (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • .changeset/tidy-squids-knock.md

@wingkwong wingkwong added this to the v2.4.3 milestone Jul 8, 2024
@wingkwong wingkwong merged commit 134f371 into nextui-org:canary Jul 8, 2024
7 of 8 checks passed
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.

None yet

3 participants