lustre-labs / lustre

An Elm-inspired framework for building HTML templates, single page applications, and server-rendered components in Gleam!
https://hexdocs.pm/lustre
MIT License
727 stars 52 forks source link

Regression: select with option selected at start #105

Closed ghivert closed 2 months ago

ghivert commented 2 months ago

When setting selected on an option in a select at first paint, the field is not the one selected.

Demo

https://github.com/lustre-labs/lustre/assets/7314118/34c4b3cd-1602-4fea-9dc9-fc1de6060fa4

Gleam code as pseudo-code

h.select([event.on_input(on_cs_input), s.select_cs()], {
  use item <- list.map(list_)
  let selected = selected_item == item
  h.option([a.value(as_s), a.selected(selected)], as_s)
})

HTML produced

<select class="css-0006">
  <option value="Ayu Dark" selected="false">Ayu Dark</option>
  <option value="Ayu Light" selected="true">Ayu Light</option>
  <option value="Gleam" selected="false">Gleam</option>
</select>

And yet, it displays "Gleam" (the last one).