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

317
Views
React - onClick function not working inside a flexbox

When I click the search button in the flexbox, I expect the console will log I am clicked, but it does not appear which is unexpected.

enter image description here

App.js

                <div
                  className={classes.searchIcon}
                  onClick={() => {
                    console.log("I am clicked");
                  }}
                >
                  <SearchIcon />
                </div>

CodeSandbox:

Edit magical-solomon-yi3xs

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You have pointerEvents: none in your CSS, which is disabling clicking. Also, I'd recommend using a button instead of a div for accessibility purposes (you can style it to look however you want).

const useStyles = makeStyles((theme) => ({
  searchIcon: {
    padding: theme.spacing(0, 1),
    height: "100%",
    //pointerEvents: "none", <-- remove this
    display: "flex",
    alignItems: "center",
    justifyContent: "center",
    cursor: "pointer",
    zIndex: 200
  }
}));

The more accessible JSX (with a button):

<button
  className={classes.searchIcon}
  onClick={() => {
    console.log("I am clicked");
  }}
>
  <SearchIcon />
</button>
about 4 years ago · Juan Pablo Isaza 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!