0

cuando el input y/o select no tengan ningún valor seleccionado o escrito que aparezcan de algún color así sea una sombra con color.

import React from 'react'

function Pruebas() {
  return (
    <div>
      <form>
        <input type="text" placeholder="input uno" />
        <select>
          <option value="uno">uno</option>
          <option value="uno">dos</option>
        </select>
      </form>
      
    </div>
  )
}

export default Pruebas

3
  • Hola, ¿eso es lo que has probado? el 17 nov. 2021 a las 15:53
  • he intentado añadirle un estado pero no he podido..
    – Giovanny
    el 17 nov. 2021 a las 15:55
  • alguien que me pueda colaborar ?
    – Giovanny
    el 20 nov. 2021 a las 12:30

1 respuesta 1

1

Puedes usar la propiedad style para aplicar css según si el input tiene valor o no

function Pruebas() {
  const [input, setInput] = useState();
  const [select, setSelect] = useState();

  return (
    <div>
      <form>
        <input
          type="text"
          placeholder="input uno"
          style={{ "background-color": !input && "gray" }}
          value={input}
          onChange={({ target }) => setInput(target.value)}
        />
        <select
          style={{ "background-color": !select && "gray" }}
          onChange={({ target }) => setSelect(target.value)}
        >
          <option value="">seleccionar</option>
          <option value="uno">uno</option>
          <option value="uno">dos</option>
        </select>
      </form>
    </div>
  );
}

Tu Respuesta

By clicking “Publica tu respuesta”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

¿No es la respuesta que buscas? Examina otras preguntas con la etiqueta o formula tu propia pregunta.