Skip to content

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

@pcorpet

Description

@pcorpet

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    type: enhancementIt’s an improvement, but we can’t make up our mind whether it's a bug fix or a new feature.typescript

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions