-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
two-way binding with <select multiple>
- Loading branch information
Showing
4 changed files
with
101 additions
and
15 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
export default { | ||
skip: true, // selectedOptions doesn't work in JSDOM??? | ||
|
||
data: { | ||
selected: [ 'two', 'three' ] | ||
}, | ||
|
||
html: ` | ||
<select> | ||
<option>one</option> | ||
<option>two</option> | ||
<option>three</option> | ||
</select> | ||
<p>selected: two, three</p> | ||
`, | ||
|
||
test ( assert, component, target, window ) { | ||
const select = target.querySelector( 'select' ); | ||
const options = [ ...target.querySelectorAll( 'option' ) ]; | ||
|
||
const change = new window.Event( 'change' ); | ||
|
||
options[1].selected = false; | ||
select.dispatchEvent( change ); | ||
|
||
assert.deepEqual( component.get( 'selected' ), [ 'three' ] ); | ||
assert.htmlEqual( target.innerHTML, ` | ||
<select> | ||
<option>one</option> | ||
<option>two</option> | ||
<option>three</option> | ||
</select> | ||
<p>selected: three</p> | ||
` ); | ||
|
||
options[0].selected = true; | ||
select.dispatchEvent( change ); | ||
|
||
assert.deepEqual( component.get( 'selected' ), [ 'one', 'three' ] ); | ||
assert.htmlEqual( target.innerHTML, ` | ||
<select> | ||
<option>one</option> | ||
<option>two</option> | ||
<option>three</option> | ||
</select> | ||
<p>selected: one, three</p> | ||
` ); | ||
|
||
component.set({ selected: [ 'one', 'two' ] }); | ||
|
||
assert.ok( options[0].selected ); | ||
assert.ok( options[1].selected ); | ||
assert.ok( !options[2].selected ); | ||
|
||
assert.htmlEqual( target.innerHTML, ` | ||
<select> | ||
<option>one</option> | ||
<option>two</option> | ||
<option>three</option> | ||
</select> | ||
<p>selected: one, two</p> | ||
` ); | ||
} | ||
}; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<select multiple bind:value='selected'> | ||
<option>one</option> | ||
<option>two</option> | ||
<option>three</option> | ||
</select> | ||
|
||
<p>selected: {{selected.join( ', ' )}}</p> |