Skip to content

selectionAlignment is not exposed in CalendarProps #8149

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
Cyral opened this issue Apr 27, 2025 · 2 comments
Open

selectionAlignment is not exposed in CalendarProps #8149

Cyral opened this issue Apr 27, 2025 · 2 comments

Comments

@Cyral
Copy link

Cyral commented Apr 27, 2025

Provide a general summary of the issue here

I want to be able to create multi-month calendars where the first month is always the current month, rather than centering the current month. Looking through the code to see how the month is centered (so I could reverse it), I found that this is actually already an option in useCalendarState with selectionAlignment. However, the selectionAlignment is not included in the CalendarProps or RangeCalendarProps, so TypeScript complains, even though adding <Calendar selectionAlignment="center"> fixes the issue for Calendar components, although not RangeCalendar components, where the code is set to always center it (cannot be specified by the RangeCalendarStateOptions)

For example, with it being April, I want to see a visibleDuration={months:3} calendar that looks like:

April | May | June

Rather than:

March | April | May

🤔 Expected Behavior?

Calendar and RangeCalendar props should include the following, like useCalendarState line 54:

 /** Determines how to align the initial selection relative to the visible date range. */
  selectionAlignment?: 'start' | 'center' | 'end'

😯 Current Behavior

selectionAlignment is not exposed

💁 Possible Solution

No response

🔦 Context

No response

🖥️ Steps to Reproduce

<Calendar selectionAlignment="start"> works because the props are passed to useCalendarState, but TypeScript complains that selectionAlignment doesn't exist.

Version

3.39.0

What browsers are you seeing the problem on?

Chrome

If other, please specify.

No response

What operating system are you using?

Mac

🧢 Your Company/Team

No response

🕷 Tracking Issue

No response

@yihuiliao
Copy link
Member

Seems fine. We'll want to make sure that the user provided alignment overrides what useRangeCalendarState calculates

let alignment: 'center' | 'start' = 'center';
if (value && value.start && value.end) {
let start = alignCenter(toCalendarDate(value.start), visibleDuration, locale, minValue, maxValue);
let end = start.add(visibleDuration).subtract({days: 1});
if (value.end.compare(end) > 0) {
alignment = 'start';
}
}

@yihuiliao
Copy link
Member

By the way, we would really appreciate a contribution as the team has other priorities at the moment. Let us know if you need any additional guidance or help!

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

No branches or pull requests

2 participants