onChange event is getting fired after onClose event. This is a problem if we want to use state dependent on logic from onChange on the onClose callback.
onClose triggers before onChange
onChange triggers before onClose
Then review console to check which one was triggered first.
use state dependent on logic from onChange on the onClose callback.
@material-ui/core": 4.9.13
react 16
@pablof300 Why does the order matter? Why should it be changed?
Then review console to check which one was triggered first.
Could you include codesandbox illustrating that order? I tend to agree that onChange should be fired before onClose. It's somewhat related to input -> commit order for <input>. Though it's probably also interesting to see if click fires before or after change in a native <select>.
Could you include codesandbox illustrating that order?
@eps1lon https://codesandbox.io/s/material-demo-wzo11?file=/demo.tsx.
Though it's probably also interesting to see if click fires before or after change in a native
<select>.
https://codesandbox.io/s/material-demo-72vnd?file=/demo.tsx
On the autocomplete, we fire onChange before onClose too:
Regarding a possible solution, it seems that
diff --git a/packages/material-ui/src/Select/SelectInput.js b/packages/material-ui/src/Select/SelectInput.js
index 27446e29a5..d748c3a5ce 100644
--- a/packages/material-ui/src/Select/SelectInput.js
+++ b/packages/material-ui/src/Select/SelectInput.js
@@ -160,10 +160,6 @@ const SelectInput = React.forwardRef(function SelectInput(props, ref) {
};
const handleItemClick = (child) => (event) => {
- if (!multiple) {
- update(false, event);
- }
-
let newValue;
if (multiple) {
@@ -194,6 +190,10 @@ const SelectInput = React.forwardRef(function SelectInput(props, ref) {
Object.defineProperty(event, 'target', { writable: true, value: { value: newValue, name } });
onChange(event, child);
}
+
+ if (!multiple) {
+ update(false, event);
+ }
};
const handleKeyDown = (event) => {
Would be enough
I can take this one if it is still valid 馃槈
@DanailH All yours :+1: