mirror of
https://github.com/rustmailer/bichon.git
synced 2026-08-03 07:48:34 +02:00
fix: Search before date picker: go back to selected date #148
This commit is contained in:
@@ -10,6 +10,7 @@ import {
|
||||
import i18n from '@/i18n'
|
||||
import { dateFnsLocaleMap } from '@/lib/utils'
|
||||
import { enUS } from 'date-fns/locale'
|
||||
import { useEffect, useState } from 'react'
|
||||
|
||||
type DatePickerProps = {
|
||||
selected: Date | undefined
|
||||
@@ -26,6 +27,14 @@ export function DatePicker({
|
||||
const currentLang = i18n.language.toLowerCase().replace('_', '-');
|
||||
const dateLocale = dateFnsLocaleMap[currentLang] || enUS;
|
||||
|
||||
const [month, setMonth] = useState<Date | undefined>(selected || new Date());
|
||||
|
||||
useEffect(() => {
|
||||
if (selected) {
|
||||
setMonth(selected);
|
||||
}
|
||||
}, [selected]);
|
||||
|
||||
return (
|
||||
<Popover>
|
||||
<PopoverTrigger asChild>
|
||||
@@ -47,6 +56,8 @@ export function DatePicker({
|
||||
mode='single'
|
||||
captionLayout='dropdown'
|
||||
selected={selected}
|
||||
month={month}
|
||||
onMonthChange={setMonth}
|
||||
onSelect={onSelect}
|
||||
disabled={(date: Date) =>
|
||||
date > new Date() || date < new Date('1900-01-01')
|
||||
|
||||
Reference in New Issue
Block a user