handle boolean attributes with snabbdom #53
Merged
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.
The current behaviour of how we handle boolean attributes seems to be broken. We are rendering
false as ""
andtrue as "true"
. Quoting from the HTML5 spec: "A number of attributes are boolean attributes. The presence of a boolean attribute on an element represents the true value, and the absence of the attribute represents the false value."The handling of boolean attributes was changed in the release
0.7.0
of snabbdom: https://github.com/snabbdom/snabbdom/releases/tag/v0.7.0. Previously it relied on an internal list of boolean attributes and would handle it depending on the attribute name. Now it relies on the type of the value, i.e., if the value is strictly equal to true/false, it will be handled as a boolean attribute. If true, the attribute is set with value "" and if false, the attribute is not set.Therefore I have changed the
Attr
type to have a value of either String or Boolean, so that snabbdom can handle it downstream. The BoolAttributeBuilder just passes the boolean value to the Attribute.I am not entirely sure about the change I did here with the builder. What was the
"_"
used for?Furthermore, this means, we have to take care which attributes are boolean attributes and which are enumeration (for example draggable is not a boolean attribute, but an enumeration of true|false).
This might also fix #34, however we cannot automatically infer whether a dynamic
data
-attribute is boolean (e.g. you could achieve it withnew BoolAttributeBuilder("data-close")
).