Is there a way to focus core-input or paper-input element?
What I want to achieve is: set cursor to input element so user can start typing.
This way he will not be forced to click on element before writing.
Is there a way to focus core-input or paper-input element?
What I want to achieve is: set cursor to input element so user can start typing.
This way he will not be forced to click on element before writing.
Share Improve this question asked Jun 30, 2014 at 18:28 wormhitwormhit 3,82740 silver badges46 bronze badges5 Answers
Reset to default 8core-input has now a .focus()
method it's delegating to the internal 's focus()
From the core-input.html
code:
focus: function() {
this.$.input.focus();
}
What means that in your own code you need to call it like following:
elem[0].focus()
In my own case, I am calling focus
from a timeout
. In this case a bind
is necessary for core-input
to make a right use of this
:
$timeout(elem[0].focus.bind(elem[0]));
core-input
is missing focus()/blur()
API, this is essentially a bug.
For now you can do this:
<reference to a core/paper-input>.$.input.focus();
.focusAction(); works in a slightly nicer way, the floating headers will react properly if enabled.
for those using Polymer 1.0 (not OP at time of post)
For the first paper-input you can set focus with this:
$('paper-input input').first().focus();
you can also select by id for a specific paper-input:
$('#myValue input').focus();
For Polymer 2.0 use
this.$.id-of-the-Element.focus();
so if your element is like
<paper-input id="myInputElement" type="number" name="myInputElement"> </paper-input>
Then you would do
this.$.myInputElement.focus();