helior / react-highlighter

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

Issue when search starts or ends with whitespace #29

Closed cookpete closed 5 years ago

cookpete commented 8 years ago

Due to the way React deals with whitespace in span, sometimes results can be a bit janky:

<Highlight search='s '>This is my test</Highlight>

Expected result: This is my test Actual result: Thisismy test

I guess because React is doing:

<span>Thi</span>
<span>s </span>
<span>i</span>
<span>s </span>
<span>my test</span>

and ignores the whitespace inside <span>s </span> because it isn't part of a string.

cookpete commented 8 years ago

You can solve the problem by applying white-space: pre; to the spans, but perhaps that is fine to leave for the developer to deal with.