Skip to content

Commit

Permalink
Removed the value sanitization logic while rendering and the touched …
Browse files Browse the repository at this point in the history
…state.
  • Loading branch information
deepakjosp committed Nov 28, 2024
1 parent 6b8aeba commit cb38e83
Showing 1 changed file with 3 additions and 23 deletions.
26 changes: 3 additions & 23 deletions src/components/DatePicker/index.jsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
import React, {
forwardRef,
useState,
useEffect,
useMemo,
useCallback,
} from "react";
import React, { forwardRef, useState, useEffect, useCallback } from "react";

import { DatePicker as AntDatePicker } from "antd";
import classnames from "classnames";
Expand Down Expand Up @@ -68,7 +62,6 @@ const DatePicker = forwardRef(
const [value, setValue] = useState(inputValue);
const [mode, setMode] = useState(picker);
const [pickerValue, setPickerValue] = useState();
const [touched, setTouched] = useState(false);
const id = useId(otherProps.id);
const datePickerRef = useSyncedRef(ref);

Expand Down Expand Up @@ -97,7 +90,6 @@ const DatePicker = forwardRef(

const allowed = getAllowedValue(getTimezoneAppliedDateTime(date));
setValue(allowed);
setTouched(true);

return onChange(allowed, formattedString(allowed, dateFormat));
};
Expand All @@ -117,29 +109,17 @@ const DatePicker = forwardRef(
);
};

const { sanitizedValue, sanitizedDefaultValue } = useMemo(() => {
let sanitizedDefaultValue = convertToDayjsObjects(defaultValue);
let sanitizedValue = convertToDayjsObjects(value);

if (touched) {
sanitizedValue = getAllowedValue(sanitizedValue);
sanitizedDefaultValue = getAllowedValue(sanitizedDefaultValue);
}

return { sanitizedDefaultValue, sanitizedValue };
}, [defaultValue, value, touched, getAllowedValue]);

return (
<Provider>
<div className="neeto-ui-input__wrapper">
{label && <Label {...{ required, ...labelProps }}>{label}</Label>}
<Component
data-cy={label ? `${hyphenize(label)}-input` : "picker-input"}
defaultValue={sanitizedDefaultValue}
defaultValue={convertToDayjsObjects(defaultValue)}
placeholder={placeholder ?? format}
ref={datePickerRef}
showTime={showTime && { format: timeFormat, ...timePickerProps }}
value={sanitizedValue}
value={convertToDayjsObjects(value)}
className={classnames("neeto-ui-date-input", [className], {
"neeto-ui-date-input--small": size === "small",
"neeto-ui-date-input--medium": size === "medium",
Expand Down

0 comments on commit cb38e83

Please sign in to comment.