Description
Provide a general summary of the issue here
I'm creating a mobile calendar and when I scroll up I want to add the previous months. I am doing this by increasing the visibleDuration.
When the visibleMonths is updated the value of the startDate
is not recalculated and therefore my calendar never goes before the initial startDate.
🤔 Expected Behavior?
When updating visibleDuration
the startDate
will be recalculated.
😯 Current Behavior
When updating visibleDuration
the startDate
is not recalculated.
💁 Possible Solution
I have copied the source code and amended locally and made the change below
Before:
let [startDate, setStartDate] = useState(() => {
switch (selectionAlignment) {
case 'start':
return alignStart(focusedDate, visibleDuration, locale, minValue, maxValue);
case 'end':
return alignEnd(focusedDate, visibleDuration, locale, minValue, maxValue);
case 'center':
default:
return alignCenter(focusedDate, visibleDuration, locale, minValue, maxValue);
}
});
After:
const calculateStartDate = () => {
switch (selectionAlignment) {
case 'start':
return alignStart(
focusedDate,
visibleDuration,
locale,
minValue,
maxValue
)
case 'end':
return alignEnd(
focusedDate,
visibleDuration,
locale,
minValue,
maxValue
)
case 'center':
default:
return alignCenter(
focusedDate,
visibleDuration,
locale,
minValue,
maxValue
)
}
}
const [startDate, setStartDate] = useState(() => calculateStartDate())
const visibleDurationRef = useRef(visibleDuration)
useEffect(() => {
if (visibleDuration.months !== visibleDurationRef.current.months) {
visibleDurationRef.current = visibleDuration
setStartDate(calculateStartDate())
}
}, [visibleDuration])
If you would like me to open a PR let me know and I can also create a CodeSandbox or similar to show.
🔦 Context
No response
🖥️ Steps to Reproduce
to follow
Version
3.6.0
What browsers are you seeing the problem on?
Chrome
If other, please specify.
No response
What operating system are you using?
MacOS
🧢 Your Company/Team
No response
🕷 Tracking Issue
No response
Activity
LFDanLu commentedon Mar 7, 2025
I must have missed this somehow when looking for any duplicates of #7876, sorry about that! I think what you have is promising, would you like to also try to add
locale
as mentioned above to the useEffect so that the start date also updates on locale change?paddyjoneill commentedon Apr 30, 2025
Hi @LFDanLu ,
I'm trying to open a PR for this but am unable to push to the repo.
Can you help?
LFDanLu commentedon Apr 30, 2025
Sure, did you make a fork of the repo from which you are trying to open the PR?
paddyjoneill commentedon Apr 30, 2025
i just pulled the repo and made a branch.
Is there any documentation on the process?
LFDanLu commentedon Apr 30, 2025
We have https://react-spectrum.adobe.com/contribute.html#pull-requests, but feel free to let me know if you have any additional questions!
paddyjoneill commentedon May 1, 2025
#8177
@LFDanLu
I opened a draft PR, still need to add a test for this though
Should I add it here:
packages/@react-aria/calendar/test/useCalendar.test.js
LFDanLu commentedon May 1, 2025
That should be fine or you could add a test to
Calendar.test.js
if you would prefer to test it against the React Aria Components calendar implementation instead