Material-ui: Autocomplete defaultvalue and value for options with checkbox only works if options reference is passed

Created on 22 Nov 2019  路  11Comments  路  Source: mui-org/material-ui


Autocomplete defaultvalue for checked options only works if options reference is passed

I created a demo to represent this issue
https://codesandbox.io/s/material-demo-4imuq

In the example, both Autocompletes are able to show the selected values in the input field correctly the issue arises in the second autocomplete when you open the autocomplete you can only see checkbox for the only one value.

Current Behaviour
image

Expected Behaviour
image

My apology if i didn't articulate the bug precisely

Autocomplete docs good first issue

Most helpful comment

We document this for the Select component https://material-ui.com/api/select/#props (see value). We need to document it for the Autocomplete component as well.

All 11 comments

We document this for the Select component https://material-ui.com/api/select/#props (see value). We need to document it for the Autocomplete component as well.

This is related to #18443. An update of the documentation would be great. Maybe something like this?

diff --git a/packages/material-ui-lab/src/Autocomplete/Autocomplete.js b/packages/material-ui-lab/src/Autocomplete/Autocomplete.js
index 3b1fe0368..99b6ac4f4 100644
--- a/packages/material-ui-lab/src/Autocomplete/Autocomplete.js
+++ b/packages/material-ui-lab/src/Autocomplete/Autocomplete.js
@@ -597,6 +597,9 @@ Autocomplete.propTypes = {
   renderTags: PropTypes.func,
   /**
    * The value of the autocomplete.
+   *
+   * The value must have reference equality with the option in order to be selected.
+   * You can customize the equality behavior with the `getOptionSelected` prop.
    */
   value: PropTypes.any,
 };

Hey @oliviertassinari !

Can I take this up if no one is working on it?

Sure :)

thanks @eps1lon

is there a way to handle this without passing the reference object ?

@DarkKnight1992 we have two follow-up issues open about this problem. One is about adding a prop to customize the equality check. One is about adding a warning so developers can find this prop. They are good to take, in case you want to push them forward and open pull requests :).

@oliviertassinari would be glad to since i need it one way or another.

I had the same problem i had to hack the renderOption :/
image

See #18514 and #18443 as two good follow up on this problem.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ghost picture ghost  路  3Comments

anthony-dandrea picture anthony-dandrea  路  3Comments

chris-hinds picture chris-hinds  路  3Comments

finaiized picture finaiized  路  3Comments

ghost picture ghost  路  3Comments