Ballmac UI home

Match Highlight

Text with the words of a search marked, as search results show them: real mark elements in a theme tint that stays readable in light and dark, plus helpers that split a query and test whether text matches it.

Verify webhook signatures

Every webhook request is signed. Check the signature header against your signing secret before you trust the payload.

Installation

$ pnpm dlx shadcn@latest add @ballmac/match-highlight

Usage

import { MatchHighlight, queryTokens, matchesAll, countMatches } from "@/components/ballmac/match-highlight"

The full example is in the Code tab above.

Examples

Type to search

  • Download invoices and receipts
  • Invite teammates and set their role
  • Turn on two-step sign-in

API reference

PropTypeDefault
text*

The text to show.

string—
query

What was searched for: a string (split into words) or a list of words. Every occurrence of any word is marked.

string | string[]""

Also accepts the standard attributes of its root element.

Accessibility

KeyAction
NoneUses <mark>, which assistive technology can announce; the tint is chosen so the text keeps its contrast.

Quality scorecard

6/6

Every applicable check passes

Measured in Chromium 153.0.8010.12 on October 19, 2026, on version 1.0.0, across 2 examples.

How we measure
  • Passed: Accessibility scan

    No serious or critical issues in light and dark, on a phone and a desktop (axe-core 4.13.0, WCAG 2.1 AA and best-practice rules).

  • Passed: Small screens

    No sideways scrolling at 360, 390 or 1280 px wide.

  • Passed: Reduced motion

    No endless animation to begin with.

  • Not applicable: Right to left

    Not mirrored by design: The marks sit inside running text, whose word order follows the language of the text, so a mirror image of English prose cannot apply. It marks Arabic and Hebrew text correctly (tested).

  • Passed: Clean console

    No console errors or React hydration errors while loading.

  • Passed: Keyboard

    1 tab stop, each showing a visible change when it takes focus. 1 documented key.

  • Not applicable: Loading, empty and error

    A display of text: nothing to load, submit or fail.

  • Passed: Automated tests

    Covered by match-highlight.test.tsx.

  • For information: Footprint

    1.0 KB of source (gzip) in 1 file. No extra npm packages.

Automated checks find a subset of problems and do not replace testing with a screen reader and a keyboard in your own app. What they miss.

Use with AI

<MatchHighlight text={result.title} query={query} /> marks every occurrence of every word of the query, ignoring case. queryTokens(query) gives the words, matchesAll(text, query) tests that all of them occur, countMatches(text, query) counts occurrences for ranking. No "use client": it works in server components. With the shadcn MCP server set up (guide), ask your agent:

Add the Ballmac UI Match Highlight (@ballmac/match-highlight) to this project with the shadcn MCP, then use it where it fits.

Use it for

  • Search results, suggestions and autocomplete rows
  • Showing why an item matched a filter

Not for

  • Syntax highlighting of code (use code-block)
  • A hand-drawn emphasis mark on a phrase (use highlighter)

Registry JSON: https://ui.ballmac.com/r/match-highlight.json

Credits

Free to use in personal and commercial projects.

npm
None
Registry
shadcn/utils

Ballmac UI Pro

Need the whole screen, not one piece?

150 premium blocks (dashboards, settings, calendars, mail, shops, onboarding), a private shadcn registry and Figma tokens. Blocks that show data come with loading, empty and error states built in.

Not ready? Try three Pro blocks free

Leave your email and the blocks appear right here, ready to copy. Yours to use in any project.