Skip to content

Commit

Permalink
Fixed the Calendar Bug where it doesn't close after choosing a Date (#37
Browse files Browse the repository at this point in the history
)
  • Loading branch information
elliottc32 authored Dec 4, 2024
1 parent 820dc96 commit 0c5d1df
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/main/frontend/src/components/CreateLoanDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ function CreateLoanDialog() {
});
}, []);

const [calendarDialogOpen, setCalendarDialogOpen] = useState(false);

return (
<Dialog>
<DialogTrigger asChild>
Expand Down Expand Up @@ -208,6 +210,7 @@ function CreateLoanDialog() {
"w-[240px] pl-3 text-left font-normal",
!field.value && "text-muted-foreground"
)}
onClick={() => setCalendarDialogOpen(!calendarDialogOpen)}
>
{field.value ? (
format(field.value, "PPP")
Expand All @@ -222,7 +225,10 @@ function CreateLoanDialog() {
<Calendar
mode="single"
selected={field.value}
onSelect={field.onChange}
onSelect={(date) => {
field.onChange(date);
setCalendarDialogOpen(false);
}}
disabled={(date) =>
date > new Date() || date < new Date("1900-01-01")
}
Expand Down

0 comments on commit 0c5d1df

Please sign in to comment.