Boolean attributes #159
goertzenator
started this conversation in
Ideas
Replies: 1 comment
-
Reasonable topic.
Taking a Bool is simple and an easy addition. Although I’d prefer some other naming convention than the prime. Maybe “checkedIf_” or something like that.
I won’t introduce breaking changes but very happy to add docs regarding “no-op” attribute values, perhaps pointing to the better option.
Haven’t been at the personal laptop keyboard for a few days, sorry for the slow reply.
On Wed, Oct 30, 2024, at 2:11 PM, Daniel Goertzen wrote:
HTML boolean attributes are awkward to deal with because their presence or absence indicates their value rather than a boolean parameter. When working with these attributes in Lucid2 one is compelled to do things like this:
`i1 = input_ ([type_ "checkbox", name_ "check1" ] <> if doChecked then [checked_] else [])
i2 = input_ ([type_ "checkbox", name_ "check2" ] <> ([checked_ | doChecked]))
i3 = input_ [type_ "checkbox", name_ "check3", if doChecked then checked_ else mempty]
i4 = input_ [type_ "checkbox", name_ "check4", bool mempty checked_ doChecked]
`
React and Alpine.js (and likely many others) paper over that by making boolean attributes work like a parameterized attribute taking a bool, which works out nicely:
`i5 = input_ [type_ "checkbox", name_ "check5", checked_' doChecked]
`
I'd like to suggest that parameterized boolean attributes be added to Lucid2:
`checked_' :: Bool -> Attributes
checked_' = bool mempty checked_
autofocus_' :: Bool -> Attributes
autofocus_' = bool mempty autofocus_
disabled_' :: Bool -> Attributes
disabled_' = bool mempty (makeAttributes "disabled" mempty)
`
… One other observation: The existing `disabled_` attribute takes a `Text` parameter. This is tolerated by HTML5, but does nothing <https://developer.mozilla.org/en-US/docs/Glossary/Boolean/HTML>. It should probably be removed, or if it needs to be preserved for compatibility, at least document that it functionally does nothing.
Thoughts?
—
Reply to this email directly, view it on GitHub <#159>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/AAACWC4UGBY7RKG2PLBWU53Z6DSKTAVCNFSM6AAAAABQ4GVSTOVHI2DSMVQWIX3LMV43ERDJONRXK43TNFXW4OZXGM4TMMZUG4>.
You are receiving this because you are subscribed to this thread.Message ID: ***@***.***>
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
HTML boolean attributes are awkward to deal with because their presence or absence indicates their value rather than a boolean parameter. When working with these attributes in Lucid2 one is compelled to do things like this:
React and Alpine.js (and likely many others) paper over that by making boolean attributes work like a parameterized attribute taking a bool, which works out nicely:
I'd like to suggest that parameterized boolean attributes be added to Lucid2:
One other observation: The existing
disabled_
attribute takes aText
parameter. This is tolerated by HTML5, but does nothing. It should probably be removed, or if it needs to be preserved for compatibility, at least document that it functionally does nothing.Thoughts?
Beta Was this translation helpful? Give feedback.
All reactions