Skip to content

Instantly share code, notes, and snippets.

@kevashcraft
Created July 24, 2015 00:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kevashcraft/b07b2aa83563473c54c2 to your computer and use it in GitHub Desktop.
Save kevashcraft/b07b2aa83563473c54c2 to your computer and use it in GitHub Desktop.
Paper Dialog AutoFocus and Size Fix
window.addEventListener('iron-overlay-opened', fixDialog);
function fixDialog (dore) {
var dialog = (typeof dore.tagName != 'undefined') ? dore : dore.target;
if(dialog.tagName == 'PAPER-DIALOG') {
dialog.fit();
var input = dialog.querySelector('[autofocus]');
if(input) {
if(typeof input.dataset.highlight != 'undefined') var highlight = true;
switch(input.tagName.toLowerCase()) {
case 'paper-textarea':
case 'paper-input':
input.$.input.focus();
if(highlight) input.$.input.select();
break;
case 'input':
input.focus();
if(highlight) input.select();
break;
case 'iron-autogrow-textarea':
console.log("Here!");
break;
default:
console.log("Tried to focus:",input.tagName.toLowerCase());
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment