mirror of https://github.com/sveltejs/svelte
fix: only skip updating bound `<input>` if the input was the source of the change (#16373)
* fix: only skip updating bound `<input>` if the input was the source of the change * import Batch as type, not valuepull/16374/head
parent
1e4547b005
commit
9134caca24
@ -0,0 +1,5 @@
|
||||
---
|
||||
'svelte': patch
|
||||
---
|
||||
|
||||
fix: only skip updating bound `<input>` if the input was the source of the change
|
@ -0,0 +1,40 @@
|
||||
import { flushSync } from 'svelte';
|
||||
import { test } from '../../test';
|
||||
|
||||
export default test({
|
||||
mode: ['client', 'hydrate'],
|
||||
|
||||
async test({ assert, target }) {
|
||||
const [input] = target.querySelectorAll('input');
|
||||
|
||||
flushSync(() => {
|
||||
input.focus();
|
||||
input.dispatchEvent(new KeyboardEvent('keydown', { key: 'ArrowUp', bubbles: true }));
|
||||
});
|
||||
assert.equal(input.value, '2');
|
||||
assert.htmlEqual(
|
||||
target.innerHTML,
|
||||
`
|
||||
<label>
|
||||
<input /> arrow up/down
|
||||
</label>
|
||||
<p>value = 2</p>
|
||||
`
|
||||
);
|
||||
|
||||
flushSync(() => {
|
||||
input.focus();
|
||||
input.dispatchEvent(new KeyboardEvent('keydown', { key: 'ArrowDown', bubbles: true }));
|
||||
});
|
||||
assert.equal(input.value, '1');
|
||||
assert.htmlEqual(
|
||||
target.innerHTML,
|
||||
`
|
||||
<label>
|
||||
<input /> arrow up/down
|
||||
</label>
|
||||
<p>value = 1</p>
|
||||
`
|
||||
);
|
||||
}
|
||||
});
|
@ -0,0 +1,16 @@
|
||||
<script>
|
||||
let value = $state('1');
|
||||
|
||||
function onkeydown (e) {
|
||||
let _v = parseFloat(value);
|
||||
if (e.key === 'ArrowUp') _v += 1;
|
||||
else if (e.key === 'ArrowDown') _v -= 1;
|
||||
value = _v.toString();
|
||||
}
|
||||
</script>
|
||||
|
||||
<label>
|
||||
<input bind:value {onkeydown} /> arrow up/down
|
||||
</label>
|
||||
|
||||
<p>value = {value}</p>
|
Loading…
Reference in new issue