Reputation: 3262
Let's assume I've got Polymer custom control like:
<template if="{{editMode}}">
<input id="myInput" type="text">
</template>
<div on-doubleclick="{{setEditModeToTrue}}">
some stuff here
</div>
Now I want #myInput to be text focused everytime editMode is true. The problem is that in the setEditModeToTrue handler #myInput is not yet in DOM tree so I can't focus it by:
root.QuerySelector('#myInput').focus();
(And yes I tried setting autofocus attribute on input but it works only for the first double click)
Is there any event or something else letting me know that template-if content is in DOM tree ?
Upvotes: 1
Views: 147
Reputation: 657496
You can wrap or extend the input
element and put your code in the attached
or ready
lifecycle method or use MutationObserver.
Upvotes: 1