Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

155
Views
How to stop showing the checkbox in the input of Material UI TextField with select attribute when we have MenuItems with Checkboxes

I have added checkboxes to the MenuItems in the TextField of type Select. When I select one of the MenuItems, the checkbox is also displaying in the input of the TextField.

Req: I need to stop displaying the check box in the input of TextField. I need to strictly use the TextField with Selcet attribute.

Can someone please help me with this? Thnak you.

enter image description here

sandbox link: https://codesandbox.io/s/basicselect-material-demo-forked-06gns?file=/demo.js

code:

import * as React from "react";
import MenuItem from "@mui/material/MenuItem";
import FormControl from "@mui/material/FormControl";
import ListItemText from "@mui/material/ListItemText";
import Checkbox from "@mui/material/Checkbox";
import TextField from "@mui/material/TextField";

const ITEM_HEIGHT = 48;
const ITEM_PADDING_TOP = 8;
const MenuProps = {
  PaperProps: {
    style: {
      maxHeight: ITEM_HEIGHT * 4.5 + ITEM_PADDING_TOP,
      width: 250
     }
  }
};

const names = ["Oliver Hansen", "Van Henry"];

export default function MultipleSelectCheckmarks() {
  const [personName, setPersonName] = React.useState([]);

   const handleChange = (event) => {
   const {
      target: { value }
    } = event;
    setPersonName(
     // On autofill we get a the stringified value.
      typeof value === "string" ? value.split(",") : value
    );
  };

  return (
    <div>
      <FormControl sx={{ m: 1, width: 300 }}>
        <TextField
          // multiple
          select
          value={personName}
          onChange={handleChange}
          renderValue={(selected) => selected.join(", ")}
          MenuProps={MenuProps}
        >
          {names.map((name) => (
            <MenuItem key={name} value={name}>
              <Checkbox checked={personName.indexOf(name) > -1} />
              <ListItemText primary={name} />
            </MenuItem>
          ))}
        </TextField>
      </FormControl>
    </div>
  );
}
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

I did give it a try and changed some code, onchange and renderValue should be props on select, on not textfield so it was not working


import * as React from "react";
import MenuItem from "@mui/material/MenuItem";
import FormControl from "@mui/material/FormControl";
import FormControlLabel from "@mui/material/FormControlLabel";
import Checkbox from "@mui/material/Checkbox";
import TextField from "@mui/material/TextField";

const ITEM_HEIGHT = 48;
const ITEM_PADDING_TOP = 8;

const names = ["Oliver Hansen", "Van Henry"];

export default function MultipleSelectCheckmarks() {
  const [personName, setPersonName] = React.useState([]);

  const handleChange = (event) => {
    if (!personName.includes(event.target.value))
      setPersonName(event.target.value); // selected options
  };

  return (
    <div>
      <FormControl sx={{ m: 1, width: 300 }}>
        <TextField
          select
          SelectProps={{
            multiple: true,
            value: personName,
            onChange: (e) => handleChange(e),
            renderValue: (selected) => selected.join(", "),
            style: {
              width: "250px",
              maxHeight: `${ITEM_HEIGHT} * 4.5 + ${ITEM_PADDING_TOP}`
            }
          }}
        >
          {names.map((name) => (
            <MenuItem key={name} value={name}>
              <FormControlLabel
                control={<Checkbox checked={personName.includes(name)} />}
                label={name}
              />
            </MenuItem>
          ))}
        </TextField>
      </FormControl>
    </div>
  );
}

Please check working demo here: https://codesandbox.io/s/multi-select-with-textfield-uf100

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!