@@ -14,7 +14,7 @@ import { Dynamic } from "@reflect-ui/core/lib/_utility-types";
1414 * You can select wich element to render with `elementPreference`. - choose between h1 ~ h6, p, span, etc.
1515 */
1616export class Text extends TextChildWidget {
17- _type : "Text" ;
17+ _type : "Text" = "Text" ;
1818
1919 // text properties
2020 data : Dynamic < string > ;
@@ -74,15 +74,27 @@ export class Text extends TextChildWidget {
7474 "text-decoration" : css . textDecoration ( this . textStyle . decoration ) ,
7575 "text-shadow" : css . textShadow ( this . textStyle . textShadow ) ,
7676 // ------------------------------------------
77- "min-height" : css . px ( this . height ) ,
78- // TODO: do not specify width when parent is a flex container.
79- // Also flex: 1 is required to make the text wrap.
80- width : css . px ( this . width ) ,
77+ ...textWH ( { width : this . width , height : this . height } ) ,
8178 } ;
8279
8380 return < CSSProperties > textStyle ;
8481 }
8582
83+ get finalStyle ( ) {
84+ const superFinalStyle = super . finalStyle ;
85+ // TODO: this is a dirty fix ------------------------------------------------
86+ // the text's width should not be overriden by the constraint's preference.
87+ if ( this . width === undefined ) {
88+ delete superFinalStyle [ "width" ] ;
89+ }
90+ if ( this . height === undefined ) {
91+ delete superFinalStyle [ "height" ] ;
92+ }
93+ // --------------------------------------------------------------------------
94+
95+ return { ...superFinalStyle } ;
96+ }
97+
8698 jsxConfig ( ) : StylableJSXElementConfig {
8799 return < StylableJSXElementConfig > {
88100 type : "tag-and-attr" ,
@@ -99,3 +111,12 @@ const __get_dedicated_element_tag = (t?: WebTextElement | undefined) => {
99111 return __default_element_tag ;
100112 }
101113} ;
114+
115+ function textWH ( { width, height } : { width : number ; height : number } ) {
116+ return {
117+ // TODO: do not specify width when parent is a flex container.
118+ // Also flex: 1 is required to make the text wrap.
119+ width : css . px ( width ) ,
120+ "min-height" : css . px ( height ) ,
121+ } ;
122+ }
0 commit comments