From 97a2c005beef761c37082e2ab4741b67382db33c Mon Sep 17 00:00:00 2001 From: Dmitriy Kovalenko Date: Sat, 27 Jul 2019 21:17:24 +0300 Subject: [PATCH 1/3] Fix dispatching 2 onChange events with variant="inline" --- lib/src/_shared/hooks/usePickerState.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/src/_shared/hooks/usePickerState.ts b/lib/src/_shared/hooks/usePickerState.ts index f361e2c69..d999e199b 100644 --- a/lib/src/_shared/hooks/usePickerState.ts +++ b/lib/src/_shared/hooks/usePickerState.ts @@ -77,6 +77,8 @@ export function usePickerState(props: BasePickerProps, options: StateHookOptions if (variant === 'inline' || variant === 'static') { onChange(newDate); + onAccept && onAccept(newDate); + return; // simulate autoOk, but do not close the mod } if (isFinish && autoOk) { @@ -84,7 +86,7 @@ export function usePickerState(props: BasePickerProps, options: StateHookOptions } }, }), - [acceptDate, autoOk, onChange, pickerDate, variant] + [acceptDate, autoOk, onAccept, onChange, pickerDate, variant] ); const validationError = validate(value, utils, props); From d6b874ea7ad2f7558292c01c013b931ec9fcf825 Mon Sep 17 00:00:00 2001 From: Dmitriy Kovalenko Date: Sat, 27 Jul 2019 21:19:07 +0300 Subject: [PATCH 2/3] Update lib/src/_shared/hooks/usePickerState.ts --- lib/src/_shared/hooks/usePickerState.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/src/_shared/hooks/usePickerState.ts b/lib/src/_shared/hooks/usePickerState.ts index d999e199b..268132e5e 100644 --- a/lib/src/_shared/hooks/usePickerState.ts +++ b/lib/src/_shared/hooks/usePickerState.ts @@ -78,7 +78,7 @@ export function usePickerState(props: BasePickerProps, options: StateHookOptions if (variant === 'inline' || variant === 'static') { onChange(newDate); onAccept && onAccept(newDate); - return; // simulate autoOk, but do not close the mod + return; // simulate autoOk, but do not close the modal } if (isFinish && autoOk) { From 5f89373c42227eea7a0ba64c7cf687d359382caf Mon Sep 17 00:00:00 2001 From: Dmitriy Kovalenko Date: Sat, 27 Jul 2019 22:22:43 +0300 Subject: [PATCH 3/3] Make autoOk property to have bigger prioritiy --- lib/src/_shared/hooks/usePickerState.ts | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/lib/src/_shared/hooks/usePickerState.ts b/lib/src/_shared/hooks/usePickerState.ts index 268132e5e..944c696ff 100644 --- a/lib/src/_shared/hooks/usePickerState.ts +++ b/lib/src/_shared/hooks/usePickerState.ts @@ -75,14 +75,15 @@ export function usePickerState(props: BasePickerProps, options: StateHookOptions onChange: (newDate: MaterialUiPickersDate, isFinish = true) => { setPickerDate(newDate); + if (isFinish && autoOk) { + acceptDate(newDate); + return; + } + + // simulate autoOk, but do not close the modal if (variant === 'inline' || variant === 'static') { onChange(newDate); onAccept && onAccept(newDate); - return; // simulate autoOk, but do not close the modal - } - - if (isFinish && autoOk) { - acceptDate(newDate); } }, }),