mirror of https://github.com/sveltejs/svelte
Fix: bind:scroll resets scroll state (#11469)
* Fixed: bind:scroll resets scroll state * failing test * bail if value is undefined * changeset --------- Co-authored-by: Rich Harris <rich.harris@vercel.com>pull/11474/head
parent
6bd6f0971b
commit
85d680582b
@ -0,0 +1,5 @@
|
||||
---
|
||||
'svelte': patch
|
||||
---
|
||||
|
||||
fix: only initiate scroll if scroll binding has existing value
|
@ -0,0 +1,5 @@
|
||||
<script>
|
||||
let scrollY;
|
||||
</script>
|
||||
|
||||
<svelte:window bind:scrollY/>
|
@ -0,0 +1,30 @@
|
||||
import { flushSync } from 'svelte';
|
||||
import { test } from '../../test';
|
||||
|
||||
/** @type {Window['scrollTo']} */
|
||||
let original_scrollTo;
|
||||
|
||||
export default test({
|
||||
before_test() {
|
||||
original_scrollTo = window.scrollTo;
|
||||
|
||||
// @ts-ignore
|
||||
window.scrollTo = (x, y) => {
|
||||
window.scrollX = x;
|
||||
window.scrollY = y;
|
||||
};
|
||||
},
|
||||
|
||||
after_test() {
|
||||
window.scrollTo = original_scrollTo;
|
||||
},
|
||||
|
||||
async test({ assert, component, window, target }) {
|
||||
window.scrollTo(0, 500);
|
||||
|
||||
const button = target.querySelector('button');
|
||||
flushSync(() => button?.click());
|
||||
|
||||
assert.equal(window.scrollY, 500);
|
||||
}
|
||||
});
|
@ -0,0 +1,13 @@
|
||||
<script>
|
||||
import Child from './Child.svelte';
|
||||
|
||||
let show = false;
|
||||
</script>
|
||||
|
||||
<div style='width: 100%; height: 9999px;'></div>
|
||||
|
||||
<button on:click={() => show = !show}>toggle</button>
|
||||
|
||||
{#if show}
|
||||
<Child />
|
||||
{/if}
|
Loading…
Reference in new issue