az5112
az5112

Reputation: 642

How to modify Html.Node in Elm

How would I go about modifying an existing Html.Node in Elm?

I would like to create a function with the following signature that would add an extra attribute to the input node.

  addAttribute : Html msg -> Attribute msg -> Html msg

Given

  node = Html.div [] [Html.text "dummy"]
  attr = Html.Attributes.style "display" : "inline-block"

a call to addAttribute node attr should return

  Html.div [Html.Attributes.style "display" "inline-block"] [Html.text "dummy"]

Upvotes: 1

Views: 94

Answers (1)

pdamoc
pdamoc

Reputation: 2923

Html msg nodes are opaque by design. There is no way to access their structure and add attributes or children after they have been created.

You will need to find a different approach to building the node.

What I usually do is create some kind of Cfg msg record that is passed to some function that generates the node I need. I can then pass styles or optional children through that record.

Upvotes: 3

Related Questions