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

269
Vistas
How To: onClick/onChange for a <select>'s <option> in a child component

Is there a way to have a child component which rendered only an <option> tag to trigger the onChange of it's parent <select> ?

I ask because I've tried onClick and onChange on the the child <option> and it seems to be aloof to them.

The idea is a parent React component that looks like this:

render() {
  return (
    <select value={this.state.value} onChange={this.handleChange}>
      <ChildOption onClick={this.handleChange}
    </select>
  );
}

and the ChildOption component like this:

render() {
  return (
    <option onClick={this.handleClick} />
  );
}

The full code for this issue is here in a CodePen (pretend it's returning an array of <option>s:

  • http://codepen.io/mikeumus/pen/BpzeYO?editors=0010

Real world code here in Cloud9:

  • https://ide.c9.io/mikeumus/ca-blinds#imports/plugins/included/product-detail-simple/client/components/variantList.js:205
over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

You can have a child component that only renders the option tag. You actually don't need to add an event handler to the option tag. The select onChange event get called automatically once an option tag is clicked (passing it's value with it).

See the example here: http://codepen.io/anon/pen/oBzzWr?editors=0010

over 4 years ago · Santiago Trujillo 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