I'm using lightning:select. I need to set focus for it in doInit of lightning aura component. I'm using the below code to set focus.

Its working. focus set to that lightning:select. But I'm getting the following error. "Uncaught Action failed: lightning:select$controller$focus [Cannot read property 'focus' of null]" Please suggest me some solutions for this. Thanks in advance.

$A.getCallback(function() {
                            if(component.find("dataList")!= undefined){                                   
                        }), 1


You can't focus an element on doInit, because the first render cycle has not yet run. You need to wait until the element is available. The easiest way to do this is with a setTimeout:

  $A.getCallback(() => {
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.