Skip to main content

<Highlight> props

import { Highlight } from 'one-more-highlight';

Required props

PropTypeDescription
textstringThe text to search and render.
searchWordsArray<string | RegExp>Terms to find. String terms are auto-escaped by default. RegExps are cloned with g flag forced on.

Matching options

PropTypeDefaultDescription
caseSensitivebooleanfalseMatch case (string terms only; regex flags are honored as-is).
autoEscapebooleantrueEscape regex special chars in string terms.
sanitize(s: string) => stringPre-process text and search source before matching. Use for diacritic-insensitive search.
findChunks(input: FindChunksInput) => RawChunk[]Custom matcher; completely replaces the default matchAll-based implementation.
overlapStrategy'merge' | 'nest' | 'first-wins''merge'How overlapping matches are resolved.

State options

PropTypeDefaultDescription
statesHighlightState[]Per-match layered styling. Each entry selects a subset of matches and applies a className and/or style on top of the base.

Rendering options

PropTypeDefaultDescription
highlightTagkeyof JSX.IntrinsicElements | ComponentType'mark'Element or component for matches. Custom components receive matchIndex and states as extra props.
highlightClassNamestringBase className applied to every match.
highlightStyleCSSPropertiesBase inline style applied to every match.
unhighlightTagkeyof JSX.IntrinsicElementsElement to wrap non-match segments (default: no wrapper).
unhighlightClassNamestringclassName for non-match wrappers (only applied when unhighlightTag is set).
unhighlightStyleCSSPropertiesInline style for non-match wrappers.
renderMatch(seg: MatchSegment, defaults: MatchDefaults) => ReactNodeFull render-prop control over match output.

Root element options

PropTypeDefaultDescription
askeyof JSX.IntrinsicElements'span'Root wrapper element.
classNamestringclassName on the root wrapper.
styleCSSPropertiesInline style on the root wrapper.

Additional HTML attributes are forwarded to the root element.

<Highlight> is wrapped with forwardRef — you can pass a ref and it will be attached to the root element (the as element, default <span>).