Multiselect onChange property not working
See original GitHub issueWhat package has an issue
Describe the bug
When using MultiSelect
, the onChange
callback is not triggered.
Oddly enough, an onSelect
is triggered.
I checked the source code, which confirms the docs in saying that the property to use should be onChange
.
This is happening while trying to use Mantine with react-hook-forms
within a RedwoodJS project.
Code to check:
import { MultiSelect } from "@mantine/core";
import "./styles.css";
export default function App() {
return (
<div className="App">
<MultiSelect
label="This uses onChange and triggers nothing."
onChange={(x) => {
console.log(x);
}}
data={["red", "white", "blue"]}
/>
<MultiSelect
label="This uses onSelect and output to console."
onSelect={(x) => {
console.log(x);
}}
data={["red", "white", "blue"]}
/>
</div>
);
}
In which browser did the problem occur
Chrome/Linux
If possible, please include a link to a codesandbox with the reproduced problem
https://codesandbox.io/s/reverent-snowflake-sv9iqx?file=/src/App.tsx
Do you know how to fix the issue
No
Are you willing to participate in fixing this issue and create a pull request with the fix
No
Possible fix
No response
Issue Analytics
- State:
- Created a year ago
- Reactions:1
- Comments:9 (4 by maintainers)
Top Results From Across the Web
Change event not working on multiple select input
My change event is not firing on a multiple select input. I would like an event to fire each time the multiple select's...
Read more >Multi-Select optionset onchange not working? - Dynamics 365 ...
I tried having as simple as function RunOnchange() { alert("RUN"); } but this doesn't work onchange of multiselect field.
Read more >trigger onChange not work when click in 'Select All' · Issue #787
First for all, thanks for your plugin! The trigger 'onChange' not work when click in 'Select All'. Any help is appreciated.
Read more >SCR19: Using an onchange event on a select element ... - W3C
Navigate to the trigger select element, navigate through the options but do not change the value. Check that the matching option values are...
Read more >Getting values from MultiSelect onChange with JQuery and ...
Demonstrate how to retrieve the selected values of a multiselect dropdown in the onchange event handler using both plain JavaScript and JQuery ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I agree that this behaviour doesn’t feel “right”. I think the main problem resides in
use-uncontrolled.ts
. If thevalue
prob of<Select>
isundefined
at the first render, the component keeps acting like it’s uncontrolled because it’ll never switch back to beeing controlled (even ifvalue
changes to something different toundefined
).If we compare that to e.g. useControllableState.ts from Radix, they compute the controlled/uncontrolled state on the fly.
this behaviour is rather counterintuitive 😞
I’ve spent quite some time figuring out why my my values were not being changed, and eventually discovered that the issue was due to initialValues being
undefined
because of the use of optional chaining on the data object. I ended up using a structure likename: companyData?.name ?? '',
in all initialValues lines; which is quite error prone. I don’t understand the rationale behind it, and can’t help but wonder if there wouldn’t be a more developer friendly way to handle the case…