bvaughn / react-highlight-words

React component to highlight words within a larger body of text
https://bvaughn.github.io/react-highlight-words/
MIT License
2.18k stars 171 forks source link

Unable to add props to wrapper span #69

Closed ioloie closed 5 years ago

ioloie commented 5 years ago

Is there an existing way to add standard DOM attributes to the span wrapper such as title or data-*? It could be as simple as spreading any remaining props to the child so we could do the following:

        <Highlighter
          className="gameName"
          highlightClassName="highlightName"
          searchWords={searchValue}
          textToHighlight={content.gameName}
          title="Play Game"
          data-ext="test"
        />
bvaughn commented 5 years ago

No, there's no way currently to do that.

I'm a little reluctant to spread remaining props that way, but...maybe that would be the least awkward approach for this use case.

If you'd be willing to put together a PR (including tests and documentation updates) I'll review it.

ioloie commented 5 years ago

Would it be better to spread remaining props as above or to add a dedicated prop object:


const spanProps={
  title: 'Play Game',
  'data-ext': 'test'
}

return (<Highlighter
  className="gameName"
  highlightClassName="highlightName"
  searchWords={searchValue}
  textToHighlight={content.gameName}
  spanProps={spanProps}
/>)
bvaughn commented 5 years ago

I'm not thrilled with either approach, but I think I like the first approach better than the wrapper object.

bvaughn commented 5 years ago

Published as 0.16.0

Thanks for contributing!