[SalesForce] Lightning component’s .focus() not working

I have an input field:

<ui:inputText aura:id="name-input"/>

With controller code:

var input = cmp.find("name-input");
console.log(input);    
input.focus();

This gives the error:

Access Check Failed! Component.method():'markup://ui:focus' is not visible to 'markup://c:TimeTagCreator {100:0}'.

I can even see that the .focus() method exists, with the output of that console.log(); being:

enter image description here

What is going on here?

Best Answer

You're getting an Access Check Failure (ACF) here because the focus aura:method on ui:input (which ui:inputText extends) is not marked access=GLOBAL so it is not public available for use. Even though you can see the method defined on the ui:inputText object, the framework will verify access before letting you call it.

https://github.com/forcedotcom/aura/blob/master/aura-components/src/main/components/ui/input/input.cmp#L69

You can see more info on ACFs here: https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/access_intro.htm#access_intro

Since it's still in Beta, don't use it for anything that will end up in a managed package, but have you tried out lightning:input? https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/aura_compref_lightning_input.htm

Of course, you can always roll your own using the native <input> tag, but I do think this is something that should be fixed by the framework.

Edit:

The focus() method of lightning:input also throws an ACF currently, but will be fixed in the Spring '17 major release.