Gives the parts of a search result that match the keyword the brand text color (brand-text) at weight 500, with no background; single line, truncated when it doesn’t fit.
Status: stable · Components: Highlight
Import
Section titled “Import”import { Highlight } from 'nacre'import { View } from 'nsh'import { Highlight, TEXT_SIZE } from 'nacre'
export function HighlightUsage() { return ( <View class="w-[320px] max-w-full"> <Highlight class={`${TEXT_SIZE.body} text-muted-foreground`} text="Opening an HK stock account requires an ID card and proof of address" keyword="account" /> </View> )}Examples
Section titled “Examples”Following a search field
Section titled “Following a search field”keyword takes the search field’s value directly, so results highlight as you type; with an empty keyword the whole line shows as is.
import { View, signal } from 'nsh'import { Highlight, SearchField, TEXT_SIZE } from 'nacre'
const faq = () => [ 'Opening an HK stock account requires an ID card and proof of address', 'When do funds arrive in a US stock account', 'How long until withdrawn funds reach my bank card', 'How to change the linked phone number',]
export function HighlightSearch() { const keyword = signal('funds') return ( <View class="w-[360px] max-w-full gap-2"> <SearchField value={keyword()} onChange={(v) => keyword.set(v)} placeholder="Search FAQs" /> <View class="gap-1.5"> {faq().map((text) => ( <Highlight class={`${TEXT_SIZE.small} text-muted-foreground`} text={text} keyword={keyword()} /> ))} </View> </View> )}Multiple matches and case
Section titled “Multiple matches and case”Every match in the line is highlighted, case-insensitively, and the original case is kept in what’s shown.
import { View } from 'nsh'import { Highlight, TEXT_SIZE } from 'nacre'
export function HighlightMatches() { return ( <View class="w-[320px] max-w-full gap-2"> <Highlight class={`${TEXT_SIZE.body} text-muted-foreground`} text="VIP customers moved to the vip line get a dedicated agent" keyword="vip" /> <Highlight class={`${TEXT_SIZE.body} text-muted-foreground`} text="Transferring funds in or funds out requires verification first" keyword="funds" /> </View> )}Accessibility
Section titled “Accessibility”- Screen readers read the whole original line; the highlight is visual emphasis only and isn’t read separately.
Do / Don’t
Section titled “Do / Don’t”Do
- Highlight only the keyword the user typed
- Use muted-foreground for the rest so only the matches stand out
Don’t
- Use it to emphasize ordinary copy
- Use it in multi-line body text (Highlight is single-line and truncates)
Highlight
Section titled “Highlight”| Prop | Type | Default | Description |
|---|---|---|---|
text * |
string |
— | |
keyword |
string |
— | |
class |
string |
— | |
testID |
string |
— |
* required