Search based on beginning of words
Instead of the search results simply looking to see if a word contains the term searched for, this makes it so the term has to match the beginning of one of the words. For example, let's say the options were: - First name - Confirmation time Previously, a search for "n" would return both, because there is an n in the word Confirmation. With this change, only First name would match because the word name starts with n. See the Jira ticket for discussion. [MAILPOET-3958]
This commit is contained in:
committed by
Veljko V
parent
b682eb6239
commit
f193957096
@@ -25,7 +25,8 @@ export default () => {
|
||||
// `name` is the label displayed to users
|
||||
const matchedChildren = data.children.filter((child) => {
|
||||
const label = child.name.toLowerCase();
|
||||
return label.includes(searchTerm);
|
||||
const words = label.split(' ');
|
||||
return words.some((word) => word.startsWith(searchTerm));
|
||||
});
|
||||
if (matchedChildren.length === 0) {
|
||||
// Returning null prevent the entire optgroup from being displayed
|
||||
|
Reference in New Issue
Block a user