base-ui icon indicating copy to clipboard operation
base-ui copied to clipboard

[Autocomplete] Fix type for multiple values to use readonly arrays

Open pcorpet opened this issue 2 years ago • 3 comments

Steps to reproduce 🕹

The following should work

  // values accepts const and value has correct type
  useAutocomplete({
    options: ['1', '2', '3'] as const,
    multiple: true,
    value: ['1', '3'] as const,
    onChange(event, value) {
      expectType<ReadonlyArray<'1' | '2' | '3'>, typeof value>(value);
    },
  });

Current behavior 😯

Typescript complains that the value is an immutable array.

Expected behavior 🤔

accept it.

Context 🔦

A fix was proposed in mui/material-ui#38253 and got merged, it got reverted in mui/material-ui#38253 because of mui/material-ui#38817.

The steps proposed by @mnajdova were to

  • move the current useAutocomplete in Material UI
  • iterate on the useAutocomplete in Base UI - test the changes in Joy UI
  • in v6, migrate Material UI's Autocomplete to use the Base UI's useAutocomplete

Your environment 🌎

No response

pcorpet avatar Nov 02 '23 23:11 pcorpet

@mnajdova I'm not sure what you mean by moving the "current" useAutocomplete in Material UI:

  • is Material UI, the package in the folder mui-material?
  • are you suggesting that we copy the current version of useAutocomplete to mui-material for instance without exporting it and just using it the Autocomplete component?

pcorpet avatar Nov 02 '23 23:11 pcorpet

Thanks for creating the issue @pcorpet. To give some clarification, at this moment Material UI uses the useAutocomplete from Base UI. If we want to make breaking changes to this hook at this point, we can't do it because a stable package depends on it. This is why I said that we should copy the current version to Material UI: /packages/mui-material/ and then we can safely iterate on the Base UI's version of the useAutocomplete. We can replace the useAutocomplete in Material UI in the next major, together with the other planned breaking changes.

mnajdova avatar Nov 03 '23 10:11 mnajdova

@mnajdova is mui/material-ui#39738 what you had in mind for the first steps?

pcorpet avatar Nov 03 '23 21:11 pcorpet