Skip to content

feat: add navLayout prop #2755

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 20 commits into
base: main
Choose a base branch
from
Open

feat: add navLayout prop #2755

wants to merge 20 commits into from

Conversation

gpbl
Copy link
Owner

@gpbl gpbl commented May 4, 2025

This PR introduces the new navLayout prop, which fixes #2629 and provides a new layout option for navigation:

  • around: Navigation buttons are displayed on either side of the caption.
  • after: Navigation buttons are displayed after the caption

Screen Shot 2025-05-04 at 08 10 34

Screen Shot 2025-05-04 at 08 22 06

This change also accounts for cases where the number of months displayed is greater than one.

Screen Shot 2025-05-04 at 08 21 54

Known Issues

  • During transitions, the navigation buttons appear duplicated. This issue can likely be resolved by modifying the useAnimation hook.
Screen.Recording.2025-05-04.at.8.14.09.AM.mov

Notes on Reusing the Nav Component

I considered adding skipNextButton or skipPrevButton props to the Nav component to reuse it. However, I am not sure if as having multiple <nav> elements with the same label is correct. Reusing Nav would potentially result in a breaking change.

gpbl added 4 commits May 4, 2025 08:04
Signed-off-by: gpbl <io@gpbl.dev>
Signed-off-by: gpbl <io@gpbl.dev>
Signed-off-by: gpbl <io@gpbl.dev>
Signed-off-by: gpbl <io@gpbl.dev>
@gpbl gpbl requested a review from rodgobbi May 4, 2025 13:21
@gpbl
Copy link
Owner Author

gpbl commented May 4, 2025

@rodgobbi still refining the change, wanted to share with you this proof-of-concept - what do you think?

@rodgobbi
Copy link
Collaborator

rodgobbi commented May 4, 2025

@gpbl

Lemme fix the animation issues, I'll push changes to your branch.

@rodgobbi

This comment was marked as outdated.

@rodgobbi

This comment was marked as outdated.

Copy link
Collaborator

@rodgobbi rodgobbi left a comment

Choose a reason for hiding this comment

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

@gpbl

The approach looks good indeed.
I understand better now, using explicit values for the prop fixes #2629.

And I imagine we could make the after value the default one in the upcoming breaking change.

My only suggestion is to try to move the new nav layout elements out of the months.map, as they don't repeat per month in the calendar, therefore conceptually they should be out of the months.map logic.
And I expect that doing so would simplify the CSS styles and perhaps fix the issue happening with the animation.

@@ -377,6 +381,24 @@ export function DayPicker(initialProps: DayPickerProps) {
displayIndex={displayIndex}
calendarMonth={calendarMonth}
>
{navLayout === "around" &&
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think we could move this out of the months.map scope, as it is absolute positioned, I expect we could mount one button before the map and another one after.
If you tried this already, lemme know if there are any issues.

This comment also applies to the after navLayout, which is mounted within the map scope.

Perhaps doing that fixes the issue that happens during the animation.

Signed-off-by: gpbl <io@gpbl.dev>
@gpbl
Copy link
Owner Author

gpbl commented May 4, 2025

Thank you, @rodgobbi, for your quick review and suggestions! Apologies for not being clear about how to test this (I use the playground in the website).

And I imagine we could make the after value the default one in the upcoming breaking change.

Yes, exactly! That is the plan.

I think we could move this out of the months.map scope, as it is absolutely positioned. I expect we could mount one button before the map and another one after.
If you tried this already, let me know if there are any issues.

The reason I placed the navigation buttons inside the loop is to align them with the caption when displaying multiple months across multiple rows. I can't make assumptions about how large is that container...

Screenshot 2025-05-04 at 10 42 06 AM

Moving the buttons outside the months container makes it challenging to position them correctly without altering the element tree.

I believe the animation glitch is because these elements are not being hidden while duplicating the container during the transition (the test failure seems to confirm that). If you have some time to look at it I'd be happy to let you fix it!

gpbl added 5 commits May 4, 2025 12:05
Signed-off-by: gpbl <io@gpbl.dev>
Signed-off-by: gpbl <io@gpbl.dev>
Signed-off-by: gpbl <io@gpbl.dev>
Signed-off-by: gpbl <io@gpbl.dev>
Signed-off-by: gpbl <io@gpbl.dev>
@rodgobbi
Copy link
Collaborator

rodgobbi commented May 4, 2025

@gpbl

I see, I think I was testing the branch too soon, even before you pushed some changes required for the nav buttons to be aligned with the caption.
It makes sense to mount with the month element to align it properly.

For the after layout, I see different issues, one of which is a bug is that multiple buttons are being mounted, one for each month; we should mount only one.
The glitch also happens because of the styles manually set to the month container during the animation, which causes the relative container for the nav buttons to change from the root element to the month in the calendar.

What do you think of rendering only the after nav buttons outside the months.map? After the calendar months.
I think this would fix the glitch and the current issue of multiple buttons rendered, and it also makes more sense to be outside the map logic.

I can test this and push the changes if it works.

gpbl added 9 commits May 4, 2025 16:24
Signed-off-by: gpbl <io@gpbl.dev>
Signed-off-by: gpbl <io@gpbl.dev>
Signed-off-by: gpbl <io@gpbl.dev>
Signed-off-by: gpbl <io@gpbl.dev>
Signed-off-by: gpbl <io@gpbl.dev>
Signed-off-by: gpbl <io@gpbl.dev>
Signed-off-by: gpbl <io@gpbl.dev>
Signed-off-by: gpbl <io@gpbl.dev>
Signed-off-by: gpbl <io@gpbl.dev>
@gpbl
Copy link
Owner Author

gpbl commented May 4, 2025

Thanks @rodgobbi I got what you mean.

For the around layout - I could fix the animation glitch by changing useAnimation (I I'd like to give a review to these query selectors soon or later).

For the after layout, I see different issues, one of which is a bug is that multiple buttons are being mounted, one for each month; we should mount only one.

Fixed,

The glitch also happens because of the styles manually set to the month container during the animation, which causes the relative container for the nav buttons to change from the root element to the month in the calendar.

I'm not sure if I can replicate this again - I'll double check.

What do you think of rendering only the after nav buttons outside the months.map?

Also in this case, we want it right after the caption to preserve the tab behavior.

@gpbl gpbl marked this pull request as ready for review May 4, 2025 22:25
Signed-off-by: gpbl <io@gpbl.dev>
@gpbl
Copy link
Owner Author

gpbl commented May 4, 2025

I confirm the glitch with multiple months is still there:

Untitled.mov

I will give a look to it tomorrow with a fresh mind!

@rodgobbi
Copy link
Collaborator

rodgobbi commented May 6, 2025

@gpbl thanks for checking, lemme try to fix it later and I'll message you again with the results 👍

@rodgobbi
Copy link
Collaborator

rodgobbi commented May 6, 2025

@gpbl
The line that is causing the issue in the animation is this one.

I need to think more about how to work around that. It's very tricky to support the current after nav layout UX with the current animation logic.

On the flip side, the glitch happens when there are multiple months wrapping to the next line, and in the same scenario the tabbing flow is also problematic:

Screen.Recording.2025-05-06.at.18.59.50.mov

I wasn't able to reproduce the glitch happening to the first displayed month like in #2755 (comment).

What do you think of always anchoring the after nav buttons to the last displayed month?

Like the last nav button for the around layout.
This would keep the tabbing flow consistent following the visual order, and this glitch would not happen because the nav buttons' position during animation would be the same as the non-animating state.

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.

Tab order is not in visual order when captionLayout is "dropdown"
2 participants