Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(recent-searches): add search highlighting #370

Merged
merged 4 commits into from
Nov 12, 2020

Conversation

francoischalifour
Copy link
Member

This adds support for search highlighting in the Recent Searches.

Preview

image

image

@codesandbox-ci
Copy link

codesandbox-ci bot commented Nov 12, 2020

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit 5d8cff4:

Sandbox Source
@algolia/js-example Configuration

@francoischalifour francoischalifour merged commit 3cb1d39 into next Nov 12, 2020
@francoischalifour francoischalifour deleted the feat/recent-searches-highlighting branch November 12, 2020 14:55
}

return items
.filter((item) => item.query.toLowerCase().startsWith(query.toLowerCase()))
.slice(0, limit);
.filter((item) => item.query.toLowerCase().includes(query.toLowerCase()))
Copy link
Contributor

@Haroenv Haroenv Nov 16, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you use indexOf here (instead of includes), you already have the start index of the highlight & the end index will be that + the length of the query. You'd need to store this info temporarily on the object and remove that in highlight though

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants