mirror of https://github.com/sveltejs/svelte
parent
8a7ae2e89f
commit
e82ddd6ea9
@ -0,0 +1,9 @@
|
||||
<script>
|
||||
import { getPortalKey } from './main.svelte';
|
||||
</script>
|
||||
|
||||
{#portal getPortalKey()}
|
||||
on page A
|
||||
{/portal}
|
||||
|
||||
<p>contents of page A</p>
|
||||
@ -0,0 +1,9 @@
|
||||
<script>
|
||||
import { getPortalKey } from './main.svelte';
|
||||
</script>
|
||||
|
||||
{#portal getPortalKey()}
|
||||
on page B
|
||||
{/portal}
|
||||
|
||||
<p>contents of page B</p>
|
||||
@ -0,0 +1,13 @@
|
||||
import { flushSync } from 'svelte';
|
||||
import { test } from '../../test';
|
||||
|
||||
export default test({
|
||||
html: '<div>on page A</div> <button>switch page</button> <p>contents of page A</p>',
|
||||
test({ assert, target }) {
|
||||
const [toggle] = target.querySelectorAll('button');
|
||||
|
||||
toggle.click();
|
||||
flushSync();
|
||||
assert.htmlEqual(target.innerHTML, '<div>on page B</div> <button>switch page</button> <p>contents of page B</p>');
|
||||
}
|
||||
});
|
||||
@ -0,0 +1,24 @@
|
||||
<script module>
|
||||
import { createContext } from 'svelte';
|
||||
|
||||
const [getPortalKey, setPortalKey] = createContext();
|
||||
export { getPortalKey };
|
||||
</script>
|
||||
|
||||
<script>
|
||||
import PageA from './PageA.svelte';
|
||||
import PageB from './PageB.svelte';
|
||||
|
||||
const portalKey = Symbol('portal');
|
||||
setPortalKey(portalKey);
|
||||
|
||||
let Page = $state(PageA);
|
||||
</script>
|
||||
|
||||
<div>
|
||||
{@portal portalKey}
|
||||
</div>
|
||||
|
||||
<button onclick={() => Page = Page === PageA ? PageB : PageA}>switch page</button>
|
||||
|
||||
<Page />
|
||||
Loading…
Reference in new issue