Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

material ui warning in using `textField` component with `select`

Using TextField as the input param of Select gives the following warning:

Material-UI: children must be passed when using the TextField component with select.

<Select
    multiple        
    value="value"
    fullWidth
    input={
        <TextField name="name" id="id" variant="outlined" label="test"/>
    }
>
 <MenuItem>1</MenuItem>
 <MenuItem>2</MenuItem>
</Select>

What is the proper implementation of the same?

like image 343
mehdi parastar Avatar asked Oct 28 '25 08:10

mehdi parastar


1 Answers

The proper way is to render a TextField as parent component, and providing it select prop

import React from 'react';
import { makeStyles } from '@material-ui/core/styles';
import MenuItem from '@material-ui/core/MenuItem';
import TextField from '@material-ui/core/TextField';

const useStyles = makeStyles(theme => ({
  root: {
    width: '100px'
  },
}));

export default function SelectTextField() {
  const classes = useStyles();

  return (   
    <TextField 
    classes={{root:classes.root}}
    select
    name="name" 
    id="id" 
    variant="outlined" 
    label="test"
    SelectProps={{
      multiple: true,
      value: []
    }}
    >
      <MenuItem>1</MenuItem>
      <MenuItem>2</MenuItem>
    </TextField>
    );
}

Code Sandbox

like image 62
Ido Avatar answered Oct 30 '25 23:10

Ido