Skip to main content
Vuetify0 is now in alpha!
Vuetify0 Logo
Theme
Mode
Palettes
Accessibility
Vuetify One
Sign in to Vuetify One

Access premium tools across the Vuetify ecosystem — Bin, Play, Studio, and more.

Not a subscriber? See what's included

toHighlight

Pure transformer that splits text into matched and unmatched chunks. Returns a plain HighlightChunk[] — wrap the call in computed() for reactive recomputation.

Usage

ts
import { computed } from 'vue'
import { toHighlight } from '@vuetify/v0'

const chunks = computed(() =>
  toHighlight(() => props.text, () => props.query, { ignoreCase: true })
)
// chunks.value → [{ text: 'Hello ', match: false }, { text: 'World', match: true }]

Architecture

toHighlight resolves its input through a fixed priority order:

Reactivity

toHighlight is a pure transformer — it reads each input through toValue once and returns a plain HighlightChunk[]. To make the result track upstream changes, wrap the call in computed() (or any reactive scope). The function itself creates no reactivity.

BehaviorReactiveNotes
Calling toHighlight(text, query)One-shot snapshot at call time
Wrapping in computed(() => toHighlight(...))Re-runs when tracked refs change
Passing refs or getters as argumentstoValue unwraps them on every call
Mutating returned chunksTreat the array as derived; do not mutate
Tip

Reach for plain values, refs, or getters Every input accepts MaybeRefOrGetter<T>. Pass a literal for static input, a Ref for v-model integration, or a getter (() => props.text) for prop-driven reactivity. Wrap the call in computed() when you want the result to update automatically.

Examples

Accessibility

Wrap matched chunks in the native <mark> element. It carries the implicit ARIA role mark and is announced by screen readers as highlighted or marked text. No additional ARIA attributes are needed on the wrapper element.

Tip

WCAG 1.4.3 (Contrast — Minimum) applies to highlighted text. Ensure sufficient contrast between the mark background color and the surrounding text.

FAQ

API Reference

The following API details are for the toHighlight composable.
Was this page helpful?

Ctrl+/