CaptionLayout dropdown descending #2817
-
How can I change the sort direction for the year dropdown to descending so the current year is the first entry? |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 2 replies
-
Interesting case @joshuarost ! You could use a custom https://codesandbox.io/p/sandbox/ph4pvd function SelectWithReversedYears(
props: SelectHTMLAttributes<HTMLSelectElement>
) {
if (props["aria-label"] === "Choose the Year") {
return (
<Select {...props}>
{/* Reverse the select options */}
{React.Children.toArray(props.children).reverse()}
</Select>
);
}
return <Select {...props} />;
}
export default function App() {
return (
<DayPicker
captionLayout="dropdown"
components={{
Select: SelectWithReversedYears,
}}
/>
);
} Screenshot: ![]() |
Beta Was this translation helpful? Give feedback.
-
We may want to add this behavior as a prop. Tracked in #2819 Thanks for your suggestion! |
Beta Was this translation helpful? Give feedback.
-
@joshuarost we just released v9.9.0, which includes a <DayPicker captionLayout="dropdown" reverseYears /> See it in action in the playground: ![]() |
Beta Was this translation helpful? Give feedback.
@joshuarost we just released v9.9.0, which includes a
reverseYears
prop that does exactly this. No need to use a custom component anymore!See it in action in the playground: