-
-
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.
- Loading branch information
Showing
7 changed files
with
117 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<script> | ||
$: data = toString($$slots); | ||
$: stringified = toString($$slots); | ||
export function getData() { | ||
return data; | ||
} | ||
function toString(data) { | ||
const result = {}; | ||
const sortedKeys = Object.keys(data).sort(); | ||
sortedKeys.forEach(key => result[key] = data[key]); | ||
return JSON.stringify(result); | ||
} | ||
</script> | ||
|
||
<slot></slot> | ||
<slot name="a"></slot> | ||
|
||
$$slots: {toString($$slots)} {stringified} | ||
|
||
{#if $$slots.b} | ||
<div> | ||
<slot name="b"></slot> | ||
</div> | ||
{:else} | ||
Slot b is not available | ||
{/if} |
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,23 @@ | ||
export default { | ||
html: ` | ||
<span>bye</span><span>default</span> | ||
<span>hello a</span> | ||
$$slots: {"a":true,"default":true} {"a":true,"default":true} | ||
Slot b is not available | ||
`, | ||
|
||
async test({ assert, component, target }) { | ||
assert.equal(component.getData(), '{"a":true,"default":true}'); | ||
|
||
component.show_b = true; | ||
assert.htmlEqual(target.innerHTML, ` | ||
<span>bye</span><span>default</span> | ||
<span>hello a</span> | ||
$$slots: {"a":true,"b":true,"default":true} {"a":true,"b":true,"default":true} | ||
<div><span>hello b</span></div> | ||
`); | ||
assert.equal(component.getData(), '{"a":true,"b":true,"default":true}'); | ||
|
||
component.show_default = false; | ||
} | ||
}; |
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,30 @@ | ||
<script> | ||
import A from "./A.svelte"; | ||
let a; | ||
export let show_default = true; | ||
export let show_a = true; | ||
export let show_b = false; | ||
export function getData() { | ||
return a.getData(); | ||
} | ||
</script> | ||
|
||
<A bind:this={a}> | ||
{#if show_a} | ||
<svelte:fragment slot="a"> | ||
<span>hello a</span> | ||
</svelte:fragment> | ||
{/if} | ||
{#if show_default} | ||
<svelte:fragment slot="default"> | ||
<span>bye</span> | ||
<span>default</span> | ||
</svelte:fragment> | ||
{/if} | ||
{#if show_b} | ||
<svelte:fragment slot="b"> | ||
<span>hello b</span> | ||
</svelte:fragment> | ||
{/if} | ||
</A> |
3 changes: 3 additions & 0 deletions
3
test/runtime/samples/component-conditional-slot-10-default/Foo.svelte
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,3 @@ | ||
<div> | ||
<slot>default fallback</slot> | ||
</div> |
13 changes: 13 additions & 0 deletions
13
test/runtime/samples/component-conditional-slot-10-default/_config.js
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,13 @@ | ||
export default { | ||
html: ` | ||
<div></div> | ||
<div>default fallback</div> | ||
`, | ||
test({ assert, component, target }) { | ||
component.condition = true; | ||
assert.htmlEqual(target.innerHTML, ` | ||
<div>hello #1</div> | ||
<div>hello #2</div> | ||
`); | ||
} | ||
}; |
16 changes: 16 additions & 0 deletions
16
test/runtime/samples/component-conditional-slot-10-default/main.svelte
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,16 @@ | ||
<script> | ||
import Foo from "./Foo.svelte"; | ||
export let condition = false; | ||
</script> | ||
|
||
<Foo> | ||
{#if condition} | ||
hello #1 | ||
{/if} | ||
</Foo> | ||
|
||
<Foo> | ||
{#if condition} | ||
<svelte:fragment slot="default">hello #2</svelte:fragment> | ||
{/if} | ||
</Foo> |