How do I call the blur () method of the Select component in ant design?

Jun.15,2022

import React, { Component, Fragment } from 'react'
import { Select, Button } from 'antd'

const Option = Select.Option

export default class SelBtn extends Component {
  constructor (props) {
    super(props)
    this.myRef = React.createRef()
  }

  selBlur = () => {
    this.myRef.current.blur()
  }

  render () {
    return <Fragment>
        <Select ref={this.myRef} style={{width: 300}}>
          <Option value="jack">Jack</Option>
          <Option value="lucy">Lucy</Option>
        </Select>
        <Button onClick={this.selBlur}>blur</Button>
    </Fragment>
  }
}

Note:
createRef () method requires React v16.3 or above
if the react version is lower than 16.3, use ref callback to get ref.

Menu