1.0.0
This release upgrades to highlight-words-core 2.0.
- React 16.3 or newer is required (for
forwardRef); React 0.14, 15, and 16.0–16.2 are no longer supported. - String search words are matched literally by default (
autoEscapenow defaults totrue), so characters like(,., and$match themselves. To match patterns, passRegExpsearch words, or setautoEscape={false}for trusted input only. - Custom
findChunksfunctions must include asearchIndex(the index withinsearchWordsof the search word that matched) in each chunk they return, and the exportedChunktype now requires it. They also receive every option with its default applied, and receivesearchWordsas aReadonlyArray(so TypeScript functions that declare it as a mutable array, e.g.string[], must update their parameter type). - The package now defines
exports, so only the package root (react-highlight-words) can be imported; deep imports (e.g.react-highlight-words/dist/react-highlight-words.js) are no longer available. highlight-words-core2.0 is published as ES2020 (e.g.??), so environments and bundlers that can't parse that syntax (e.g. webpack 4) need to transpile it.- When
autoEscapeisfalse, string search words that aren't valid regular expressions (e.g."(a") are matched literally instead of throwing an error. - When a
sanitizefunction changes the text, it is applied to each character separately (so that matches can be mapped back to the original text). Sanitizers that depend on context will give different results.
searchWordscan includeRegExpobjects, which are used as-is (with their own flags).searchWordscan be a readonly array (e.g.["a", "b"] as const).- Custom
highlightTagcomponents receive asearchIndexprop: the index (withinsearchWords) of the search word that matched. - A
refis forwarded to the outer/wrapper<span>(this requires React 16.3 or newer). - The
FoundChunktype is exported (as an alias ofChunk, matching its name inhighlight-words-core).
- Matches line up with the original text when the
sanitizefunction changes its length (e.g.latinize("Æ")is"AE"). - Surrogate pairs (e.g. emoji) are no longer split between highlighted and unhighlighted text.
- A missing or non-string
textToHighlight(from untyped callers) no longer throws an error. - When
highlightClassNameis an object, matches whose text isn't one of its keys (e.g. becausesanitizechanged it, or overlapping matches were combined) use the class of the search word that matched, and no longer get an"undefined"class name. - Inactive matches no longer have a trailing space in their class name, and matches and unhighlighted text with no class name no longer render an empty
class=""attribute. - TypeScript declarations are correct for CommonJS consumers:
require("react-highlight-words")(orimport Highlighter = require(...)) is typed as the component itself, and the types are available as e.g.Highlighter.HighlighterProps. Previously, projects using"moduleResolution": "node16"couldn't import the package from CommonJS files. - When
highlightClassNameis an object, matches like"constructor"or"toString"no longer get a class name from properties every object inherits.
0.21.1
The component's behavior is unchanged, but the package is now built with Vite instead of webpack. Check the packaging changes below if you use an older bundler or runtime, or load the UMD build.
- Add TypeScript type definitions (
dist/react-highlight-words.d.ts), including exportedHighlighterProps,HighlightTagProps,UnhighlightTagProps,ChunkandFindChunksOptionstypes. - Add an ES module build (
dist/react-highlight-words.js), exposed through themodulefield. - Move the CommonJS entry point from
dist/main.jstodist/react-highlight-words.cjs.require("react-highlight-words")still returns the component directly. - Target modern JavaScript (ES2018+: object spread, destructuring defaults,
const/let) instead of ES5. Environments that can't parse that syntax need to transpile the package. - Stop bundling
highlight-words-coreinto the build; it is installed as a regular dependency (^1.2.0). - Lowercase the keys of an object
highlightClassNameonce per render instead of once per match (whencaseSensitiveisfalse). - Remove the UMD build (
dist/main.umd.js). - Remove the
memoize-onedependency.
v0.21.0
- deps: React 19 support by @sergei-startsev in https://github.com/bvaughn/react-highlight-words/pull/123
- fix: set autoEscape to true on demo website by @dorobila in https://github.com/bvaughn/react-highlight-words/pull/102
- fix typo in tests by @RyanChadly in https://github.com/bvaughn/react-highlight-words/pull/111
- @RyanChadly made their first contribution in https://github.com/bvaughn/react-highlight-words/pull/111
- @dorobila made their first contribution in https://github.com/bvaughn/react-highlight-words/pull/102
Full Changelog: https://github.com/bvaughn/react-highlight-words/compare/v0.20.0...v0.21.0
v0.18.0
- feat: provide basic support of React 18 by @sergei-startsev in https://github.com/bvaughn/react-highlight-words/pull/100