Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Boolean attributes that evaluate to false not being omitted as expected #1554

Closed
mdubb86 opened this issue Jun 22, 2018 · 7 comments
Closed

Comments

@mdubb86
Copy link

mdubb86 commented Jun 22, 2018

I'm almost certain I'm missing something here since I've seen this question asked/answered before but can't figure it out.

If you inspect the header element in the example below in devtools the 'hidden' attribute is completely removed when set to false (expected) but the 'disabled' attribute results in disabled="false" (unexpected).

https://svelte.technology/repl?version=2.8.0&gist=da9d9432c9aab7b8c47a5bd5c4f57b29

Is this expected behavior? Is there a defined list of attributes that are allowed? Thanks!

@Rich-Harris
Copy link
Member

This is expected — disabled has no meaning in the context of an <h1> element, whereas hidden does. If it was a button instead, disabled would get treated as a boolean property rather than an unknown attribute (which would show up in the DOM).

You can see a list of the elements and attributes that get this treatment here — the list is derived from this MDN page.

@Conduitry
Copy link
Member

Conduitry commented Jun 22, 2018

Hm. I'm forgetting right now why this was necessary then. That's only getting used for SSR. The nuances of something that I must have previously thought I understood are eluding me.

The relevant issue was #1109. I'm going to read through that again.

Edit:

For DOM code, we'd continue to use the attributes-to-props lookup as it exists now, and rely on browsers to do the right thing.

This seems to be an important observation from my past self. The attribute-to-prop lookup is just for attributes that have corresponding props, and it basically then unrelated from what's happening during SSR, which obviously always uses the attribute name forms.

@Rich-Harris
Copy link
Member

oh, yeah. that seems like it might be the wrong fix for that SSR problem; it should be determining whether it truly is a boolean attribute for the element in question. Is a real edge case though, probably doesn't need an urgent fix

@mdubb86
Copy link
Author

mdubb86 commented Jun 22, 2018

Got it, sorry about that! I was using it on something like <a class="button">Anchor</a> and <a> is also not on that list. I'll see about using a <button> element instead. Thanks for your help!

@N-McA
Copy link

N-McA commented Jul 19, 2018

Some CSS frameworks seem to detect 'disabled' on tags; this means that using disabled={false} on an a element will render as disabled with Svelte. This seems like a bug to me.

@antony
Copy link
Member

antony commented Oct 15, 2018

@N-McA I've just run into this with Bulma. It's pretty common practice now to use the [disabled] attribute selector, so this does indeed break the model.

@Conduitry
Copy link
Member

If we're going to provide some nice way of conditionally including an attribute, it's going to be via something like #1434, and not via special handling of disabled that happens regardless of whether it's a valid boolean attribute on the given element. Closing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants