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

271
Visualizações
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 Respostas
Responde à pergunta

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 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