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

Highlight arrays #1932

Closed
bitblitter opened this issue Feb 1, 2017 · 3 comments
Closed

Highlight arrays #1932

bitblitter opened this issue Feb 1, 2017 · 3 comments

Comments

@bitblitter
Copy link

Do you want to request a feature or report a bug?
This is a feature request.

Feature: What is your use case for such a feature?
This feature would enable highlighting for arrays of strings.
In my specific case, I wanted to display the values separated by a comma, and highlight the matching terms.

Feature: What is your proposed API entry? The new option to add? What is the behavior?
Enable the Highlight component to be able to display string arrays, with an optional separator.

What project are you opening an issue for?

  • react-instantsearch
  • instantsearch.js

What is the version you are using? Always use the latest one before opening a bug issue.
I'm using the last version on npm: react-instantsearch ^2.2.5

@mthuret
Copy link
Contributor

mthuret commented Feb 2, 2017

Thanks @bitblitter for opening the issue here!

this follow this discussion: https://discourse.algolia.com/t/react-instantsearch-highlight-on-field-with-array-value/469.

@julienpa
Copy link
Contributor

julienpa commented Mar 17, 2017

Really looking forward to this feature too! 😃

With the help of @mikaa123, we came up with this workaround that doesn't need to change the highlighting tags:

  const highlightedAttr = hit._highlightResult.array_attr
    .map(attr => attr.value)
    .map(attr => attr.replace(/<ais-highlight-[0-9]+/, '<em class="ais-Highlight__highlighted"').replace(/<\/ais-highlight-[0-9]+/, '</em'))
    .join(', ')

and then:

<span dangerouslySetInnerHTML={{__html: highlightedAttr}} />

@mthuret
Copy link
Contributor

mthuret commented Apr 11, 2017

React InstantSearch has been moved here: https://github.com/algolia/react-instantsearch
This issue has either been rewritten or placed inside our backlog.

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

No branches or pull requests

3 participants