fix(date-picker): month and year picker scroller
Closes #3785
๐ Description
Fixing the month/year UI sync bug.
โณ๏ธ Current behavior (updates)
The month and year were incorrectly updating due to a UI rectangle intersection error. This has been removed and the data is updated directly from the value attribute.
๐ New behavior
Please describe the behavior or changes this PR adds
๐ฃ Is this a breaking change (Yes/No):
No.
๐ Additional Information
Summary by CodeRabbit
Summary by CodeRabbit
- New Features
- Introduced the
AccordionTreecomponent for hierarchical data representation. - Added an aria label for the month/year picker toggle button to enhance accessibility.
- Enhanced keyboard interaction capabilities in the calendar picker component.
- Added a new custom hook for managing key press states and scroll events.
- Introduced the
- Bug Fixes
- Improved user interface and data synchronization for the month/year picker component.
- Refactor
- Simplified scrolling behavior and focused date management in the calendar picker component.
- Chores
- Updated versions for
@nextui-org/accordionand@nextui-org/calendarpackages. - Added a new test case for the month and year picker functionality in the
DatePickercomponent.
- Updated versions for
๐ฆ Changeset detected
Latest commit: 214385fd9b329bcc62d86b38d825bdcc62a19fcf
The changes in this PR will be included in the next version bump.
This PR includes changesets to release 3 packages
| Name | Type |
|---|---|
| @nextui-org/calendar | Patch |
| @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
@buchananwill is attempting to deploy a commit to the NextUI Inc Team on Vercel.
A member of the Team first needs to authorize it.
Walkthrough
This pull request introduces updates to three packages: @nextui-org/accordion, @nextui-org/calendar, and @nextui-org/date-picker. The @nextui-org/accordion package has received a minor version update, while the @nextui-org/calendar package has been patched. A new component, AccordionTree, has been added to support hierarchical data. Additionally, significant refactoring has been performed on the useCalendarPicker function, simplifying the scrolling behavior and focused date management. Accessibility improvements have also been made to the date picker component.
Changes
| File Path | Change Summary |
|---|---|
| .changeset/serious-snails-count.md | Documented minor version update for @nextui-org/accordion and patch update for @nextui-org/calendar. Noted a fix related to the month/year picker component. |
| packages/components/accordion/src/accordion-tree.tsx | Introduced AccordionTree component with interfaces AccordionTreeItemProps and AccordionTreeProps for hierarchical data support. |
| packages/components/calendar/src/calendar-header.tsx | Added constant monthAndYearPickerToggle for the aria-label of the month/year picker toggle button, enhancing accessibility. |
| packages/components/calendar/src/calendar-picker-item.tsx | Updated CalendarPickerItem to include onKeyUp prop for handling key-up events. |
| packages/components/calendar/src/calendar-picker.tsx | Introduced onPickerItemKeyUp event handler for enhanced keyboard interaction in the calendar picker. |
| packages/components/calendar/src/use-calendar-picker.ts | Removed handleListScroll function and debounced scroll event listeners, simplifying the logic for updating the focused date in the calendar picker component. |
| packages/components/date-picker/tests/date-picker.test.tsx | Introduced a new test case for the month and year picker functionality, verifying button interactions and visibility of the dialog. |
Assessment against linked issues
| Objective | Addressed | Explanation |
|---|---|---|
| Ensure highlighted, focused, and selected values are consistent in Date Picker (#3785) | โ | Changes simplify scrolling but do not explicitly confirm resolution of the issue. |
Possibly related PRs
- #2845: Addresses issues in the DatePicker component, specifically related to the month and year pickers, which aligns with the main PR's focus on enhancing the date picker functionality.
- #3088: Prevents changes in the year and month when toggling the month and year pickers, directly relating to the updates made in the main PR regarding the date picker component.
- #3331: Resolves a bug related to incorrect year display in the
showMonthAndYearPickerscomponent, which is pertinent to the main PR's updates on the date picker. - #3416: Resolves a width clipping issue in the DatePicker, which is relevant to the overall functionality and user experience improvements noted in the main PR.
- #3773: Enhances the DatePicker by ensuring that classNames from
calendarPropsare correctly applied, which is related to the styling updates in the main PR.
Suggested labels
๐ Scope : Docs
Suggested reviewers
- wingkwong
- jrgarciadev
- ryo-manba
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.
- BEFORE: https://github.com/nextui-org/nextui/issues/3785#issuecomment-2366931481 AFTER:
https://github.com/user-attachments/assets/82b59fea-ef1c-434d-92af-58f87cdbc65f
- Issue: https://github.com/nextui-org/nextui/issues/3785
- I've parked the accordion-tree on a different branch and delete that file in this commit.
- I added a test that checks the tabindex is correctly being modified, as that is uniquely 0 for the focused month/year in the picker.
just keep one changeset file where no accordion is mentioned
Is that correct now?
The latest updates on your projects. Learn more about Vercel for Git โ๏ธ
| Name | Status | Preview | Comments | Updated (UTC) |
|---|---|---|---|---|
| nextui-docs-v2 | โ Ready (Inspect) | Visit Preview | ๐ฌ Add feedback | Sep 25, 2024 0:44am |
| nextui-storybook-v2 | โ Ready (Inspect) | Visit Preview | ๐ฌ Add feedback | Sep 25, 2024 0:44am |
Please suggest an alternative way to mark this component so the test can find it.
On Wed, 25 Sept 2024, 14:04 ีกำีก, @.***> wrote:
@.**** requested changes on this pull request.
In packages/components/calendar/src/calendar-header.tsx https://github.com/nextui-org/nextui/pull/3789#discussion_r1775134096:
@@ -99,6 +101,7 @@ export function CalendarHeader(props: CalendarHeaderProps) { return showMonthAndYearPickers ? ( <Button {...headerProps}
aria-label={monthAndYearPickerToggle}we don't hardcode aria-label internally. We can take it from users' side tho.
โ Reply to this email directly, view it on GitHub https://github.com/nextui-org/nextui/pull/3789#pullrequestreview-2328101810, or unsubscribe https://github.com/notifications/unsubscribe-auth/BBL2M6NRIQAJMCWW6L6TKF3ZYKYEDAVCNFSM6AAAAABOU7COTKVHI2DSMVQWIX3LMV43YUDVNRWFEZLROVSXG5CSMV3GSZLXHMZDGMRYGEYDCOBRGA . You are receiving this because you were mentioned.Message ID: @.***>
In the test, you can simply get the element by container.querySelector("[data-slot='header']")
Please include the content of this comment in the PR description. https://github.com/nextui-org/nextui/pull/3789#issuecomment-2367949681
@buchananwill please click re-request review once it's ready for review.
I had one more idea, which I've added. The PickerItems now also have a keyUp listener, which just calls the scrollIntoView function. This seems to be a bullet proof way of ensuring that if you've been holding down any of the directional keys, then whatever was the last key to fire (and thus has focus) is scrolled to the desired position.
I have to confess my weaker experience with writing imperative DOM events, so please if anyone with that could ponder whether this broad-brush fix could have any unexpected side-effects?
I also changed the home/end values of the keyDown event to 1 and 12, since months are 1-indexed, not zero indexed. These buttons don't work for the year picker, since 1 and 12 aren't valid years within the available range. Couldn't see an obvious way to pass in the max/min years that would be dynamically set (since it could vary with locale etc.).
Hopefully this wraps up the functionality of this component & hook?
The Home/End keys seem to already function in the original implementation. Where did you find the information about the month's index?
I also changed the home/end values of the keyDown event to 1 and 12, since months are 1-indexed, not zero indexed. These buttons don't work for the year picker, since 1 and 12 aren't valid years within the available range.
I added two additional hooks to cover the different behaviours needed for the different navigation keys:
- Home/End use a deferred focus that only triggers when the scroll ends. Otherwise, the focus event overrides the scrolling, and the element immediately snaps into view.
- Home/End also use a repeated key blocker, to prevent the value from receiving more than one update from these keys, since a. repetition of this event is meaningless b. it was playing havoc with the other scrolling/focus events/behaviours.
If you have existing hooks with the required API already in the codebase, feel free to swap them in. Equally, feel free to migrate them to a different (generic) hook folder if you want to centralize them for other scenarios to use.
I can't find any more bugs in this component.
On a side note, I prefer the simpler version where home/end cause the instant scrolling. I get that this is a minor inconsistency in the style of the UI, but the two extra control flow checks to defer the focus update and block repeat key strokes seems overly convoluted. I wouldn't be surprised to find it has negative performance implications or introduces other bugs on different systems from my own...
Let me know what you think! :-)
Yep there was one more bug where the listener wasn't clearing correctly. Fixed that now. cries in open source
On a side note, I prefer the simpler version where home/end cause the instant scrolling. I get that this is a minor inconsistency in the style of the UI, but the two extra control flow checks to defer the focus update and block repeat key strokes seems overly convoluted. I wouldn't be surprised to find it has negative performance implications or introduces other bugs on different systems from my own...
This seems to be a separate issue from the current one. If you'd like to address it, please open a new issue for further discussion.
Any updates on this PR?