question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Multiselect onChange property not working

See original GitHub issue

What package has an issue

@mantine/core

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:closed
  • Created a year ago
  • Reactions:1
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
steschwacommented, Jul 27, 2022

I agree that this behaviour doesn’t feel “right”. I think the main problem resides in use-uncontrolled.ts. If the value prob of <Select> is undefined at the first render, the component keeps acting like it’s uncontrolled because it’ll never switch back to beeing controlled (even if value changes to something different to undefined).

If we compare that to e.g. useControllableState.ts from Radix, they compute the controlled/uncontrolled state on the fly.

2reactions
mlarchercommented, Jul 26, 2022

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 like name: 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…

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found