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

299
Visualizações
Change the state of arrows in a dropdown list

The code below illustrates a normal drop down list. To indicate a drop down list, I use a down arrow with arrow_drop_down This arrow remains static for me in any state of the list (open or closed). However, I would like that when clicking on the list, the arrow changes to arrow_drop_up .

Those. so that with two different states of the list, there would be two different arrows.

    export default function FilterStatusCode() {
  const [values, setValues] = React.useState([]);

  const [isExpanded, setIsExpanded] = useState(false);

  const toggleExpand = () => {
      setIsExpanded(!isExpanded);
  };

  return <>
    <div className="item-toggle-statuscode" onClick={toggleExpand}>
        <h6>Status Code</h6>
          <span class="material-icons">
            arrow_drop_down
          </span>
    </div>
    { isExpanded &&
      <div>
        <TagInput
          inputProps={{ placeholder: 'Add status code...' }}
          values={values}
          onChange={(values) => {
          setValues(values)}}>
        </TagInput>
      </div>
    }
</>;
}
about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

try

 <div className="item-toggle-statuscode" onClick={toggleExpand}>
    <h6>Status Code</h6>
      <span class="material-icons">
       { isExpanded ? arrow_drop_up : arrow_drop_down }
      </span>
</div>
about 4 years ago · Juan Pablo Isaza Relatório

0

You can choose which arrow you use depending on the current state:

// If the list is open show the `up` arrow
// otherwise show the `down` arrow
<span className={open ? "up" : "down"}></span>

I had to improvise in this example and used unicode in the class names.

const { useState } = React;

function Example() {
  return (
    <div>
      <Item />
      <Item />
    </div>
  );
}

function Item() {

  const [ input, setInput ] = useState('');
  const [ open, setOpen ] = useState(false);

  function handleChange(e) {
    setInput(e.target.value);
  }

  function handleOpen() {
    setOpen(!open);
  }

  function handleClick() {
    console.log(input);
  }

  return (
    <div className="item">
      <div onClick={handleOpen} className="heading"> 
        <span>Status code</span>
        <span className={open ? "up" : "down"}></span>
      </div>
      {open && (
        <div>
          <input
            type="text"
            onChange={handleChange}
            value={input}
          />
          <button
            type="button"
            onClick={handleClick}
          >Submit
          </button>
        </div>
      )}
    </div>
  );

}

ReactDOM.render(
  <Example />,
  document.getElementById('react')
);
.down:after { content: '\25BC'; }
.up:after { content: '\25B2'; }
.heading:hover { cursor: pointer; color: red; }
.item { margin-bottom: 1em; }
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/17.0.2/umd/react.production.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/17.0.2/umd/react-dom.production.min.js"></script>
<div id="react"></div>

Additional documentation

  • Conditional (ternary) operator
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