Created
July 24, 2015 00:12
-
-
Save kevashcraft/b07b2aa83563473c54c2 to your computer and use it in GitHub Desktop.
Paper Dialog AutoFocus and Size Fix
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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