@@ -597,4 +597,209 @@ describe('compat render', () => {
597597
598598 expect ( scratch . textContent ) . to . equal ( 'foo' ) ;
599599 } ) ;
600+
601+ it ( 'should append "px" to unitless inline css values' , ( ) => {
602+ // These are all CSS Properties that support a single <length> value
603+ // that must have a unit. If we encounter a number we append "px" to it.
604+ // The list is taken from: https://developer.mozilla.org/en-US/docs/Web/CSS/Reference
605+ const unitless = {
606+ 'border-block' : 2 ,
607+ 'border-block-end-width' : 3 ,
608+ 'border-block-start-width' : 4 ,
609+ 'border-block-width' : 5 ,
610+ 'border-bottom-left-radius' : 6 ,
611+ 'border-bottom-right-radius' : 7 ,
612+ 'border-bottom-width' : 8 ,
613+ 'border-end-end-radius' : 9 ,
614+ 'border-end-start-radius' : 10 ,
615+ 'border-image-outset' : 11 ,
616+ 'border-image-width' : 12 ,
617+ 'border-inline' : 2 ,
618+ 'border-inline-end' : 3 ,
619+ 'border-inline-end-width' : 4 ,
620+ 'border-inline-start' : 1 ,
621+ 'border-inline-start-width' : 123 ,
622+ 'border-inline-width' : 123 ,
623+ 'border-left' : 123 ,
624+ 'border-left-width' : 123 ,
625+ 'border-radius' : 123 ,
626+ 'border-right' : 123 ,
627+ 'border-right-width' : 123 ,
628+ 'border-spacing' : 123 ,
629+ 'border-start-end-radius' : 123 ,
630+ 'border-start-start-radius' : 123 ,
631+ 'border-top' : 123 ,
632+ 'border-top-left-radius' : 123 ,
633+ 'border-top-right-radius' : 123 ,
634+ 'border-top-width' : 123 ,
635+ 'border-width' : 123 ,
636+ bottom : 123 ,
637+ 'column-gap' : 123 ,
638+ 'column-rule-width' : 23 ,
639+ 'column-width' : 23 ,
640+ 'flex-basis' : 23 ,
641+ 'font-size' : 123 ,
642+ 'grid-gap' : 23 ,
643+ 'grid-auto-columns' : 123 ,
644+ 'grid-auto-rows' : 123 ,
645+ 'grid-template-columns' : 23 ,
646+ 'grid-template-rows' : 23 ,
647+ height : 123 ,
648+ 'inline-size' : 23 ,
649+ inset : 23 ,
650+ 'inset-block-end' : 12 ,
651+ 'inset-block-start' : 12 ,
652+ 'inset-inline-end' : 213 ,
653+ 'inset-inline-start' : 213 ,
654+ left : 213 ,
655+ 'letter-spacing' : 213 ,
656+ margin : 213 ,
657+ 'margin-block' : 213 ,
658+ 'margin-block-end' : 213 ,
659+ 'margin-block-start' : 213 ,
660+ 'margin-bottom' : 213 ,
661+ 'margin-inline' : 213 ,
662+ 'margin-inline-end' : 213 ,
663+ 'margin-inline-start' : 213 ,
664+ 'margin-left' : 213 ,
665+ 'margin-right' : 213 ,
666+ 'margin-top' : 213 ,
667+ 'mask-position' : 23 ,
668+ 'mask-size' : 23 ,
669+ 'max-block-size' : 23 ,
670+ 'max-height' : 23 ,
671+ 'max-inline-size' : 23 ,
672+ 'max-width' : 23 ,
673+ 'min-block-size' : 23 ,
674+ 'min-height' : 23 ,
675+ 'min-inline-size' : 23 ,
676+ 'min-width' : 23 ,
677+ 'object-position' : 23 ,
678+ 'outline-offset' : 23 ,
679+ 'outline-width' : 123 ,
680+ padding : 123 ,
681+ 'padding-block' : 123 ,
682+ 'padding-block-end' : 123 ,
683+ 'padding-block-start' : 123 ,
684+ 'padding-bottom' : 123 ,
685+ 'padding-inline' : 123 ,
686+ 'padding-inline-end' : 123 ,
687+ 'padding-inline-start' : 123 ,
688+ 'padding-left' : 123 ,
689+ 'padding-right' : 123 ,
690+ 'padding-top' : 123 ,
691+ perspective : 123 ,
692+ right : 123 ,
693+ 'scroll-margin' : 123 ,
694+ 'scroll-margin-block' : 123 ,
695+ 'scroll-margin-block-start' : 123 ,
696+ 'scroll-margin-bottom' : 123 ,
697+ 'scroll-margin-inline' : 123 ,
698+ 'scroll-margin-inline-end' : 123 ,
699+ 'scroll-margin-inline-start' : 123 ,
700+ 'scroll-margin-inline-left' : 123 ,
701+ 'scroll-margin-inline-right' : 123 ,
702+ 'scroll-margin-inline-top' : 123 ,
703+ 'scroll-padding' : 123 ,
704+ 'scroll-padding-block' : 123 ,
705+ 'scroll-padding-block-end' : 123 ,
706+ 'scroll-padding-block-start' : 123 ,
707+ 'scroll-padding-bottom' : 123 ,
708+ 'scroll-padding-inline' : 123 ,
709+ 'scroll-padding-inline-end' : 123 ,
710+ 'scroll-padding-inline-start' : 123 ,
711+ 'scroll-padding-left' : 123 ,
712+ 'scroll-padding-right' : 123 ,
713+ 'scroll-padding-top' : 123 ,
714+ 'shape-margin' : 123 ,
715+ 'text-decoration-thickness' : 123 ,
716+ 'text-indent' : 123 ,
717+ 'text-underline-offset' : 123 ,
718+ top : 123 ,
719+ 'transform-origin' : 123 ,
720+ translate : 123 ,
721+ width : 123 ,
722+ 'word-spacing' : 123
723+ } ;
724+
725+ // These are all CSS properties that have valid numeric values.
726+ // Our appending logic must not be applied here
727+ const untouched = {
728+ '-webkit-line-clamp' : 2 ,
729+ 'animation-iteration-count' : 3 ,
730+ 'column-count' : 2 ,
731+ // TODO: unsupported atm
732+ // columns: 2,
733+ flex : 1 ,
734+ 'flex-grow' : 1 ,
735+ 'flex-shrink' : 1 ,
736+ 'font-size-adjust' : 123 ,
737+ 'font-weight' : 12 ,
738+ 'grid-column' : 2 ,
739+ 'grid-column-end' : 2 ,
740+ 'grid-column-start' : 2 ,
741+ 'grid-row' : 2 ,
742+ 'grid-row-end' : 2 ,
743+ 'grid-row-start' : 2 ,
744+ // TODO: unsupported atm
745+ //'line-height': 2,
746+ 'mask-border-outset' : 2 ,
747+ 'mask-border-slice' : 2 ,
748+ 'mask-border-width' : 2 ,
749+ 'max-zoom' : 2 ,
750+ 'min-zoom' : 2 ,
751+ opacity : 123 ,
752+ order : 123 ,
753+ orphans : 2 ,
754+ 'grid-row-gap' : 23 ,
755+ scale : 23 ,
756+ // TODO: unsupported atm
757+ //'tab-size': 23,
758+ widows : 123 ,
759+ 'z-index' : 123 ,
760+ zoom : 123
761+ } ;
762+
763+ render (
764+ < div
765+ style = { {
766+ ...unitless ,
767+ ...untouched
768+ } }
769+ /> ,
770+ scratch
771+ ) ;
772+
773+ let style = scratch . firstChild . style ;
774+
775+ // Check properties that MUST not be changed
776+ for ( const key in unitless ) {
777+ // Check if css property is supported
778+ if (
779+ window . CSS &&
780+ typeof window . CSS . supports === 'function' &&
781+ window . CSS . supports ( key , unitless [ key ] )
782+ ) {
783+ expect (
784+ String ( style [ key ] ) . endsWith ( 'px' ) ,
785+ `Should append px "${ key } : ${ unitless [ key ] } " === "${ key } : ${ style [ key ] } "`
786+ ) . to . equal ( true ) ;
787+ }
788+ }
789+
790+ // Check properties that MUST not be changed
791+ for ( const key in untouched ) {
792+ // Check if css property is supported
793+ if (
794+ window . CSS &&
795+ typeof window . CSS . supports === 'function' &&
796+ window . CSS . supports ( key , untouched [ key ] )
797+ ) {
798+ expect (
799+ ! String ( style [ key ] ) . endsWith ( 'px' ) ,
800+ `Should be left as is: "${ key } : ${ untouched [ key ] } " === "${ key } : ${ style [ key ] } "`
801+ ) . to . equal ( true ) ;
802+ }
803+ }
804+ } ) ;
600805} ) ;
0 commit comments