import { forwardRef, useImperativeHandle, useRef } from 'react'; import { Box, Icon, TapArea, TextField, useDefaultLabel, useExperimentalTheme } from 'morphe'; import VRDateInput from './VRDateInput'; import styles from '../DatePicker.css'; // InjectedProps are props that Datepicker adds on to DatePickerTextField. // Datepicker takes this props and then funnels them to DatePickerTextField. // See https://github.com/Hacker0x01/react-datepicker/blob/769d960d35d18f06bdee1b62a53d739ef4f0c39a/src/index.jsx#L844 type InjectedProps = { disabled?: boolean; id: string; name?: string; label?: string; onBlur?: (event: React.FocusEvent) => void; onChange?: (event: React.ChangeEvent) => void; onClick?: () => void; onFocus?: (event: React.FocusEvent) => void; onPassthroughFocus?: () => void; onKeyDown?: (event: React.KeyboardEvent) => void; placeholder?: string; readOnly?: boolean; value?: string; errorMessage?: string; helperText?: string; size?: 'md' | 'lg'; }; type Props = { id: string; } & InjectedProps; const DateInputWithForwardRef = forwardRef(function DateInput( { disabled, id, label, name, onChange, onClick, onBlur, onFocus, onPassthroughFocus, onKeyDown, placeholder, readOnly, value, errorMessage, helperText, size, }: Props, ref, ) { const innerRef = useRef(null); // @ts-expect-error - TS2322 - Type 'HTMLDivElement | HTMLInputElement | null' is not assignable to type 'HTMLInputElement'. useImperativeHandle(ref, () => innerRef.current); const { openCalendar } = useDefaultLabel('DatePicker'); const theme = useExperimentalTheme(); if (theme.MAIN) { return ( onBlur?.(data.event)} onChange={(data) => onChange?.(data.event)} onClick={onClick} onFocus={(data) => { onPassthroughFocus?.(); onFocus?.(data.event); }} onKeyDown={(data) => onKeyDown?.(data.event)} placeholder={placeholder} readOnly={readOnly} size={size} value={value} /> ); } return ( onBlur?.(data.event)} onChange={(data) => onChange?.(data.event)} onClick={onClick} onFocus={(data) => { onPassthroughFocus?.(); onFocus?.(data.event); }} onKeyDown={(data) => onKeyDown?.(data.event)} placeholder={placeholder} readOnly={readOnly} size="lg" value={value} />
{ innerRef.current?.focus(); }} rounding="circle" tabIndex={-1} >
); }); DateInputWithForwardRef.displayName = 'DatePickerTextField'; export default DateInputWithForwardRef;