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

324
Views
Componente de entrada de enfoque automático Antd

Intento hacer el componente de entrada de enfoque automático que se encuentra en el componente del cajón. Todos los componentes que tomo de Antd. El problema es que el enfoque automático no funciona inmediatamente, sino solo después de que la ventana se abre y se cierra. Enlace en CodeSandbox https://codesandbox.io/s/quizzical-morning-1nhi2v?file=/src/App.js

 import './App.css'; import 'antd/dist/antd.css'; import {Button, Drawer, Input} from 'antd' import React, { useState, createContext, useRef, useEffect } from 'react'; function App() { const inputRef = useRef(true); const [visible, setVisible] = useState(false); const onClose = () =>{ //Close Drawer setVisible(false); } const open = () =>{ //Open Drawer and must be autofocus on Input setVisible(true); } useEffect(()=>{ console.log(visible + 'useEffect'); if(visible){ inputRef.current.focus(); } }, [visible]) return ( <div className="App"> <Drawer visible={visible} onClose={onClose} autoFocus={true}> <Input ref={inputRef} ></Input> </Drawer> <Input ref={inputRef_} ></Input> <Button onClick={open}> Open</Button> </div> ); } export default App;
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Puedes probar esto. Probé y funcionó.

 if (visible) { setTimeout(() => { inputRef.current.focus(); }, [500]); }
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!