diff options
author | Hayleigh Thompson <me@hayleigh.dev> | 2024-03-14 06:46:02 +0100 |
---|---|---|
committer | Hayleigh Thompson <me@hayleigh.dev> | 2024-03-14 06:47:00 +0100 |
commit | e689c185024783c72952ed00283f82b8e585133a (patch) | |
tree | 0647e573860e8f0834dba4741419b6a9bcdd2528 | |
parent | 1c80731d39b159e86d24ee9f5e61c58d18e1d81c (diff) | |
download | lustre-e689c185024783c72952ed00283f82b8e585133a.tar.gz lustre-e689c185024783c72952ed00283f82b8e585133a.zip |
:bug: Fixed a bug where boolean attributes were stringified correctly on erlang.
-rw-r--r-- | src/lustre/internals/vdom.gleam | 21 |
1 files changed, 14 insertions, 7 deletions
diff --git a/src/lustre/internals/vdom.gleam b/src/lustre/internals/vdom.gleam index c803b44..0cb4811 100644 --- a/src/lustre/internals/vdom.gleam +++ b/src/lustre/internals/vdom.gleam @@ -265,13 +265,18 @@ fn attributes_to_string_builder( html, class, style, - inner_html - <> val, + inner_html <> val, ) Ok(#("class", val)) if class == "" -> #(html, val, style, inner_html) Ok(#("class", val)) -> #(html, class <> " " <> val, style, inner_html) Ok(#("style", val)) if style == "" -> #(html, class, val, inner_html) Ok(#("style", val)) -> #(html, class, style <> " " <> val, inner_html) + Ok(#(key, "")) -> #( + string_builder.append(html, " " <> key), + class, + style, + inner_html, + ) Ok(#(key, val)) -> #( string_builder.append(html, " " <> key <> "=\"" <> val <> "\""), class, @@ -321,17 +326,19 @@ fn attribute_to_string_parts( Attribute("", _, _) -> Error(Nil) Attribute("dangerous-unescaped-html", _, _) -> Error(Nil) Attribute(name, value, as_property) -> { + let true_atom = dynamic.from(True) + case dynamic.classify(value) { "String" -> Ok(#(name, dynamic.unsafe_coerce(value))) // Boolean attributes are determined based on their presence, eg we don't // want to render `disabled="false"` if the value is `false` we simply // want to omit the attribute altogether. - "Boolean" -> - case dynamic.unsafe_coerce(value) { - True -> Ok(#(name, name)) - False -> Error(Nil) - } + // + // On the Erlang target, booleans are actually just the atoms `true` and + // `false`! + "Atom" | "Boolean" if value == true_atom -> Ok(#(name, "")) + "Atom" | "Boolean" -> Error(Nil) // For everything else, we care whether or not the attribute is actually // a property. Properties are *Javascript* values that aren't necessarily |