# Search Match

Marks the part of a result that matches the search, on a light navy tint, keeping the text's own size and colour.

- Beta: ready to use; its API can still change in a minor release.
- Category: Text

```tsx
import { HighlightMatch, SearchMatch } from "@leap-crm/design-system";
```

## Best practices

- Do: Use `HighlightMatch` with the result's `text` and the searched `query` in search results and pickers, like Ada in Ada Hartley. It marks every case-insensitive match.
- Do: Use `SearchMatch` by hand when you already know which part matched, like a range the server returns.
- Don't: Use it to emphasise words in text nobody searched, like a key phrase in a note. The tint means the text matched a search.
- Don't: Use it to point at an item someone was taken to from a notification or a link. Use `Highlight`.

## Related

- [Highlight](./highlight.md)
- [Truncate](./truncate.md)
- [Combobox](./combobox.md)

## Examples

What the examples import:

```tsx
import { useState } from "react";
import { HighlightMatch, SearchMatch } from "@leap-crm/design-system";
```

Scaffolding the examples call. It lives in the docs page, not in the library:

```tsx
const people = [
  "Ada Hartley",
  "Adam Nguyen",
  "Jane Citizen",
  "Kanada Pty Ltd",
] as const;

function Searching() {
  const [query, setQuery] = useState("ada");
  return (
    <div className="flex w-72 flex-col gap-2">
      <label className="text-small text-neutral-text-muted flex flex-col gap-1">
        Search
        <input
          value={query}
          onChange={event => setQuery(event.target.value)}
          className="border-neutral-border text-neutral-text focus-visible:border-focus-border focus-visible:shadow-focus h-9 rounded-md border px-3 text-base outline-none"
        />
      </label>
      <ul className="m-0 flex list-none flex-col gap-1 p-0 text-base">
        {people.map(person => (
          <li key={person}>
            <HighlightMatch text={person} query={query} />
          </li>
        ))}
      </ul>
    </div>
  );
}
```

### HighlightMatch

Type to search; every case-insensitive match is marked.

```tsx
<Searching />
```

### By hand

```tsx
<p className="m-0 text-base">
  <SearchMatch>Ada</SearchMatch> Hartley
</p>
```

## Props

SearchMatch takes every prop of a <mark>.

### HighlightMatch

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `text` (required) | `string` |  | The text to show, like a contact's name. |
| `query` (required) | `string` |  | What was searched for. Every case-insensitive match is marked. |
| `className` | `string` |  | Classes added to the root element, merged with its own. Tokens only. |

### SearchMatch

No props of its own.
