Skip to content

data-bind:files fails to clear native file input value when signal is reset #1119

@jiajing21387177

Description

@jiajing21387177

Bug Report

Description:
There is a synchronization issue with data-bind:files. While the binding correctly updates the signal when files are selected, the reverse is not true for clearing data. Programmatically resetting the signal (e.g., $files = [] or $files.length = 0) empties the reactive state but fails to reset the native DOM element's value to "".

This results in a UI mismatch: the application state behaves as if no files are selected, but the browser's file input control still displays the previous file count (e.g., "2 files").

Reproduction Steps:

  1. Create an input with data-bind:files.
  2. Select single or multiple files using the browser dialog.
  3. Observe that the signal (e.g., $files) is correctly populated with file data.
  4. Trigger an action that sets the signal to an empty array: $files = [].

Reproduction Demo: https://codepen.io/jiajing2138/pen/MYeyGpY

Expected Behavior:
The $files signal should empty and the native file input should visually reset to "No file chosen" (effectively executing input.value = "").

Actual Behavior:
The $files signal empties correctly (evidenced by reactive elements hiding/clearing), but the native <input> element retains and displays the previous file count.

Datastar Version

v1.0.0-RC.7

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions