should numbers automatically be num+'px'?
I've found that when using number values in hyperscript it's normally a pixel value. would it make sense to just interpret a number as a pixel value?
@juliangruber @Raynos @pfraze @airportyh @mmckegg @reqshark ?
I think that's a good idea. FWIW it's also what React does with the style object
There are a few cases when you do actually want to set a number without a unit prefix (e.g flex and lineHeight style properties)
I suppose the trick would be only to prefix "px" when typeof value === 'number', then the user would specify the value as a String if they wanted it to be literal.
Possibly this should be scoped just to style? All other places I can think of don't actually require 'px' - for example the width and height attributes of images can be specified as straight numbers with no unit and it is interpreted as px.
+1 if it's just for style props
Another case where px isn't expected is z-index.
+1 good call. Looks like couple edge case styles were mentioned, also let's include opacity on that list
yeah, I was thinking this would just be for style.
which is easier to list, the cases where you want px or don't want it?
hmm, all the px cases are things light width, height, top, left, right, bottom, margin, border (and subcases -left -right -top -bottom, min- max-)
and currently for non-px we have zIndex and opacity.
But of course, there may be other non-px numbers we have missed and so a positive list is safer than a negative list.
yea to be safe, we'll need to make that list positive
I mean, right now I just stumbled across another style (a flexbox thing) that takes a number: order
In the end, I just added this function px(d) { return +d+'px' } and there after used px(num) and that is nice enough.
@ashaffer created a module listing a lot of the properties which are unitless. Maybe you guys can take the list out of there or include the module if @dominictarr is still interested in this.
- https://github.com/micro-js/css-default-units
- https://github.com/micro-js/css-unitless
thanks @queckezz given the size of that list I'd say it's unappropiate to set +'px' by default.
I agree, often one may want to use em or increasingly device size units.