Is it possible to for the ht-attrs property to automatically set key-value pairs based on the key-value pairings of the object being provided? E.g. if the properties are valid JSON/YAML properties, and the values are String, Boolean, or Number types, could HT assume that, if not given a name, each property name should be used with each value being assigned to said property?
To illustrate… I’d love for the following to work. If given an object like:
link:
content: Example
attrs:
href: "/example"
class: "button-primary"
aria-current: "page"
I didn’t understand at first what the ask is here, but the examples help a lot. It’s a good idea!
In fact, those numbered attributes are an evidence of some unfinished work in the ht-attrs implementation. I wanted ht-attrs to be robust enough to handle incorrectly formatted directives (i.e. an attribute with no name), but I also thought no one would find those data-attr-x numbered attributes to be useful, haha. I was basically hoping they would prompt some feedback that could steer me in the right direction. And it has!
Let me think on this one, but my hot take is that this is a really good idea and it feels kinda obvious (in hindsight) that I should have done this in the first place.
I’m going to hold off on posting the announcement until tomorrow, but I just cut a v0.18.0 release of hyperctl that includes support for attribute maps!
Let me know what you think about this approach. I hope it helps!
Instead of passing <nil> as a string value, would it make more sense for the empty key-value pair (in this example, example_data.image.alt) to be handled in one of the following manners?
Add alt to the element without setting a value: <img alt ...> (might show a warning in the browser developer tools.)
Add alt to the element with an empty value: <img alt="" ...> (should not show a warning in the browser developer tools.)
Do not add alt to the element: <img ...> (For certain elements, like the img element, might show a warning in the browser developer tools.)
I like option 3 the best.
I noticed right now that if I want to set an attribute like disabled to input elements I need to pass the key-value pairing like so: disabled: "" (this becomes a standalone disabled attribute on the element)