helior / react-highlighter

:high_brightness: Highlight text using React
MIT License
157 stars 42 forks source link

Highlighter Crashes on Numeric Values #65

Open epligrow opened 3 years ago

epligrow commented 3 years ago

Summary

Wrapping a numeric value in a Highlight component utilizing the search property has the potential to cause a TypeError.

image

Expected Behavior

The Highlighter should show the matching string within the return results. Here is an example of this working as expected with the search term of "test".

image

How to Replicate

Using the first image as an example, if the value of cell is numeric (ex. 1234 instead of "1234"), and the value of query is a partial match (ex. 123), the component breaks, citing the following:

image

Workaround

A workaround for this issue is to either call the toString() method or wrap the value in a String constructor.