-
-
Notifications
You must be signed in to change notification settings - Fork 32.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Autocomplete] 'renderTags' ignored when 'multiple' is false #26440
Comments
I also wonder if this was perhaps intentional. Regardless, I believe there is enough of a use case to either allow I'm curious what your workaround was @degzhaus. Were you able to do it somehow inside the |
Thanks for the feedback. What we consider a "tag" is a combination of a value and an affordance to de-select that value. There's no need to de-select a single value in a single-select Autocomplete so we don't even attempt to "render tags". The purpose of So we definitely do lack some clearer documentation for the Autocomplete. As to your specific issue: Could you explain a bit more what UI you're trying to build? Then we can discuss what kind of API could solve this problem. |
Thanks for the response @eps1lon . That makes a lot of sense. Looking at it now everything inside the To describe a bit further our use case, we have a custom component, |
This would be an incredibly helpful change for us also. We need to show a device status icon - and ideally also a device class icon - not only on the options, but also for the selected value. We use this type of device select for both single and multiselection. IIUC one can only render a string unless multiselection is enabled, which results in an inconsistent UI in our case. And since we cannot omit the status icon, we currently add it to the textfield label, which is of course very undesirable. |
I am using Autocomplete to display the selected popup as chip and typed text as normal text |
This is something that would be very helpful for us also |
I can think of the following approaches:
We should also update the API docs for @oliviertassinari @michaldudak What do you guys think? |
This comment was marked as spam.
This comment was marked as spam.
I see how this may be useful. A thing to note, though, is that rendering anything else than a default string will break the current autocompletion logic. Let's say we have a list of colors and when selected, we display a swatch before the color name in the textbox:
When we now focus the textbox and press Backspace, we are left with We could overcome this by disallowing to edit the selected value and clearing the input completely when Backspace, Delete, or any character key is pressed, similar to how react-select does it. This logic would kick in only if we override what is displayed in the textbox. Do you have any preferences in this matter? cc @mnajdova |
+1 for this! We would also be helped a lot if this was a feature. Edit: found out our team is actually using this approach: https://codesandbox.io/s/material-demo-forked-ijzbt?file=/demo.js degzhaus' suggestion didn't work but the one used on this csb did. Basically adding |
This comment was marked as spam.
This comment was marked as spam.
Aren't we be able to keep the actual value somewhere else and have the rendered component not interfere with our autocompletion? Based on your suggestion and example, when deleting the character "d", could we make it so that the swatch goes away? Idk if I'm going to far here, but basically having a way to map a value to its renderTag, so "red" maps to "🟥 red", as soon as we deleted a single character from the input, there won't be any value that maps to that, so we go back to normal rendering the text typed. So instead of this
We would get this:
-edit |
From a UI POV I personally prefer the latter solution where backspace removes the selected value and completely clears the input. This aligns with Autocomplete behavior when The case where users instead want to view similar items to the one they just removed (search results for 're') seems less likely. One caveat to that may be if |
The gmail to field would be something that supports renderTags and freeSolo={true}? |
I think it could be confusing if the rendered value changed during editing. I'm leaning towards a solution similar to how the Autocomplete works in If someone is willing to prototype a solution, I'll be happy to review it and discuss the solutions for problems that arise. |
Is there any solution for this? |
My workaround/idea is
Still, I’m waiting for the official solution as well. |
Any news on an official solution for this? Would be extremely helpful and it's been 3 years 🙏 |
A workaround I came up with entailed using a state and the adornment used in the comment above. So, for example, my autocomplete is one for picking colours. You can display the colour and text just fine with renderOption. But when the value is selected, I call the setColour action to set the colour state. Then in the adornment I have a div that's a box with the background set as the state value (colour hex code). |
I created a PR to add this feature request: #45387 |
Current Behavior 😯
On v5 alpha, when passing
renderTags
to Autocomplete whenmultiple
is false the renderTags prop will be ignored.Expected Behavior 🤔
renderTags
should be used to render the selected item(s) in the Input no matter whatmultiple
is set to.Steps to Reproduce 🕹
Comment line 11 of this code sandbox
Context 🔦
We have a single select Autocomplete where we set the
renderOption
prop to render a custom element that includes a small profile pic. However once one option is selected there is currently no way to render this custom element in the Input of the AutocompleteYour Environment 🌎
`npx @material-ui/envinfo`
The text was updated successfully, but these errors were encountered: