Skip to content

Conversation

@newsiberian
Copy link
Contributor

@newsiberian newsiberian commented May 16, 2023

I've noticed that isOptionEqualToValue doesn't take into account that value could be a string (freeSolo mode)

Fixes #38322

@mui-bot
Copy link

mui-bot commented May 16, 2023

@zannager zannager added the scope: autocomplete Changes related to the autocomplete. This includes ComboBox. label May 17, 2023
@zannager zannager requested a review from michaldudak May 17, 2023 09:41
@michaldudak
Copy link
Member

Is there an issue you ran into because of this? IIRC, the isOptionEqualToValue is called with the actually selected value, not the input text.

@michaldudak michaldudak added the status: waiting for author Issue with insufficient information. label Jun 15, 2023
@newsiberian
Copy link
Contributor Author

@michaldudak , yes, this is my issue (with freeSolo)
Снимок экрана 2023-06-15 в 16 22 05

@github-actions github-actions bot added the PR: out-of-date The pull request has merge conflicts and can't be merged. label Jul 27, 2023
Copy link
Member

@ZeeshanTamboli ZeeshanTamboli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@newsiberian Could you please provide a CodeSandbox reproducing the issue? The issue template is a good starting point.

@michaldudak
Copy link
Member

There is an issue created independently that describes the problem: #38322

@newsiberian Your solution seems to be correct. Please rebase this PR on the latest master and make sure the checks pass.

Copy link
Member

@ZeeshanTamboli ZeeshanTamboli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The changes make sense, but it will be a breaking change for apps using Autocomplete with both freeSolo and this prop. TypeScript will throw a compile error now, and users will need to update the value parameter in isOptionEqualToValue using type narrowing. Here's an example:

<Autocomplete
  freeSolo
  options={options}
  getOptionLabel={(option) => (typeof option === 'string' ? option : option.book.name)}
  isOptionEqualToValue={(option, value) =>
    option.book.id === (typeof value !== 'string' ? value.book.id : value)
  }
  renderInput={(params) => <TextField {...params} label="book" />}
/>;

Yes it throws a runtime error as mentioned in #38322 but they might be using optional chaining to fix the runtime error.

@ZeeshanTamboli ZeeshanTamboli added the breaking change Introduces changes that are not backward compatible. label Nov 24, 2023
@ZeeshanTamboli ZeeshanTamboli changed the title [useAutocomplete]: Improve isOptionEqualToValue value argument type [useAutocomplete] Improve isOptionEqualToValue value argument type Nov 24, 2023
…-option-equal-to-value-free-solo-type-fix

# Conflicts:
#	packages/mui-base/src/useAutocomplete/useAutocomplete.d.ts
@github-actions github-actions bot removed the PR: out-of-date The pull request has merge conflicts and can't be merged. label Nov 28, 2023
@DiegoAndai
Copy link
Member

I agree with @ZeeshanTamboli in that this is a breaking change that should be released in a major version. Given that the solution is ready, we could target this for v6.

…lue declaration for `isOptionEqualToValue` and `getOptionLabel` to `AutocompleteValueOrFreeSoloValueMapping` and add new demo which covers cases when option can change it type to a string
@newsiberian
Copy link
Contributor Author

@ZeeshanTamboli , all set. tests were fine

Copy link
Member

@ZeeshanTamboli ZeeshanTamboli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@newsiberian Can you fix the CI?

…tocompleteFreeSoloValueMapping<FreeSolo>)` to `(option: AutocompleteValueOrFreeSoloValueMapping<T, FreeSolo>)`
@DiegoAndai
Copy link
Member

DiegoAndai commented Dec 6, 2023

Hey again! After discussing with members of the core team, I confirm that we won't release this in v5. The breaking change is to fix a bug, but it's a breaking change nonetheless. I'm really sorry 😓.

The good news is that we plan to start working on v6 very soon, so we could have this in early alpha releases, with the stable release planned for Q2 2024. We also plan to have more frequent major releases so we don't have to hold bug fixes that require breaking changes like this for too long in the future.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

breaking change Introduces changes that are not backward compatible. scope: autocomplete Changes related to the autocomplete. This includes ComboBox. type: bug It doesn't behave as expected. typescript v7.x

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[material-ui][Autocomplete] Component with freeSolo and isOptionEqualToValue doesn't use string for type of value

7 participants