mirror of https://github.com/sveltejs/svelte
use <option> children as value attribute, if none exists. fixes #928
parent
4411ab116e
commit
7e07cde021
@ -0,0 +1,40 @@
|
||||
export default {
|
||||
data: {
|
||||
values: [1, 2, 3],
|
||||
foo: 2
|
||||
},
|
||||
|
||||
html: `
|
||||
<select>
|
||||
<option value='1'>1</option>
|
||||
<option value='2'>2</option>
|
||||
<option value='3'>3</option>
|
||||
</select>
|
||||
|
||||
<p>foo: 2</p>
|
||||
`,
|
||||
|
||||
test(assert, component, target, window) {
|
||||
const select = target.querySelector('select');
|
||||
const options = [...target.querySelectorAll('option')];
|
||||
|
||||
assert.ok(options[1].selected);
|
||||
assert.equal(component.get('foo'), 2);
|
||||
|
||||
const change = new window.Event('change');
|
||||
|
||||
options[2].selected = true;
|
||||
select.dispatchEvent(change);
|
||||
|
||||
assert.equal(component.get('foo'), 3);
|
||||
assert.htmlEqual( target.innerHTML, `
|
||||
<select>
|
||||
<option value='1'>1</option>
|
||||
<option value='2'>2</option>
|
||||
<option value='3'>3</option>
|
||||
</select>
|
||||
|
||||
<p>foo: 3</p>
|
||||
` );
|
||||
}
|
||||
};
|
@ -0,0 +1,7 @@
|
||||
<select bind:value='foo'>
|
||||
{{#each values as v}}
|
||||
<option>{{v}}</option>
|
||||
{{/each}}
|
||||
</select>
|
||||
|
||||
<p>foo: {{foo}}</p>
|
Loading…
Reference in new issue