Skip to content

Instantly share code, notes, and snippets.

Tabs:
[
{
"caption": "Tab Title",
"fields": [
{
"field": "title",
"caption": "Name"
},
{
@broslav
broslav / .js
Created September 14, 2018 13:44
Function to highlight user input inside autosuggest component
highlightWords = (string, highlight) => {
let counter = 0;
let str = string;
let index = string.toLowerCase().indexOf(highlight.toLowerCase());
let result = [];
while(index > -1) {
result.push(<span key={counter++}>{str.slice(0, index)}</span>);
result.push(<mark key={counter++}>{str.slice(index, index + highlight.length)}</mark>);
str = str.slice(index + highlight.length);