Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion lib/highlighter.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ var Highlighter = createReactClass({
/**
* Determines which strings of text should be highlighted or not.
*
* @param {string} subject
* @param {string | number} subject
* The body of text that will be searched for highlighted words.
* @param {string} search
* The search used to search for highlighted words.
Expand All @@ -162,6 +162,17 @@ var Highlighter = createReactClass({
var children = [];
var remaining = subject;

// If remaining is Number
if (typeof remaining === 'number') {
// Make string from Number
remaining = String(remaining);
}

// if remaining is still not a String throw Error
if (typeof remaining !== 'string') {
throw new Error('Children must be a String');
}

while (remaining) {
var remainingCleaned = (this.props.ignoreDiacritics
? removeDiacritics(remaining, this.props.diacriticsBlacklist)
Expand Down
7 changes: 7 additions & 0 deletions test/testHighlighter.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,14 @@ describe('Highlight element', function() {
expect(ReactDOM.findDOMNode(node).children.length).to.equal(3);
expect(matches).to.have.length(1);
});
it('should accept numbers as children', function() {
var element = React.createElement(Highlight, {search: '42'}, 1942);
var node = TestUtils.renderIntoDocument(element);
var matches = TestUtils.scryRenderedDOMComponentsWithClass(node, 'highlight');

expect(ReactDOM.findDOMNode(node).children.length).to.equal(2);
expect(matches).to.have.length(1);
});
it('should allow empty search', function() {
var element = React.createElement(Highlight, {search: ''}, 'The quick brown fox jumped over the lazy dog.');
var node = TestUtils.renderIntoDocument(element);
Expand Down