Skip to content

Commit

Permalink
Merge pull request #6478 from KirilCycle/fix/date-picker-value-entering
Browse files Browse the repository at this point in the history
Fix/date picker value entering
  • Loading branch information
nitrogenous authored Apr 29, 2024
2 parents fb010b6 + 90b50cf commit 68a7593
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions components/lib/calendar/Calendar.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export const Calendar = React.memo(
const [overlayVisibleState, setOverlayVisibleState] = React.useState(false);
const [viewDateState, setViewDateState] = React.useState(null);
const [idState, setIdState] = React.useState(props.id);
const isTypingRef = React.useRef(false);

const metaData = {
props,
Expand Down Expand Up @@ -96,7 +97,7 @@ export const Calendar = React.memo(
};

const onInputBlur = (event) => {
!props.keepInvalid && updateInputfield(props.value);
updateInputfield(props.value);
props.onBlur && props.onBlur(event);
setFocusedState(false);
};
Expand Down Expand Up @@ -144,9 +145,10 @@ export const Calendar = React.memo(

const updateValueOnInput = (event, rawValue, invalidCallback) => {
try {
const value = parseValueFromString(rawValue);
const value = parseValueFromString(props.timeOnly ? rawValue.replace('_', '') : rawValue);

if (isValidSelection(value)) {
isTypingRef.current = true;
updateModel(event, value);
updateViewDate(event, value.length ? value[0] : value);
}
Expand Down Expand Up @@ -3019,7 +3021,11 @@ export const Calendar = React.memo(
const newDate = props.value;

if (previousValue !== newDate) {
updateInputfield(newDate);
if (!isTypingRef.current) {
updateInputfield(newDate);
}

isTypingRef.current = false;

// #3516 view date not updated when value set programatically
if (!visible && newDate) {
Expand Down

0 comments on commit 68a7593

Please sign in to comment.