Treat false attribute values like null/undefined#98
Open
kyptin wants to merge 1 commit intohyperhype:masterfrom
Open
Treat false attribute values like null/undefined#98kyptin wants to merge 1 commit intohyperhype:masterfrom
kyptin wants to merge 1 commit intohyperhype:masterfrom
Conversation
Null and undefined attribute values are omitted, which is
convenient.
Having false attribute values be omitted would also be convenient.
Before this commit, a false value results in an actual attribute
added to the element, e.g.:
const h = require('hyperscript')
h('input', {type: 'text', name: null, required: false}).outerHTML
...which yields:
'<input type="text" required="false">'
This commit makes false-valued attributes be omitted, so that the
above example would instead yield:
'<input type="text">'
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Treat false attribute values like null/undefined
I noticed that when an attribute value is
nullorundefined, it's omitted entirely:This is convenient (and maybe worth mentioning in the README as a feature) because I can have fewer conditionals in my code.
However,
falseis handled differently:In particular, this is a (very slight) pain point when handling the
requiredattribute of inputs.Notice the extra noise for the
requiredattribute, which is needed so that a value offalseomits the attribute entirely. (Per the HTML spec, any value for therequiredattribute means that the input is required, so the attribute must be omitted entirely.)I can't think of a use case where the current behavior is convenient. My idea would technically be a breaking change, but (I think) worth it. Unless I'm missing a good use case for the current behavior.