Skip to content

Commit

Permalink
Code review: Flavien
Browse files Browse the repository at this point in the history
Better support for custom calendar header components
  • Loading branch information
LukasTy committed Jun 19, 2024
1 parent cf5c4e8 commit db9bc95
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,6 @@ const DateRangeCalendar = React.forwardRef(function DateRangeCalendar<
timezone,
slots,
slotProps,
labelId: `${id}-grid`,
},
ownerState: props,
});
Expand Down Expand Up @@ -551,10 +550,16 @@ const DateRangeCalendar = React.forwardRef(function DateRangeCalendar<
<Watermark packageName="x-date-pickers-pro" releaseInfo={releaseInfo} />
{calendarMonths.map((monthIndex) => {
const month = visibleMonths[monthIndex];
const labelId = `${id}-grid-${monthIndex}-label`;

return (
<DateRangeCalendarMonthContainer key={monthIndex} className={classes.monthContainer}>
<CalendarHeader<TDate> {...calendarHeaderProps} month={month} monthIndex={monthIndex} />
<CalendarHeader<TDate>
{...calendarHeaderProps}
month={month}
monthIndex={monthIndex}
labelId={labelId}
/>
<DayCalendarForRange<TDate>
className={classes.dayCalendar}
{...calendarState}
Expand All @@ -578,7 +583,7 @@ const DateRangeCalendar = React.forwardRef(function DateRangeCalendar<
fixedWeekNumber={fixedWeekNumber}
displayWeekNumber={displayWeekNumber}
timezone={timezone}
gridLabelId={`${id}-grid-${monthIndex}-label`}
gridLabelId={labelId}
/>
</DateRangeCalendarMonthContainer>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,7 @@ const PickersRangeCalendarHeader = React.forwardRef(function PickersRangeCalenda
});

if (calendars === 1) {
return (
<PickersCalendarHeader {...other} labelId={`${labelId}-${monthIndex}-label`} ref={ref} />
);
return <PickersCalendarHeader {...other} labelId={labelId} ref={ref} />;
}

const selectNextMonth = () => onMonthChange(utils.addMonths(currentMonth, 1), 'left');
Expand All @@ -78,7 +76,7 @@ const PickersRangeCalendarHeader = React.forwardRef(function PickersRangeCalenda
nextLabel={localeText.nextMonth}
slots={slots}
slotProps={slotProps}
labelId={`${labelId}-${monthIndex}-label`}
labelId={labelId}
>
{utils.formatByString(month, format ?? `${utils.formats.month} ${utils.formats.year}`)}
</PickersRangeCalendarHeaderContentMultipleCalendars>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ export interface PickersCalendarHeaderProps<TDate extends PickerValidDate>
view: DateView;
reduceAnimations: boolean;
onViewChange?: (view: DateView) => void;
/**
* Id of the calendar text element.
* It is used to establish an `aria-labelledby` relationship with the calendar `grid` element.
*/
labelId?: string;
/**
* Override or extend the styles applied to the component.
Expand Down

0 comments on commit db9bc95

Please sign in to comment.