Skip to content

undefined value on input and other elements #4467

@PatrickG

Description

@PatrickG

Describe the bug
The value prop behaves differently in various situations.

Suppose we have a variable let value = undefined.

If you use it on an input element with two-way binding <input bind:value />, the value is not set (this is the correct behavior, it got fixed in #3430).
If you use it on an input element like this: <input {value} />, the input elements value property is set to the string 'undefined' (not the attribute).
If you use it on any other element, like: <option {value} />, the value attribute is set to "undefined".

To Reproduce
https://svelte.dev/repl/9a8cf877df9a47948eb0cd3b04ea8372?version=3.19.1

Expected behavior
I think the value attribute (without two-way binding) should behave like the disabled attribute in the repl.

Severity
low

Additional context
You can get around it with <input value={value || ''} />

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugcompilerChanges relating to the compiler

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions