handle autofocus edge case

pull/31/head
Rich-Harris 8 years ago
parent b743e54c24
commit 92ba62e289

@ -9,6 +9,10 @@ import attributeLookup from './attributes/lookup.js';
import createBinding from './binding/index.js'; import createBinding from './binding/index.js';
function createRenderer ( fragment ) { function createRenderer ( fragment ) {
if ( fragment.autofocus ) {
fragment.initStatements.push( `${fragment.autofocus}.focus();` );
}
return deindent` return deindent`
function ${fragment.name} ( component, target${fragment.useAnchor ? ', anchor' : ''} ) { function ${fragment.name} ( component, target${fragment.useAnchor ? ', anchor' : ''} ) {
${fragment.initStatements.join( '\n\n' )} ${fragment.initStatements.join( '\n\n' )}
@ -111,7 +115,6 @@ export default function generate ( parsed, template ) {
]; ];
const updateStatements = []; const updateStatements = [];
const teardownStatements = []; const teardownStatements = [];
const allUsedContexts = new Set(); 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' ) { if ( attribute.name === 'autofocus' ) {
initStatements.push( `${name}.focus();` ); current.autofocus = name;
} }
} }

Loading…
Cancel
Save