Skip to content

Commit 6c29f7a

Browse files
authored
fix: fix firstDayOfWeek styling in S2 DateRangePicker (#9340)
* fix: fix firstDayOfWeek styling in S2 DateRangePicker * fix lint * update chromatic story
1 parent 0e25485 commit 6c29f7a

File tree

4 files changed

+24
-7
lines changed

4 files changed

+24
-7
lines changed

packages/@react-spectrum/s2/chromatic/DateRangePicker.stories.tsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,3 +120,12 @@ export const OpenPickerWithTime: Story = {
120120
}
121121
}
122122
};
123+
124+
export const FirstDayOfWeek: Story = {
125+
args: {
126+
label: 'Date of birth',
127+
firstDayOfWeek: 'wed',
128+
value: {start: startDate, end: endDate}
129+
},
130+
play: OpenPicker.play
131+
};

packages/@react-spectrum/s2/chromatic/RangeCalendar.stories.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,8 +192,8 @@ export const InvalidRangeBothUnavailable: Story = {
192192
// Invalid range with Tuesday as first day of week
193193
export const InvalidRangeTuesdayFirstDay: Story = {
194194
args: {
195-
defaultFocusedValue: new CalendarDate(2025, 12, 20),
196-
value: {start: new CalendarDate(2025, 12, 18), end: new CalendarDate(2025, 12, 31)},
195+
defaultFocusedValue: new CalendarDate(2024, 12, 20),
196+
value: {start: new CalendarDate(2024, 12, 18), end: new CalendarDate(2024, 12, 31)},
197197
isDateUnavailable: (date: DateValue) => {
198198
return date.day >= 23 && date.day <= 29;
199199
},

packages/@react-spectrum/s2/src/Calendar.tsx

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {ActionButton, Header, HeaderContext, Heading, HeadingContext, pressScale
1414
import {
1515
Calendar as AriaCalendar,
1616
CalendarCell as AriaCalendarCell,
17+
CalendarContext as AriaCalendarContext,
1718
CalendarGrid as AriaCalendarGrid,
1819
CalendarHeaderCell as AriaCalendarHeaderCell,
1920
CalendarProps as AriaCalendarProps,
@@ -28,9 +29,11 @@ import {
2829
ContextValue,
2930
DateValue,
3031
Provider,
32+
RangeCalendarContext,
3133
RangeCalendarState,
3234
RangeCalendarStateContext,
33-
Text
35+
Text,
36+
useSlottedContext
3437
} from 'react-aria-components';
3538
import {AriaCalendarGridProps} from '@react-aria/calendar';
3639
import {baseColor, focusRing, lightDark, style} from '../style' with {type: 'macro'};
@@ -371,7 +374,7 @@ export const Calendar = /*#__PURE__*/ (forwardRef as forwardRefType)(function Ca
371374
alignItems: 'start'
372375
})}>
373376
{Array.from({length: visibleMonths}).map((_, i) => (
374-
<CalendarGrid months={i} key={i} firstDayOfWeek={props.firstDayOfWeek} />
377+
<CalendarGrid months={i} key={i} />
375378
))}
376379
</div>
377380
{isInvalid && (
@@ -387,7 +390,11 @@ export const Calendar = /*#__PURE__*/ (forwardRef as forwardRefType)(function Ca
387390
});
388391

389392
export const CalendarGrid = (props: Omit<AriaCalendarGridProps, 'children'> & PropsWithChildren & {months: number}): ReactElement => {
390-
// use isolation to start a new stacking context so that we can use zIndex -1 for the selection span.
393+
let rangeCalendarProps = useSlottedContext(RangeCalendarContext);
394+
let calendarProps = useSlottedContext(AriaCalendarContext);
395+
let firstDayOfWeek = rangeCalendarProps?.firstDayOfWeek ?? calendarProps?.firstDayOfWeek;
396+
397+
// use isolation to start a new stacking context so that we can use zIndex -1 for the selection span.
391398
return (
392399
<AriaCalendarGrid
393400
className={style({
@@ -405,7 +412,7 @@ export const CalendarGrid = (props: Omit<AriaCalendarGridProps, 'children'> & Pr
405412
</CalendarGridHeader>
406413
<CalendarGridBody className="">
407414
{(date) => (
408-
<CalendarCell date={date} firstDayOfWeek={props.firstDayOfWeek} />
415+
<CalendarCell date={date} firstDayOfWeek={firstDayOfWeek} />
409416
)}
410417
</CalendarGridBody>
411418
</AriaCalendarGrid>
@@ -510,6 +517,7 @@ const CalendarCell = (props: Omit<CalendarCellProps, 'children'> & {firstDayOfWe
510517
let isFirstWeek = weekIndex === 0;
511518
let isFirstChild = dayIndex === 0;
512519
let isLastChild = dayIndex === 6;
520+
513521
return (
514522
<AriaCalendarCell
515523
date={props.date}

packages/@react-spectrum/s2/src/RangeCalendar.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ export const RangeCalendar = /*#__PURE__*/ (forwardRef as forwardRefType)(functi
109109
alignItems: 'start'
110110
})}>
111111
{Array.from({length: visibleMonths}).map((_, i) => (
112-
<CalendarGrid months={i} key={i} firstDayOfWeek={props.firstDayOfWeek} />
112+
<CalendarGrid months={i} key={i} />
113113
))}
114114
</div>
115115
{isInvalid && (

0 commit comments

Comments
 (0)