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 element attributes (disabled, checked, etc.) #295

Closed
jjt opened this issue Jan 22, 2014 · 4 comments
Closed

Boolean element attributes (disabled, checked, etc.) #295

jjt opened this issue Jan 22, 2014 · 4 comments

Comments

@jjt
Copy link

jjt commented Jan 22, 2014

This is how I've been conditionally putting the disabled attribute on elements, with a boolean variable:

<input disabled={isDisabled} type=... />

When disabled is falsey, the attribute won't be added. When true, it will output the following, which works in browsers but is against the HTML5 spec:

<input disabled="true" type=... />

I could get in line with the spec by setting disabled="disabled" on the element, but that requires a ternary operation instead of a boolean:

<input disabled={isDisabled ? "disabled" : false} ... />

Ideally, my current bit of JSX (at the top of this issue) would output this HTML, assuming disabled is set to true:

<input disabled type=... />
@jjt
Copy link
Author

jjt commented Jan 23, 2014

Just had a thought. If a known boolean attribute gets assigned a true variable as in my example, JSX should output just the attribute as per the spec. If we assign a string to a boolean attribute, it can output an attribute with a value.

@kazuho
Copy link
Member

kazuho commented Jan 24, 2014

I am afraid you are looking for a different "JSX." Maybe https://github.com/facebook/react ?

@kazuho kazuho closed this as completed Jan 24, 2014
@jjt
Copy link
Author

jjt commented Jan 24, 2014

Sorry, I thought they were related!

Hopefully you don't get this too often :p

@waldyrious
Copy link

Hopefully you don't get this too often :p

Unfortunately that's not the case -- see #305.

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

3 participants