File tree 3 files changed +32
-0
lines changed
packages/svelte/tests/runtime-runes/samples/props-bound-fallback
3 files changed +32
-0
lines changed Original file line number Diff line number Diff line change
1
+ <script >
2
+ let { count = 0 } = $props ();
3
+ </script >
4
+
5
+ <span >{count }</span >
Original file line number Diff line number Diff line change
1
+ import { test } from '../../test' ;
2
+
3
+ // Tests that fallback value is propagated up correctly when the inner component
4
+ // uses a prop it does not write to but has a fallback value
5
+ export default test ( {
6
+ accessors : false , // so that prop actually becomes $.prop and not $.prop_source
7
+ html : `<button>0</button><span>0</span>` ,
8
+
9
+ async test ( { assert, target } ) {
10
+ const btn = target . querySelector ( 'button' ) ;
11
+
12
+ await btn ?. click ( ) ;
13
+
14
+ assert . htmlEqual ( target . innerHTML , `<button>1</button><span>1</span>` ) ;
15
+ } ,
16
+
17
+ error : `Cannot use fallback values with bind:`
18
+ } ) ;
Original file line number Diff line number Diff line change
1
+ <script >
2
+ import Counter from ' ./Counter.svelte' ;
3
+
4
+ let bound = $state ();
5
+ </script >
6
+
7
+ <button on:click ={() => bound = 1 }>{bound }</button >
8
+
9
+ <Counter bind:count ={bound } />
You can’t perform that action at this time.
0 commit comments