-
-
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.
fix: consistently set value to blank string when value attribute is u…
…ndefined Fixes #4467
- Loading branch information
1 parent
700029b
commit fd9dbd2
Showing
3 changed files
with
60 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
49 changes: 49 additions & 0 deletions
49
packages/svelte/tests/runtime-runes/samples/value-attribute-null-undefined/_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,49 @@ | ||
import { test, ok } from '../../test'; | ||
import { flushSync } from 'svelte'; | ||
|
||
export default test({ | ||
mode: ['client'], | ||
|
||
async test({ assert, target }) { | ||
/** | ||
* @type {HTMLInputElement | null} | ||
*/ | ||
const input = target.querySelector('input[type=text]'); | ||
/** | ||
* @type {HTMLButtonElement | null} | ||
*/ | ||
const setString = target.querySelector('#setString'); | ||
/** | ||
* @type {HTMLButtonElement | null} | ||
*/ | ||
const setNull = target.querySelector('#setNull'); | ||
/** | ||
* @type {HTMLButtonElement | null} | ||
*/ | ||
const setUndefined = target.querySelector('#setUndefined'); | ||
|
||
ok(input); | ||
ok(setString); | ||
ok(setNull); | ||
ok(setUndefined); | ||
|
||
// value should always be blank string when value attribute is set to null or undefined | ||
|
||
assert.equal(input.value, ''); | ||
setString.click(); | ||
flushSync(); | ||
assert.equal(input.value, 'foo'); | ||
|
||
setNull.click(); | ||
flushSync(); | ||
assert.equal(input.value, ''); | ||
|
||
setString.click(); | ||
flushSync(); | ||
assert.equal(input.value, 'foo'); | ||
|
||
setUndefined.click(); | ||
flushSync(); | ||
assert.equal(input.value, ''); | ||
} | ||
}); |
9 changes: 9 additions & 0 deletions
9
packages/svelte/tests/runtime-runes/samples/value-attribute-null-undefined/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,9 @@ | ||
<script> | ||
let value = $state(); | ||
</script> | ||
|
||
<input type="text" {value} /> | ||
|
||
<button id="setString" onclick={() => {value = "foo";}}></button> | ||
<button id="setNull" onclick={() => {value = null;}}></button> | ||
<button id="setUndefined" onclick={() => {value = undefined;}}></button> |