Skip to content

Commit 917a8df

Browse files
committed
Text highlightString feature will work when passing also array of children
1 parent 3e655b1 commit 917a8df

File tree

1 file changed

+23
-13
lines changed

1 file changed

+23
-13
lines changed

src/components/text/index.js

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export default class Text extends PureBaseComponent {
2929
*/
3030
uppercase: PropTypes.bool,
3131
/**
32-
* Substring to highlight (would work when children is a string)
32+
* Substring to highlight
3333
*/
3434
highlightString: PropTypes.string,
3535
/**
@@ -74,18 +74,28 @@ export default class Text extends PureBaseComponent {
7474
return textParts;
7575
}
7676

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+
}
8999
}
90100
return children;
91101
}

0 commit comments

Comments
 (0)