Skip to content

Commit

Permalink
handle disableCloseOnSelect for both mobile and desktop
Browse files Browse the repository at this point in the history
  • Loading branch information
yyq1025 committed Apr 8, 2022
1 parent 371be29 commit cd3e46e
Showing 1 changed file with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ export const usePickerState = <TInput, TDateValue>(
}

const [initialDate, setInitialDate] = React.useState<TDateValue>(draftState.committed);
const [wrapper, setWrapper] = React.useState<WrapperVariant>(null);

// Mobile keyboard view is a special case.
// When it's open picker should work like closed, cause we are just showing text field
Expand All @@ -97,7 +98,11 @@ export const usePickerState = <TInput, TDateValue>(
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 });
Expand All @@ -112,6 +117,7 @@ export const usePickerState = <TInput, TDateValue>(
draftState.draft,
valueManager.emptyValue,
initialDate,
wrapper,
],
);

Expand All @@ -125,6 +131,7 @@ export const usePickerState = <TInput, TDateValue>(
wrapperVariant: WrapperVariant,
selectionState: PickerSelectionState = 'partial',
) => {
setWrapper(wrapperVariant);
dispatch({ type: 'update', payload: newDate });
if (selectionState === 'partial') {
acceptDate(newDate, false);
Expand Down

0 comments on commit cd3e46e

Please sign in to comment.