@@ -29,7 +29,7 @@ export default class Text extends PureBaseComponent {
29
29
*/
30
30
uppercase : PropTypes . bool ,
31
31
/**
32
- * Substring to highlight (would work when children is a string)
32
+ * Substring to highlight
33
33
*/
34
34
highlightString : PropTypes . string ,
35
35
/**
@@ -74,18 +74,28 @@ export default class Text extends PureBaseComponent {
74
74
return textParts ;
75
75
}
76
76
77
- renderText ( ) {
78
- const { children, highlightString, highlightStyle} = this . props ;
79
- if ( _ . isString ( children ) && ! _ . isEmpty ( highlightString ) ) {
80
- const textParts = this . getTextPartsByHighlight ( children , highlightString ) ;
81
- return _ . map ( textParts , ( text , index ) => {
82
- const shouldHighlight = _ . lowerCase ( text ) === _ . lowerCase ( highlightString ) ;
83
- return (
84
- < Text key = { index } style = { shouldHighlight && [ this . styles . highlight , highlightStyle ] } >
85
- { text }
86
- </ Text >
87
- ) ;
88
- } ) ;
77
+ renderText ( children = this . props . children ) {
78
+ const { highlightString, highlightStyle} = this . props ;
79
+
80
+ if ( ! _ . isEmpty ( highlightString ) ) {
81
+
82
+ if ( _ . isArray ( children ) ) {
83
+ return _ . map ( children , child => {
84
+ return this . renderText ( child ) ;
85
+ } ) ;
86
+ }
87
+
88
+ if ( _ . isString ( children ) ) {
89
+ const textParts = this . getTextPartsByHighlight ( children , highlightString ) ;
90
+ return _ . map ( textParts , ( text , index ) => {
91
+ const shouldHighlight = _ . lowerCase ( text ) === _ . lowerCase ( highlightString ) ;
92
+ return (
93
+ < Text key = { index } style = { shouldHighlight && [ this . styles . highlight , highlightStyle ] } >
94
+ { text }
95
+ </ Text >
96
+ ) ;
97
+ } ) ;
98
+ }
89
99
}
90
100
return children ;
91
101
}
0 commit comments