mirror of https://github.com/sveltejs/svelte
fix: cursor jumps in input two way binding (#16649)
* fix : remove cursor manipulation for input bindings Old Fix: Restore input binding selection position (#14649) Current Fix: Remove unnecessary cursor manipulation as the presence of runes no longer requires special handling. * fix : add change set to my previous commit * Revert "fix : add change set to my previous commit" This reverts commitpull/16672/head6ca8ef3f97
. * fix: revert previous changeset added new to fix lint errors * chore : resolve lint error to fix pipeline issue * Revert "fix: revert previous changeset added new to fix lint errors" This reverts commit91094949a6
. * fix: input binding to handle code in a synchronous manner Introduced Promise.resolve to ensure that the 'set' operation completes before the 'get' operation Minimizing update delays. * Fix: resolve cursor jumps and change sets * better fix * test * changeset * simplify * failing test * gah we can't fix the input in an effect, need to do it here, but after a tick so that changes have been flushed through each blocks * add explanatory comment * fix test * this seems to work? --------- Co-authored-by: Hariharan Srinivasan <hariharan.srinivasan@kadfire.com> Co-authored-by: Rich Harris <rich.harris@vercel.com>
parent
6534aa08e3
commit
0d48916e02
@ -0,0 +1,5 @@
|
||||
---
|
||||
'svelte': patch
|
||||
---
|
||||
|
||||
fix: Introduced Promise.resolve to ensure that the 'set' operation completes before the 'get' operation Minimizing update delays.
|
@ -0,0 +1,5 @@
|
||||
---
|
||||
'svelte': patch
|
||||
---
|
||||
|
||||
fix: wait until changes propagate before updating input selection state
|
@ -0,0 +1,28 @@
|
||||
import { flushSync } from 'svelte';
|
||||
import { test } from '../../test';
|
||||
|
||||
export default test({
|
||||
mode: ['client', 'hydrate'],
|
||||
|
||||
html: `<input><p>a</a>`,
|
||||
|
||||
async test({ assert, target }) {
|
||||
const [input] = target.querySelectorAll('input');
|
||||
|
||||
input.focus();
|
||||
input.value = 'ab';
|
||||
input.dispatchEvent(new InputEvent('input', { bubbles: true }));
|
||||
flushSync();
|
||||
|
||||
assert.htmlEqual(target.innerHTML, `<input><p>ab</a>`);
|
||||
assert.equal(input.value, 'ab');
|
||||
|
||||
input.focus();
|
||||
input.value = 'abc';
|
||||
input.dispatchEvent(new InputEvent('input', { bubbles: true }));
|
||||
flushSync();
|
||||
|
||||
assert.htmlEqual(target.innerHTML, `<input><p>abc</a>`);
|
||||
assert.equal(input.value, 'abc');
|
||||
}
|
||||
});
|
@ -0,0 +1,8 @@
|
||||
<script>
|
||||
let array = $state([{ value: 'a' }]);
|
||||
</script>
|
||||
|
||||
{#each array as obj}
|
||||
<input bind:value={() => obj.value, (value) => array = [{ value }]} />
|
||||
<p>{obj.value}</p>
|
||||
{/each}
|
@ -0,0 +1,30 @@
|
||||
import { tick } from 'svelte';
|
||||
import { test } from '../../test';
|
||||
|
||||
export default test({
|
||||
mode: ['client', 'hydrate'],
|
||||
|
||||
async test({ assert, target }) {
|
||||
const [input] = target.querySelectorAll('input');
|
||||
|
||||
input.focus();
|
||||
input.value = 'Ab';
|
||||
input.dispatchEvent(new InputEvent('input', { bubbles: true }));
|
||||
|
||||
await tick();
|
||||
await tick();
|
||||
|
||||
assert.equal(input.value, 'AB');
|
||||
assert.htmlEqual(target.innerHTML, `<input /><p>AB</p>`);
|
||||
|
||||
input.focus();
|
||||
input.value = 'ABc';
|
||||
input.dispatchEvent(new InputEvent('input', { bubbles: true }));
|
||||
|
||||
await tick();
|
||||
await tick();
|
||||
|
||||
assert.equal(input.value, 'ABC');
|
||||
assert.htmlEqual(target.innerHTML, `<input /><p>ABC</p>`);
|
||||
}
|
||||
});
|
@ -0,0 +1,6 @@
|
||||
<script>
|
||||
let text = $state('A');
|
||||
</script>
|
||||
|
||||
<input bind:value={() => text, (v) => text = v.toUpperCase()} />
|
||||
<p>{text}</p>
|
Loading…
Reference in new issue