I am trying to make one custom autocomplete , I am able to do that but I am not able to highlight the matching text
here is my code https://codesandbox.io/s/affectionate-colden-7embr?file=/src/index.js
see when I type john
john
is highlight in blue color
matchItems = (items, regexp) => {
let match = false;
items.forEach(item => {
if (item.search(regexp) > -1) {
match = true;
}
});
return match;
};
filterUsers = (users, regexp) => {
const filteredUsers = users.filter(
user =>
user.name.search(regexp) > -1 ||
user.id.search(regexp) > -1 ||
this.matchItems(user.items, regexp) ||
user.address.search(regexp) > -1 ||
user.pincode.search(regexp) > -1
);
return filteredUsers;
};
filterByKeyword = e => {
const keyword = e.target.value;
this.setState({ currentInput: keyword });
if (keyword) {
const regexp = new RegExp(`${keyword}`, 'i');
this.setState({ users: this.filterUsers(users, regexp) });
} else {
this.setState({ users });
}
};
so my code filter works correctly but I am not able to hightlist the text