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

handle boolean attributes with snabbdom #53

Merged
merged 1 commit into from
Oct 2, 2017

Conversation

cornerman
Copy link
Member

The current behaviour of how we handle boolean attributes seems to be broken. We are rendering false as "" and true 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 with new BoolAttributeBuilder("data-close")).

@cornerman cornerman mentioned this pull request Oct 2, 2017
@LukaJCB LukaJCB merged commit 1a7c0e2 into outwatch:master Oct 2, 2017
@cornerman cornerman deleted the boolean-attrs branch October 2, 2017 11:11
@cornerman cornerman mentioned this pull request Oct 16, 2017
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

Successfully merging this pull request may close these issues.

EmptyAttributeBuilder missing?
2 participants