cca-io / rescript-mui

ReScript bindings for MUI
MIT License
255 stars 52 forks source link

Autocomplete multiple value type error #201

Closed efirvida closed 7 months ago

efirvida commented 1 year ago

Hi, if I try to set the value of a multiple field, this trough a error sayung that the value prop is needs a type but I'm giving an array \<type>, so there is something missing in the type of the value prop.

Using the provided example:


type top100 = {
  title: string,
  year: int,
}

let top100Films = [
  {title: "The Shawshank Redemption", year: 1994},
  {title: "The Godfather", year: 1972},
  ...
]

<Mui.Autocomplete
    id="combo-box-demo"
    options=top100Films
    getOptionLabel={option => option.title}
    fullWidth=true
    multiple=true               // multiple
    value=top100Films     // values
    renderInput={params => {
      let props = params->Mui.Autocomplete.renderInputParamsToTextFieldProps
      <Mui.TextField {...props} label={React.string({"Combo box"})} variant=Outlined />
    }}
  />
}

give:


  This has type: array<top100>
  Somewhere wanted: top100
fhammerschmidt commented 1 year ago

I'll try to refine the Autocomplete bindings a bit soon. Maybe even to the same pattern as the Slider/Slider.Ranged.

Which means to export both a Autocomplete and Autocomplete.Multiple. I cannot think of a use-case where you want to dynamically change from the one to the other anyway.

fhammerschmidt commented 7 months ago

Published a new version with some changes. Check out the examples how to use them: https://github.com/cca-io/rescript-mui/blob/master/examples/src/examples/ExampleAutocomplete.res