Focusing div elements with React

后端 未结 6 1739
不思量自难忘°
不思量自难忘° 2020-12-15 06:16

Is it possible to focus div (or any other elements) using the focus() method?

I\'ve set a tabIndex to a div element:

6条回答
  •  一向
    一向 (楼主)
    2020-12-15 06:37

    import React from "react"
    import ReactDOM from 'react-dom';
    
    export default class DivFocusReactJs extends React.Component {
    
      constructor(props) {
        super(props)
        this.state = {
        }
      }
    
      componentDidMount() {
        ReactDOM.findDOMNode(this.refs.divFocus).focus();
      }
    
      render() {
        return (
          

    Focusing div elements with React

    {/*your code here...*/}
    ) } }

提交回复
热议问题