Skip to content

Commit

Permalink
Fix dispatching 2 onChange events with variant="inline" (mui#1209)
Browse files Browse the repository at this point in the history
* Fix dispatching 2 onChange events with variant="inline"

* Update lib/src/_shared/hooks/usePickerState.ts

* Make autoOk property to have bigger prioritiy
  • Loading branch information
dmtrKovalenko authored Jul 27, 2019
1 parent 42b2cad commit 41fa537
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions lib/src/_shared/hooks/usePickerState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,16 +75,19 @@ export function usePickerState(props: BasePickerProps, options: StateHookOptions
onChange: (newDate: MaterialUiPickersDate, isFinish = true) => {
setPickerDate(newDate);

if (variant === 'inline' || variant === 'static') {
onChange(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);
}
},
}),
[acceptDate, autoOk, onChange, pickerDate, variant]
[acceptDate, autoOk, onAccept, onChange, pickerDate, variant]
);

const validationError = validate(value, utils, props);
Expand Down

0 comments on commit 41fa537

Please sign in to comment.