onChange of Select Component should return the full data-structure and not just the value #4726
-
What package has an issue@mantine/core Describe the bugMy assumption of the onChange behaviour is that it should return the full data-structure and not just the value because users might want to use the full data-structure(object of What version of @mantine/hooks page do you have in package.json?6.0.14 If possible, please include a link to a codesandbox with the reproduced problemhttps://mantine.dev/core/select/ Do you know how to fix the issueYes Are you willing to participate in fixing this issue and create a pull request with the fixYes Possible fixNo response |
Beta Was this translation helpful? Give feedback.
Replies: 13 comments 14 replies
-
@emmanuelonah The value that goes into the select |
Beta Was this translation helpful? Give feedback.
-
@yshterev Exactly thats my point, why do i need to run a derivative search to find what i have selected already when i could just get it from I would say its data-stinginess looping through the data(s) when you could just pass into the |
Beta Was this translation helpful? Give feedback.
-
@emmanuelonah The obvious answer to this is that developers of Mantine UI don't want to add unnecessary logic to components and couple them with external data, unless really necessary. Increasing code complexity over time always leads to more bugs and more test cases to be covered. Accepting a request like yours ☝️ opens up the door to more similar requests. TBH I also really like the current approach of Mantine to keep things simple. |
Beta Was this translation helpful? Give feedback.
-
Or at least there can be a second option just like Ant Design Select onChange that contains the full option. |
Beta Was this translation helpful? Give feedback.
-
If you specify the value key on AutoComplete, onChange still returns the label, despite the value key being included as a usable key in the data prop. |
Beta Was this translation helpful? Give feedback.
-
I think there should be an option to do it, |
Beta Was this translation helpful? Give feedback.
-
I second this as the component already knows the selected data structure. Forwarding the selected item with onOptionSubmit reduces the repetitive task of walking through the data tree again on the project code. Currently, I have a component based off of the standard Mantine Select merely to walk the data structure. Since Select already enforces a data format |
Beta Was this translation helpful? Give feedback.
-
Throwing another hat into the ring — I'd like an option to return the whole object, as well. Would be a game-changer when dealing with enums (where the label/value object is keyed using the value and not the label) which you're trying to match combobox/select inputs against. |
Beta Was this translation helpful? Give feedback.
-
This is an unfortunate quirk to how this works. Any thoughts on changing the behavior of these components to return the selected object and not just the value? |
Beta Was this translation helpful? Give feedback.
-
Another vote for this change. It's very annoying and time-consuming to have to search for the whole object when it could just be returned with |
Beta Was this translation helpful? Give feedback.
-
Hi there, adding to this. Being unable to access the object makes things extra complicated for what feels like a frequent use case. On my part, I am using the autocomplete with async data to search within the users of my app and attach the selected user's id in a form. Two users can very much have the same name, so searching within the options using the value is not an option. |
Beta Was this translation helpful? Give feedback.
-
Another vote for returning the label as well. I've been using Mantine for a while and this is one change I keep coming back to again and again. Every time I get the value from a long select box and then have to loop over an array to get the label, it feels like a quick and dirty hack. It'd be great if the label was also returned along with the value. And the label is almost always needed. Unless it's a very simple form that's immediately submitted, If I'm doing anything else with the value, I'll need the label to display the value in the page. |
Beta Was this translation helpful? Give feedback.
-
This needs to be fixed... |
Beta Was this translation helpful? Give feedback.
onChange
is called with 2 arguments. The second argument is the option object.