diff --git a/packages/x-date-pickers/src/internals/hooks/usePickerState.ts b/packages/x-date-pickers/src/internals/hooks/usePickerState.ts index 4c51be4916144..aab71815e7dcc 100644 --- a/packages/x-date-pickers/src/internals/hooks/usePickerState.ts +++ b/packages/x-date-pickers/src/internals/hooks/usePickerState.ts @@ -72,6 +72,7 @@ export const usePickerState = ( } const [initialDate, setInitialDate] = React.useState(draftState.committed); + const [wrapper, setWrapper] = React.useState(null); // Mobile keyboard view is a special case. // When it's open picker should work like closed, cause we are just showing text field @@ -97,7 +98,11 @@ export const usePickerState = ( open: isOpen, onClear: () => acceptDate(valueManager.emptyValue, true), onAccept: () => acceptDate(draftState.draft, true), - onDismiss: () => acceptDate(initialDate, true), + onDismiss: () => + acceptDate( + wrapper === 'mobile' || !disableCloseOnSelect ? initialDate : draftState.draft, + true, + ), onSetToday: () => { const now = utils.date() as TDateValue; dispatch({ type: 'update', payload: now }); @@ -112,6 +117,7 @@ export const usePickerState = ( draftState.draft, valueManager.emptyValue, initialDate, + wrapper, ], ); @@ -125,6 +131,7 @@ export const usePickerState = ( wrapperVariant: WrapperVariant, selectionState: PickerSelectionState = 'partial', ) => { + setWrapper(wrapperVariant); dispatch({ type: 'update', payload: newDate }); if (selectionState === 'partial') { acceptDate(newDate, false);