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

248
Views
Por qué mi enfoque InputBase no funciona en Click React y Material UI

Me enfrento a un error extraño. Estoy tratando de enfocar mi elemento de entrada cuando hago clic en el botón pero eso no enfoca mi entrada.

Intenté usar useRef de gancho de reacción y luego usarlo en mi inputRef.

 const inputRef = useRef<HTMLInputElement>(null); <InputBase inputRef={inputRef} value={search} placeholder="Search" onChange={onSearch} onKeyPress={onSearchQuery} /> <Button variant="text" onClick={() => { inputRef.current?.focus(); onOpen(); }} > Focus my input </Button>
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Usa React.createRef()

 class MyClass extends React.Component { constructor(props) { super(props); // create a ref to store the textInput DOM element this.textInput = React.createRef(); this.focus = this.focus.bind(this); } focus() { // Explicitly focus the text input using the raw DOM API // Note: we're accessing "current" to get the DOM node this.textInput.current.focus(); } render() { // tell React that we want to associate the <input> ref // with the `textInput` that we created in the constructor return ( <div> <InputBase ref={this.textInput} value={search} placeholder="Search" onChange={onSearch} onKeyPress={onSearchQuery} /> <Button variant="text" onClick={this.focus} > Focus my input </Button> </div> ); } }
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!