https://kotlinlang.org logo
#compose-web
Title
# compose-web
b

Big Chungus

09/27/2021, 11:09 PM
Is it possible to set a boolean html attribute (not property) with compose? attr("name", true.unsafeCast<String>()) sets it as name="", whereas it should set it as just name with no empty string value.
r

rnett

09/27/2021, 11:13 PM
Isn't the convention for flag properties to do
$name="$name"
?
b

Big Chungus

09/28/2021, 12:43 AM
Haven't tried that yet, will give it a go and report back
s

shikasd

09/28/2021, 12:49 AM
attr("name", "true")
?
b

Big Chungus

09/28/2021, 7:08 AM
Nope, that one is read as true even if you pass in false value
a

Akif Abasov [JB]

09/28/2021, 4:47 PM
I believe it’s because of this behaviour of
setAttribute
Can you specify your use case?
b

Big Chungus

09/28/2021, 4:50 PM
Setting
checked
attribute on input element. Here's the end result I'm chasing:
<input type="checkbox" checked></input>
And i need that to be an html attribute as opposed to property
a

Akif Abasov [JB]

09/29/2021, 7:01 AM
We will take a look how to manage it.
Is workaround clear for you until that? using dom effect.
b

Big Chungus

09/29/2021, 7:20 AM
Yeah, but it's kinda ugly 😀
👌 1
u

[JB] Shagen

10/14/2021, 8:56 AM
Correct me if I'm wrong but boolean attribute with space is actually by spec a valid way to switch it "on". Not saying we shouldn't discuss API improvements, just want to see the whole picture
b

Big Chungus

10/14/2021, 8:57 AM
That might be true by spec, but many web frameworks don't follow it and demand empty attr without a value to work
8 Views