File tree 7 files changed +59
-1
lines changed
src/compiler/compile/render_dom/wrappers/Element
select-multiple-spread-and-bind
7 files changed +59
-1
lines changed Original file line number Diff line number Diff line change @@ -858,8 +858,9 @@ export default class ElementWrapper extends Wrapper {
858
858
}
859
859
860
860
block . chunks . mount . push ( b `
861
- (${ data } .multiple ? @select_options : @select_option)(${ this . var } , ${ data } .value);
861
+ 'value' in ${ data } && (${ data } .multiple ? @select_options : @select_option)(${ this . var } , ${ data } .value);
862
862
` ) ;
863
+
863
864
block . chunks . update . push ( b `
864
865
if (${ block . renderer . dirty ( Array . from ( dependencies ) ) } && 'value' in ${ data } ) (${ data } .multiple ? @select_options : @select_option)(${ this . var } , ${ data } .value);
865
866
` ) ;
Original file line number Diff line number Diff line change
1
+ export default {
2
+ test ( { assert, component, target } ) {
3
+ const options = target . querySelectorAll ( 'option' ) ;
4
+
5
+ assert . equal ( options [ 0 ] . selected , true ) ;
6
+ assert . equal ( options [ 1 ] . selected , false ) ;
7
+
8
+ component . value = [ '2' ] ;
9
+ assert . equal ( options [ 0 ] . selected , false ) ;
10
+ assert . equal ( options [ 1 ] . selected , true ) ;
11
+ }
12
+ } ;
Original file line number Diff line number Diff line change
1
+ <script >
2
+ import Select from ' ./select.svelte' ;
3
+
4
+ export let value = [' 1' ];
5
+ export let other = {};
6
+ </script >
7
+
8
+ <Select {value } {other } />
Original file line number Diff line number Diff line change
1
+ <script >
2
+ export let value;
3
+ export let other;
4
+ </script >
5
+
6
+ <select multiple bind:value {...other }>
7
+ <option value =" 1" >option 1</option >
8
+ <option value =" 2" >option 2</option >
9
+ </select >
Original file line number Diff line number Diff line change
1
+ export default {
2
+ test ( { assert, component, target } ) {
3
+ const options = target . querySelectorAll ( 'option' ) ;
4
+
5
+ assert . equal ( options [ 0 ] . selected , true ) ;
6
+ assert . equal ( options [ 1 ] . selected , false ) ;
7
+
8
+ // Shouldn't change the value because the value is not bound.
9
+ component . value = [ '2' ] ;
10
+ assert . equal ( options [ 0 ] . selected , true ) ;
11
+ assert . equal ( options [ 1 ] . selected , false ) ;
12
+ }
13
+ } ;
Original file line number Diff line number Diff line change
1
+ <script >
2
+ import Select from ' ./select.svelte' ;
3
+
4
+ export let attrs = { value: [' 1' ] };
5
+ </script >
6
+
7
+ <Select {attrs } />
Original file line number Diff line number Diff line change
1
+ <script >
2
+ export let attrs;
3
+ </script >
4
+
5
+ <select multiple {...attrs }>
6
+ <option value =" 1" >option 1</option >
7
+ <option value =" 2" >option 2</option >
8
+ </select >
You can’t perform that action at this time.
0 commit comments