Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

294
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda