Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[material-ui][Select] Does it receive different types of value? #40432

Closed
RivaldoCM opened this issue Jan 4, 2024 · 2 comments
Closed

[material-ui][Select] Does it receive different types of value? #40432

RivaldoCM opened this issue Jan 4, 2024 · 2 comments
Assignees
Labels
component: select This is the name of the generic UI component, not the React module! package: material-ui Specific to @mui/material support: question Community support but can be turned into an improvement typescript

Comments

@RivaldoCM
Copy link

RivaldoCM commented Jan 4, 2024

I have a doubt about the types of the select component because it only accepts string values.

exemple:

<Select>
        <MenuItem value={10}>VALUES</MenuItem>
        <MenuItem value={20}>VALUES</MenuItem>
        <MenuItem value={30}>VALUES</MenuItem>
</Select>

In MenuItem, I get an error about the number value. In the documentation file select.d.ts, there is:


export interface SelectProps<Value = unknown>
  extends StandardProps<InputProps, 'value' | 'onChange'>,
    Omit<OutlinedInputProps, 'value' | 'onChange'>,
    Pick<SelectInputProps<Value>, 'onChange'> {

   * The `input` value. Providing an empty string will select no options.
   * Set to an empty string `''` if you don't want any of the available options to be selected.
   *
   * If the value is an object it must have reference equality with the option in order to be selected.
   * If the value is not an object, the string representation must match with the string representation of the option in order to be selected.
   */
  value?: Value | '';
}

When I set value?: Value | '' | number, it works fine. Does this mean the select component does not support other types in Material UI? I was thinking of opening a pull request, but it's better to clear my doubt first.

Search keywords: types, select

@github-actions github-actions bot added the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label Jan 4, 2024
@danilo-leal danilo-leal changed the title [MATERIAL UI] Select component [material-ui][Select] Does it receive different types of value? Jan 4, 2024
@danilo-leal danilo-leal added support: question Community support but can be turned into an improvement component: select This is the name of the generic UI component, not the React module! typescript package: material-ui Specific to @mui/material labels Jan 4, 2024
@siriwatknp siriwatknp assigned DiegoAndai and unassigned mj12albert Jan 5, 2024
@DiegoAndai
Copy link
Member

Hey @RivaldoCM, thanks for reaching out!

You can specify Select's value type via the Value generic parameter by doing <Select<number>>{...}</Select>, and you can do the same for SelectChangeEvent<number>. Here's an example: https://codesandbox.io/p/sandbox/40432-example-vjpfng

Is this what you're looking for?

@DiegoAndai DiegoAndai added status: waiting for author Issue with insufficient information and removed status: waiting for maintainer These issues haven't been looked at yet by a maintainer labels Jan 5, 2024
@RivaldoCM
Copy link
Author

Exactly, @DiegoAndai . Thanks for the explanation.

@github-actions github-actions bot added status: waiting for maintainer These issues haven't been looked at yet by a maintainer and removed status: waiting for author Issue with insufficient information labels Jan 8, 2024
@zannager zannager removed the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label Jan 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: select This is the name of the generic UI component, not the React module! package: material-ui Specific to @mui/material support: question Community support but can be turned into an improvement typescript
Projects
None yet
Development

No branches or pull requests

5 participants