File tree 4 files changed +44
-4
lines changed
src/compiler/compile/render_dom/wrappers/Element
js/samples/select-dynamic-value
runtime/samples/binding-select-null-placeholder
4 files changed +44
-4
lines changed Original file line number Diff line number Diff line change @@ -171,7 +171,7 @@ export default class AttributeWrapper extends BaseAttributeWrapper {
171
171
}
172
172
173
173
if ( is_indirectly_bound_value ) {
174
- const update_value = b `${ element . var } .value = ${ element . var } .__value;` ;
174
+ const update_value = b `@set_input_value( ${ element . var } , ${ element . var } .__value) ;` ;
175
175
block . chunks . hydrate . push ( update_value ) ;
176
176
177
177
updater = b `
Original file line number Diff line number Diff line change 8
8
insert ,
9
9
noop ,
10
10
safe_not_equal ,
11
- select_option
11
+ select_option ,
12
+ set_input_value
12
13
} from "svelte/internal" ;
13
14
14
15
function create_fragment ( ctx ) {
@@ -24,9 +25,9 @@ function create_fragment(ctx) {
24
25
option1 = element ( "option" ) ;
25
26
option1 . textContent = "2" ;
26
27
option0 . __value = "1" ;
27
- option0 . value = option0 . __value ;
28
+ set_input_value ( option0 , option0 . __value ) ;
28
29
option1 . __value = "2" ;
29
- option1 . value = option1 . __value ;
30
+ set_input_value ( option1 , option1 . __value ) ;
30
31
} ,
31
32
m ( target , anchor ) {
32
33
insert ( target , select , anchor ) ;
Original file line number Diff line number Diff line change
1
+ const items = [ { id : 'a' } , { id : 'b' } ] ;
2
+
3
+ export default {
4
+ props : {
5
+ foo : null ,
6
+ items
7
+ } ,
8
+
9
+ test ( { assert, component, target } ) {
10
+ const select = target . querySelector ( 'select' ) ;
11
+ const options = target . querySelectorAll ( 'option' ) ;
12
+
13
+ assert . equal ( options [ 0 ] . selected , true ) ;
14
+ assert . equal ( options [ 0 ] . disabled , true ) ;
15
+ assert . equal ( options [ 1 ] . selected , false ) ;
16
+ assert . equal ( options [ 1 ] . disabled , false ) ;
17
+
18
+ // placeholder option value must be blank string for native required field validation
19
+ assert . equal ( options [ 0 ] . value , '' ) ;
20
+ assert . equal ( select . checkValidity ( ) , false ) ;
21
+
22
+ component . foo = items [ 0 ] ;
23
+
24
+ assert . equal ( options [ 0 ] . selected , false ) ;
25
+ assert . equal ( options [ 1 ] . selected , true ) ;
26
+ assert . equal ( select . checkValidity ( ) , true ) ;
27
+ }
28
+ } ;
Original file line number Diff line number Diff line change
1
+ <script >
2
+ export let foo;
3
+ export let items;
4
+ </script >
5
+
6
+ <select bind:value ={foo } required >
7
+ <option value ={null } disabled >Select an option</option >
8
+ {#each items as item }
9
+ <option value ={item }>{item .id }</option >
10
+ {/each }
11
+ </select >
You can’t perform that action at this time.
0 commit comments