-
Notifications
You must be signed in to change notification settings - Fork 47.3k
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
Correctly trim strings for css properties #1642
Conversation
|
Kind of related: #1357 |
Yeah I guess, but it's a pretty small amount of code to cater for both string and camelcase. Either way I can back it out if not. |
@ryanseddon Ah my bad, I saw Personally, I think it makes sense not to support hyphenated names as it would introduce ambiguity (if both are present) and unnecessarily complicates/breaks potential custom logic for modifying styles (like components could). |
This PR covers the other issue of trimming strings so unitless values don't end up I honestly think this should cover handling camelCasing of string keys. Do you want me to revert the camelCase changes and is the trimming code ok? |
cc @zpao |
(I'd personally prefer that we go the other way and not add |
re: hyphenated styles re: trimming |
var isNonNumeric = isNaN(value); | ||
if (isNonNumeric || value === 0 || | ||
isUnitlessNumber.hasOwnProperty(name) && isUnitlessNumber[name]) { | ||
return '' + value; // cast to string | ||
} | ||
|
||
if(typeof value === 'string'){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please match existing style. if (...) {
* If a unitless value is passed with a space it'll return `1 px`
I've backed out the camelCase code and fixed the if statement to match code style. |
@zpao Regarding the PS. I believe the newer C++ TRs uses this syntax too, including parenthesis (although with possibility for mathematical operations), so that's something at least. |
@syranide I'm not sure what value that would give over just writing the strings verbatim? |
@spicyj Shorter and significantly less ugly, but yeah, it would just be sugar. |
sugar for things that are already simple is usually overkill IMO. And at that point you're in what we think is JS already, so it's a bit awkward. |
Correctly trim strings for css properties
Thanks! |
This PR correctly trims property strings if passed in with a space. It also correctly matches unit less properties if the name is passed in as a 'string' and not camelCase by converting the string to camelCase.
1 px
If passed 'z-index': 1 it'll return 'z-index': '1px' convert str camelCase when doin unitless lookupSee test case
Not applicable anymore see #1662
The following component yields inline styles:z-index:1px;margin:10 px;