diff options
author | Hayleigh Thompson <me@hayleigh.dev> | 2024-04-16 21:57:51 +0100 |
---|---|---|
committer | Hayleigh Thompson <me@hayleigh.dev> | 2024-04-16 21:57:51 +0100 |
commit | 5d5b513449017118134a32571dceba754ca1c4f5 (patch) | |
tree | 8139b9e7ddd060c178527fb1e006f3a251bddb57 /src | |
parent | 6c05744eda896ac89e21f8ff32116340564a4773 (diff) | |
download | lustre-5d5b513449017118134a32571dceba754ca1c4f5.tar.gz lustre-5d5b513449017118134a32571dceba754ca1c4f5.zip |
:bug: Fixed a bug where the 'selected' attribute was not properly applied in the DOM.
Diffstat (limited to 'src')
-rw-r--r-- | src/lustre/attribute.gleam | 12 | ||||
-rw-r--r-- | src/vdom.ffi.mjs | 7 |
2 files changed, 9 insertions, 10 deletions
diff --git a/src/lustre/attribute.gleam b/src/lustre/attribute.gleam index 5588c73..7b3248d 100644 --- a/src/lustre/attribute.gleam +++ b/src/lustre/attribute.gleam @@ -95,11 +95,11 @@ pub fn classes(names: List(#(String, Bool))) -> Attribute(msg) { "class", names |> list.filter_map(fn(class) { - case class.1 { - True -> Ok(class.0) - False -> Error(Nil) - } - }) + case class.1 { + True -> Ok(class.0) + False -> Error(Nil) + } + }) |> string.join(" "), ) } @@ -123,7 +123,7 @@ pub fn type_(name: String) -> Attribute(msg) { /// pub fn value(val: String) -> Attribute(msg) { - property("value", dynamic.from(val)) + attribute("value", val) } /// diff --git a/src/vdom.ffi.mjs b/src/vdom.ffi.mjs index 07dc525..9e2a284 100644 --- a/src/vdom.ffi.mjs +++ b/src/vdom.ffi.mjs @@ -218,10 +218,9 @@ function createElementNode({ prev, next, dispatch, stack }) { for (const attr of next.attrs) { const name = attr[0]; const value = attr[1]; - const isProperty = attr[2]; // Properties are set directly on the DOM node. - if (isProperty) { + if (attr.as_property) { el[name] = value; } // Event handlers require some special treatment. We have a generic event @@ -267,8 +266,8 @@ function createElementNode({ prev, next, dispatch, stack }) { // tell which attributes are mirrored as properties on the DOM node we assume // that all attributes should be set as properties too. else { - el.setAttribute(name, value); - if (name === "value") el[name] = value; + if (typeof value === "string") el.setAttribute(name, value); + if (name === "value" || name === "selected") el[name] = value; // If we're morphing an element we remove this attribute's name from the set // of attributes that were on the previous render so we don't remove it in // the next step. |