Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/date picker value entering #6478

Merged
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
Loading