question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cannot get DOM-elements of `<Select />`

See original GitHub issue

What you did

I use <Select showSearch />as a auto-complete field

What you would like to happen

I want to get the DOM-element of the search-input to focus it programatically. The used rc-select already provide an API to get the DOM-element.

What actually happened

I’m not able to get the rc-select element from antd’s <Select />.

Online demo

http://codepen.io/sokki/pen/rLNQQa?editors=0011

Environment Information

  • antd 1.2.1

Possible Solution

add ref="select" to <RcSelect /> in the render method of antd’s <Select />: https://github.com/ant-design/ant-design/blob/master/components/select/index.jsx#L44

      <RcSelect {...this.props}
        ref="select"
        className={cls}
        optionLabelProp={optionLabelProp || 'children'}
        notFoundContent={notFoundContent} />

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
RaoHaicommented, May 31, 2016

using ReactDOM.findDOMNode(this.refs.select).click(); can also focus the search input.

1reaction
benjycuicommented, Mar 30, 2017
Read more comments on GitHub >

github_iconTop Results From Across the Web

javascript - can't select element with dom, after creating that ...
Move the event handler into the first function so that it isn't triggered until the element is created and added to the document....
Read more >
How do I select elements when I already have a DOM element?
If you have a variable containing a DOM element, and want to select elements related to that DOM element, simply wrap it in...
Read more >
Searching: getElement*, querySelector*
If an element has the id attribute, we can get the element using the method document.getElementById(id) , no matter where it is. For...
Read more >
How To Access Elements in the DOM - DigitalOcean
The easiest way to access a single element in the DOM is by its unique ID. You can get an element by ID...
Read more >
Can't select element (JavaScript) | Sololearn: Learn to code for ...
I'm trying to make a project, it's porpuse is to basically update the navigation bar of a website I have to all pages...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found