diff --git a/frontend/src/Components/DatePicker/DatePicker.tsx b/frontend/src/Components/DatePicker/DatePicker.tsx index 4e6e9c7b9..e978c5f38 100644 --- a/frontend/src/Components/DatePicker/DatePicker.tsx +++ b/frontend/src/Components/DatePicker/DatePicker.tsx @@ -1,10 +1,10 @@ import { Icon } from '@iconify/react'; import classNames from 'classnames'; import { format } from 'date-fns'; -import React, { useMemo } from 'react'; +import React, { forwardRef, useMemo } from 'react'; import { useState } from 'react'; import { useTranslation } from 'react-i18next'; -import { Button, MiniCalendar } from '~/Components'; +import { MiniCalendar } from '~/Components'; import { useClickOutside } from '~/hooks'; import { KEY } from '~/i18n/constants'; import styles from './DatePicker.module.scss'; @@ -21,56 +21,52 @@ type DatePickerProps = { maxDate?: Date; }; -export function DatePicker({ - value: initialValue, - onChange, - disabled, - label, - buttonClassName, - minDate, - maxDate, -}: DatePickerProps) { - const isControlled = initialValue !== undefined; +export const DatePicker = forwardRef( + ({ value: initialValue, onChange, disabled, label, buttonClassName, minDate, maxDate }, ref) => { + const isControlled = initialValue !== undefined; - const [date, setDate] = useState(null); - const [open, setOpen] = useState(false); + const [date, setDate] = useState(null); + const [open, setOpen] = useState(false); - const { t } = useTranslation(); + const { t } = useTranslation(); - const clickOutsideRef = useClickOutside(() => setOpen(false)); + const clickOutsideRef = useClickOutside(() => setOpen(false)); - const value = useMemo(() => { - if (isControlled) { - return initialValue; - } - return date; - }, [isControlled, initialValue, date]); + const value = useMemo(() => { + if (isControlled) { + return initialValue; + } + return date; + }, [isControlled, initialValue, date]); - function handleChange(d: Date | null) { - setDate(d); - onChange?.(d); - } + function handleChange(d: Date | null) { + setDate(d); + onChange?.(d); + } - return ( -
- -
- + return ( +
+ +
+ +
-
- ); -} + ); + }, +); +DatePicker.displayName = 'DatePicker';