Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

261
Visualizações
in mui dropdrown, icons is not showing in dropdown after selecting option in once in react JS

in the select tag initially icon is not showing ,its right. If you click the dropdown you observe the icon is showing its ok, but if you select any one option then again if you click the dropdown that icon is not showing, at the first time the flow is correct but after selecting one option then again if you select the dropdown then the icon is not showing ,how to fix that

import * as React from "react";
import Box from "@mui/material/Box";
import { BsFillArrowDownSquareFill } from "react-icons/bs";
import InputLabel from "@mui/material/InputLabel";
import MenuItem from "@mui/material/MenuItem";
import FormControl from "@mui/material/FormControl";
import Select from "@mui/material/Select";
import { ListItemIcon } from "@mui/material";
export default function BasicSelect() {
  const [age, setAge] = React.useState("");
  const [selected, setClicked] = React.useState(false);
  const handleChange = (event) => {
    setAge(event.target.value);
    setClicked(true);
  };

  return (
    <Box sx={{ minWidth: 120 }}>
      <FormControl fullWidth>
        <InputLabel id="demo-simple-select-label">Age</InputLabel>
        <Select
          labelId="demo-simple-select-label"
          id="demo-simple-select"
          value={age}
          label="Age"
          onChange={handleChange}
        >
          <MenuItem value={10}>
            Ten
            {selected ? null : (
              <ListItemIcon>
                <BsFillArrowDownSquareFill />
              </ListItemIcon>
            )}
          </MenuItem>
          <MenuItem value={20}>
            Twenty
            {selected ? null : (
              <ListItemIcon>
                <BsFillArrowDownSquareFill />
              </ListItemIcon>
            )}
          </MenuItem>
          <MenuItem value={30}>
            Thirty
            {selected ? null : (
              <ListItemIcon>
                <BsFillArrowDownSquareFill />
              </ListItemIcon>
            )}
          </MenuItem>
        </Select>
      </FormControl>
    </Box>
  );
}
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Your handleChange function is updating the value of selected to be true when an item is selected. You could just remove the conditional in the MenuItem for the Icon to be visible at all times

<MenuItem value={10}>
            Ten
             <ListItemIcon>
                <BsFillArrowDownSquareFill />
              </ListItemIcon>
      </MenuItem>
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda