mui / base-ui

Base UI is an open-source library of accessible, unstyled UI components for React.
MIT License
356 stars 49 forks source link

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

Open pcorpet opened 1 year ago

pcorpet commented 1 year ago

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

Your environment 🌎

No response

pcorpet commented 1 year ago

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

mnajdova commented 1 year ago

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.

pcorpet commented 1 year ago

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