<paper-dialog>
<h2>Rename</h2>
<div>
<paper-input autofocus></paper-input>
</div>
<div class="buttons">
<paper-button dialog-dismiss>Cancel</paper-button>
<paper-button dialog-confirm on-click="_confirm">Rename</paper-button>
</div>
</paper-dialog>
此纸张对话框仅在您第一次打开纸张时才会触发自动对焦。
每次打开对话框时如何触发焦点?
答案 0 :(得分:1)
要修复对话框的自动对焦,我必须使用事件监听器并手动对焦元素。
例如:
window.addEventListener('iron-overlay-opened', function(event) {
// Grab the autofocus input
var input = event.target.querySelector('[autofocus]');
// Switch it because some require special treatment
switch(input.tagName.toLowerCase()) {
case 'input':
input.focus();
break;
case 'paper-textarea':
case 'paper-input':
input.$.input.focus();
break;
}
});