Skip to content

Commit d2593c5

Browse files
committed
fix(date-range-picker): fix preset buttons calendar navigation
1 parent f582fc3 commit d2593c5

File tree

1 file changed

+27
-6
lines changed

1 file changed

+27
-6
lines changed

apps/docs/content/components/date-range-picker/presets.raw.jsx

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import React from "react";
12
import {DateRangePicker, Radio, RadioGroup, Button, ButtonGroup, cn} from "@heroui/react";
23
import {
34
today,
@@ -15,6 +16,7 @@ export default function App() {
1516
end: today(getLocalTimeZone()).add({days: 7}),
1617
};
1718
let [value, setValue] = React.useState(defaultDate);
19+
let [focusedValue, setFocusedValue] = React.useState(defaultDate.start);
1820

1921
let {locale} = useLocale();
2022
let formatter = useDateFormatter({dateStyle: "full"});
@@ -81,20 +83,39 @@ export default function App() {
8183
variant="bordered"
8284
>
8385
<Button
84-
onPress={() =>
85-
setValue({
86+
onPress={() => {
87+
const thisWeek = {
8688
start: now,
8789
end: now.add({days: 7}),
88-
})
89-
}
90+
};
91+
92+
setValue(thisWeek);
93+
setFocusedValue(thisWeek.start);
94+
}}
9095
>
9196
This week
9297
</Button>
93-
<Button onPress={() => setValue(nextWeek)}>Next week</Button>
94-
<Button onPress={() => setValue(nextMonth)}>Next month</Button>
98+
<Button
99+
onPress={() => {
100+
setValue(nextWeek);
101+
setFocusedValue(nextWeek.start);
102+
}}
103+
>
104+
Next week
105+
</Button>
106+
<Button
107+
onPress={() => {
108+
setValue(nextMonth);
109+
setFocusedValue(nextMonth.start);
110+
}}
111+
>
112+
Next month
113+
</Button>
95114
</ButtonGroup>
96115
}
97116
calendarProps={{
117+
focusedValue: focusedValue,
118+
onFocusChange: setFocusedValue,
98119
nextButtonProps: {
99120
variant: "bordered",
100121
},

0 commit comments

Comments
 (0)