Skip to content

Commit b4bed2f

Browse files
committed
Add missing valueProp
1 parent 29db319 commit b4bed2f

File tree

1 file changed

+15
-12
lines changed

1 file changed

+15
-12
lines changed

src/Components/DatePicker.tsx

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import DatePickerPopup from "./DatePickerPopup"
66
import DatePickerProvider, { DatePickerContext } from "./DatePickerProvider"
77

88
export interface IDatePickerProps {
9-
value?: Date,
9+
value?: Date
1010
children?: ReactElement | ReactNode
1111
options?: IOptions
1212
onChange?: (date: Date) => void
@@ -19,12 +19,14 @@ export interface IDatePickerProps {
1919
const DatePicker = ({ value, children, options, onChange, classNames, show, setShow, selectedDateState }: IDatePickerProps) => (
2020
<div className={twMerge("w-full", classNames)}>
2121
<DatePickerProvider options={options} onChange={onChange} show={show} setShow={setShow} selectedDateState={selectedDateState}>
22-
<DatePickerMain value={value} options={options}>{children}</DatePickerMain>
22+
<DatePickerMain value={value} options={options}>
23+
{children}
24+
</DatePickerMain>
2325
</DatePickerProvider>
2426
</div>
2527
)
2628

27-
const DatePickerMain = ({ value, options: customOptions, children }: { value?: Date, options?: IOptions; children?: ReactElement }) => {
29+
const DatePickerMain = ({ value, options: customOptions, children }: { value?: Date; options?: IOptions; children?: ReactElement }) => {
2830
const options = { ...defaultOptions, ...customOptions }
2931
const { setShow, show } = useContext(DatePickerContext)
3032
const InputRef = useRef<HTMLInputElement>(null)
@@ -57,6 +59,7 @@ const DatePickerMain = ({ value, options: customOptions, children }: { value?: D
5759
<Input
5860
ref={InputRef}
5961
idProp={options?.inputIdProp}
62+
valueProp={value}
6063
nameProp={options?.inputNameProp}
6164
placeholderProp={options?.inputPlaceholderProp}
6265
dateFormat={options?.inputDateFormatProp}
@@ -68,16 +71,16 @@ const DatePickerMain = ({ value, options: customOptions, children }: { value?: D
6871
)
6972
}
7073

71-
const Input = forwardRef<HTMLInputElement, { idProp ?: string, valueProp?: Date, nameProp?: string, placeholderProp ?: string, dateFormat?: Intl.DateTimeFormatOptions }>((props, ref) => {
74+
const Input = forwardRef<HTMLInputElement, { idProp?: string; valueProp?: Date; nameProp?: string; placeholderProp?: string; dateFormat?: Intl.DateTimeFormatOptions }>((props, ref) => {
7275
const { setShow, selectedDate, showSelectedDate, options, getFormattedDate } = useContext(DatePickerContext)
73-
74-
const nameProp = props.nameProp || "date";
75-
const idProp = props.idProp || nameProp;
76-
const placeholderProp = props.placeholderProp || "Select Date";
77-
const valueProp = props.valueProp;
7876

79-
const format = props.dateFormat || null;
80-
77+
const nameProp = props.nameProp || "date"
78+
const idProp = props.idProp || nameProp
79+
const placeholderProp = props.placeholderProp || "Select Date"
80+
const valueProp = props.valueProp
81+
82+
const format = props.dateFormat || null
83+
8184
return (
8285
<input
8386
ref={ref}
@@ -89,7 +92,7 @@ const Input = forwardRef<HTMLInputElement, { idProp ?: string, valueProp?: Date,
8992
options?.theme?.input
9093
)}
9194
placeholder={placeholderProp}
92-
value={value ? getFormattedDate(valueProp, format) : selectedDate && showSelectedDate ? getFormattedDate(selectedDate, format) : ""}
95+
value={valueProp ? getFormattedDate(valueProp, format) : selectedDate && showSelectedDate ? getFormattedDate(selectedDate, format) : ""}
9396
onFocus={() => setShow(true)}
9497
readOnly
9598
/>

0 commit comments

Comments
 (0)