Highlight
Shows a string with every match of a search query marked, for search results and filtered lists.
<arc-highlight>Overview
Highlight shows the string in text and wraps every occurrence of query in a <mark>. The query is matched as one literal string: regex characters such as ., ( and * are escaped, and it isn't split into words. Matching ignores case unless you set case-sensitive, which suits code search.
Marks have the --accent-primary-subtle background, accent-colored text and slightly rounded corners, and keep the surrounding font style and weight. With no query or no match, the text renders plain.
Use it in search results and filtered lists, next to Search or CommandPalette, to show why each item matched.
Guidelines
Do
- Update `query` as the user types for live highlighting
Don't
- Don't use it for static emphasis. Use `<strong>` or Text with `variant="label"`
- Don't pass HTML in `text`. It renders as plain text, so tags show up literally
Features
- It's inline, so you can use it inside a sentence or a list item
- CSS parts: `text` for the whole string, `mark` for each match
Preview
Usage
<arc-highlight
text="The quick brown fox jumps over the lazy dog"
query="fox"
></arc-highlight>
<!-- Case-sensitive matching -->
<arc-highlight
text="Hello World, hello world"
query="Hello"
case-sensitive
></arc-highlight>import { Highlight } from '@arclux/arc-ui-react';
function SearchResults({ results, query }) {
return results.map(r => (
<Highlight key={r.id} text={r.title} query={query} />
));
}<script setup>
import { ref } from 'vue';
import { Highlight } from '@arclux/arc-ui-vue';
const query = ref('');
const text = 'The quick brown fox jumps over the lazy dog';
</script>
<template>
<input v-model="query" placeholder="Search..." />
<Highlight :text="text" :query="query" />
</template><script>
import { Highlight } from '@arclux/arc-ui-svelte';
let query = '';
</script>
<input bind:value={query} placeholder="Search..." />
<Highlight text="The quick brown fox" {query} />import { Component } from '@angular/core';
import { Highlight } from '@arclux/arc-ui-angular';
@Component({
imports: [Highlight],
template: `
<input [(ngModel)]="query" placeholder="Search..." />
<arc-highlight [text]="text" [query]="query" />
`,
})
export class MyComponent {
text = 'The quick brown fox jumps over the lazy dog';
query = '';
}import { Highlight } from '@arclux/arc-ui-solid';
import { createSignal } from 'solid-js';
const [query, setQuery] = createSignal('');
<input onInput={(e) => setQuery(e.target.value)} />
<Highlight text="The quick brown fox" query={query()} />import { Highlight } from '@arclux/arc-ui-preact';
import { useState } from 'preact/hooks';
const [query, setQuery] = useState('');
<input onInput={(e) => setQuery(e.target.value)} />
<Highlight text="The quick brown fox" query={query} /><!-- Auto-generated by @arclux/prism — do not edit manually -->
<!-- arc-highlight — requires highlight.css + tokens.css (or arc-ui.css) -->
<span class="arc-highlight">
<span></span>
</span><!-- Auto-generated by @arclux/prism — do not edit manually -->
<!-- arc-highlight — self-contained, no external CSS needed -->
<span class="arc-highlight" style="display: inline">
<span></span>
</span>API
textstring''- The full text to display and search within
querystring''- The search query to highlight within the text
caseSensitivebooleanfalse- Whether matching should be case-sensitive