sync state with view, if <select> binding does not have initial value (#639)

pull/641/head
Rich Harris 8 years ago
parent 5dc12bbe84
commit d3d026a510

@ -89,6 +89,11 @@ export default function visitBinding(
${ifStatement}
}
`;
generator.hasComplexBindings = true;
block.builders.create.addBlock(
`if ( !('${name}' in state) ) ${block.component}._bindings.push( ${handler} );`
);
} else if (attribute.name === 'group') {
// <input type='checkbox|radio' bind:group='selected'> special case
if (type === 'radio') {

@ -0,0 +1,26 @@
export default {
solo: true,
show: true,
html: `
<p>selected: a</p>
<select>
<option>a</option>
<option>b</option>
<option>c</option>
</select>
<p>selected: a</p>
`,
test ( assert, component, target ) {
const select = target.querySelector( 'select' );
const options = [ ...target.querySelectorAll( 'option' ) ];
assert.equal( select.value, 'a' );
assert.ok( options[0].selected );
component.destroy();
}
};

@ -0,0 +1,9 @@
<p>selected: {{selected}}</p>
<select bind:value='selected'>
<option>a</option>
<option>b</option>
<option>c</option>
</select>
<p>selected: {{selected}}</p>
Loading…
Cancel
Save