Skip to content

Setting the value of an input doesn't update value bindings #14865

@Ocean-OS

Description

@Ocean-OS

Describe the bug

If you use bind:value on an input and access the input element (either using bind:this or some other method), and then set the value of the input using the element's reference like so...

<script>
let value = $state("");
let input = $state();
</script>
Hello, {value}!<br>
<input type="text" bind:value bind:this={input} />
<button onclick={()=>input.value = ""}>Clear value</button>

The value variable doesn't stay synchronized with the input's value.

Reproduction

REPL

Logs

No response

System Info

N/A

Severity

annoyance

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions