Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

265
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!