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 numbers in styles #46

Merged
merged 2 commits into from
Nov 10, 2017

Conversation

acstll
Copy link
Contributor

@acstll acstll commented Nov 9, 2017

This would solve #18

You can write

h("div", { style: { opacity: 0 } })

and get

<div style="opacity: 0;"></div>

@codecov-io
Copy link

Codecov Report

Merging #46 into master will not change coverage.
The diff coverage is 100%.

Impacted file tree graph

@@          Coverage Diff          @@
##           master    #46   +/-   ##
=====================================
  Coverage     100%   100%           
=====================================
  Files           2      2           
  Lines         115    115           
  Branches       32     32           
=====================================
  Hits          115    115
Impacted Files Coverage Δ
src/patch.js 100% <100%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update f63a590...a687cc5. Read the comment docs.

@@ -55,7 +55,7 @@ function setElementProp(element, name, value, oldValue) {
if (name === "key") {
} else if (name === "style") {
for (var name in merge(oldValue, (value = value || {}))) {
element.style[name] = value[name] || ""
element.style[name] = value[name] != null ? value[name] : ""
Copy link
Owner

@jorgebucaran jorgebucaran Nov 10, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@acstll Could we get away with?

element.style[name]+=""

EDIT: What did I just ask? 😆

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With element.style[name]+="" tests fail.

!= null checks against null and undefined, so 0 is valid. Anything else will be already coerced into a string by the browser.

If I'm correct, this change will keep things intact and only allow 0 to be valid and not being swallowed as falsy. Everything else stays the same.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I wasn't thinking well! 😅

@jorgebucaran jorgebucaran added the enhancement New feature or request label Nov 10, 2017
@jorgebucaran jorgebucaran merged commit ef045b0 into jorgebucaran:master Nov 10, 2017
@jorgebucaran
Copy link
Owner

Thanks @acstll! 👍

@acstll
Copy link
Contributor Author

acstll commented Nov 10, 2017

You're welcome!

jorgebucaran pushed a commit that referenced this pull request Jan 6, 2018
* add failing test for passing numbers in styles
* handle numbers correctly in styles
jorgebucaran pushed a commit that referenced this pull request Jan 7, 2018
* add failing test for passing numbers in styles
* handle numbers correctly in styles
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants