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

145
Views
Lock an input to focus. React

I want my input to be locked to focus. I tried this

onBlur={this.click()}

but it didn't work. How do I do it?

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

0

give it an autoFocus (camelCase because its react/jsx) attribute

<input type="text" autoFocus/>

if thats what you mean.

about 4 years ago · Juan Pablo Isaza Report

0

The autoFocus attribute is a boolean attribute.

When present, it specifies that an element should automatically get focus when the page loads.

Try this

about 4 years ago · Juan Pablo Isaza Report

0

Use event.target.focus instead of click. You might also want to [invoke this at the end of the event loop][1], i.e. after a timeout of 0ms:

const onBlur = (e) => {
  window.setTimeout(() => e.target.focus(), 0);
};

return (
  <div className="App">
    <h1>Hello CodeSandbox</h1>
    <input type="text" onBlur={onBlur} />
  </div>
);

See proof-of-concept example:

Edit flamboyant-euclid-ow5xf

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!