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
738 stars 52 forks source link

Boolean attributes don't seem to apply #55

Closed brattonross closed 3 months ago

brattonross commented 3 months ago

Using boolean attributes on elements doesn't appear to work as expected, I'm only using lustre to render html elements to strings, so I'm not sure if this affects the SPA side of things.

For example:

import gleam/io
import lustre/attribute
import lustre/element
import lustre/element/html

// executing the following I would expect "<input disabled>", but we get "<input>"
pub fn main() {
  html.input([attribute.disabled(True)])
  |> element.to_string
  |> io.println
}

I would assume that this is because boolean attributes are being registered as properties, instead of attributes, and so we are never hitting the boolean case here, but that's just a guess from a quick glance at the code.

Happy to take a look and make a PR

hayleigh-dot-dev commented 3 months ago

I would assume that this is because boolean attributes are being registered as properties, instead of attributes, and so we are never hitting the boolean case here, but that's just a guess from a quick glance at the code.

Hmm no that case should still be hit, I will investigate!

hayleigh-dot-dev commented 3 months ago

Ah uncovered. On the erlang target dynamic.classify(dynamic.from(True)) gives us "Atom" not "Boolean" (because bools are just atoms!). I can special-case this one.

hayleigh-dot-dev commented 3 months ago

Fixed and will be live either in the next rc or v4 if i publish that instead :)

brattonross commented 3 months ago

Great, thanks!