0
0
mirror of https://github.com/sveltejs/svelte.git synced 2024-12-01 17:30:59 +01:00

handle autofocus edge case

This commit is contained in:
Rich-Harris 2016-11-20 13:11:08 -05:00
parent b743e54c24
commit 92ba62e289

View File

@ -9,6 +9,10 @@ import attributeLookup from './attributes/lookup.js';
import createBinding from './binding/index.js';
function createRenderer ( fragment ) {
if ( fragment.autofocus ) {
fragment.initStatements.push( `${fragment.autofocus}.focus();` );
}
return deindent`
function ${fragment.name} ( component, target${fragment.useAnchor ? ', anchor' : ''} ) {
${fragment.initStatements.join( '\n\n' )}
@ -111,7 +115,6 @@ export default function generate ( parsed, template ) {
];
const updateStatements = [];
const teardownStatements = [];
const allUsedContexts = new Set();
@ -133,9 +136,9 @@ export default function generate ( parsed, template ) {
` );
}
// special case autofocus
// special case autofocus. has to be handled in a bit of a weird way
if ( attribute.name === 'autofocus' ) {
initStatements.push( `${name}.focus();` );
current.autofocus = name;
}
}