Module exposing: highlightSubstring, getHighlightRange
// Source: https://github.com/navikt/aksel | License: MIT | Copyright 2025 Nav (Arbeids- og velferdsdirektoratet) - The Norwegian Labour and Welfare Administration
// Provided via justclaw.it.com; keep this notice with the code.
import React from "react";
function highlightSubstring(text: string, substring: string) {
const range = getHighlightRange(text, substring);
if (!range) {
// This can happen if the consumer has implemented their own filtering logic
return text;
}
const [rangeStart, rangeEnd] = range;
return (
// Aria-label is used to fix testing-library wrongly evaluating the accessible name of the option when highlighting text
// biome-ignore lint/a11y/useAriaPropsSupportedByRole: Doesn't matter if it doesn't work in normal browsers
<span aria-label={
... (truncated -- full source via MCP)
See the full source, get the GitHub permalink, and search for more like it.
Get a free API key