import { addMonths } from 'date-fns'; import { CaptionProps } from 'components/Caption/Caption'; import { CaptionLabel } from 'components/CaptionLabel'; import { MonthsDropdown } from 'components/MonthsDropdown'; import { YearsDropdown } from 'components/YearsDropdown'; import { useDayPicker } from 'contexts/DayPicker'; import { useNavigation } from 'contexts/Navigation'; import { MonthChangeEventHandler } from 'types/EventHandlers'; /** * Render a caption with the dropdowns to navigate between months and years. */ export function CaptionDropdowns(props: CaptionProps): JSX.Element { const { classNames, styles, components } = useDayPicker(); const { goToMonth } = useNavigation(); const handleMonthChange: MonthChangeEventHandler = (newMonth) => { goToMonth( addMonths(newMonth, props.displayIndex ? -props.displayIndex : 0) ); }; const CaptionLabelComponent = components?.CaptionLabel ?? CaptionLabel; const captionLabel = ( ); return (
{/* Caption label is visually hidden but for a11y. */}
{captionLabel}
); }