Overview
TheQueryPreview component retrieves and displays a preview of search results for a specific query without navigating away or performing a full search. This is perfect for implementing hover previews, dropdown suggestions with results, or “peek” functionality that shows users what results they’ll get before committing to a search.
When to Use
Use the QueryPreview component to:- Show result previews when hovering over query suggestions
- Display a subset of results in dropdown panels
- Implement “instant preview” functionality
- Help users make informed decisions before clicking a suggestion
- Reduce friction by showing results before full navigation
Installation
Import the component from the queries-preview module:Basic Usage
The component requires aqueryPreviewInfo object that defines what to preview:
Props
The information about the request for the query preview. Must include at minimum a
query property. Can also include filters and extraParams.Structure:The origin property for the request. Used for analytics and tracking to identify where the query preview was triggered from.
Number of query preview results to be rendered. Limits the results displayed even if more are available.
Controls whether the query preview request should be triggered only when the component becomes visible in the viewport. Useful for performance optimization.
Debounce time in milliseconds for triggering the search requests. Set to 0 for immediate requests (common in pre-search). Use 250ms or higher for empathize/search-as-you-type scenarios.
Controls whether the QueryPreview should remain in the state cache when the component is destroyed. Set to true to cache results for faster re-display.
Slots
Default Slot
Provide a custom layout for displaying the preview results and metadata. Slot Props:queryPreviewInfo(QueryPreviewInfo) - The query preview info objectresults(Result[]) - Array of result objectstotalResults(number) - Total number of results availabledisplayTagging(unknown) - Display tagging informationqueryTagging(unknown) - Query tagging information
result Slot
Customize only the result items without modifying the list structure. Slot Props:result(Result) - Individual result object
Events
X Bus Events
The component emits these events through the event bus:- QueryPreviewRequestUpdated: Emitted when the component mounts and when request properties change. Payload is the
queryPreviewRequestobject. - QueryPreviewMounted: Emitted when a cached query preview is mounted
- QueryPreviewUnmounted: Emitted when the component is destroyed
Vue Events
The component also emits standard Vue events:- load: Emitted when the query results have been successfully loaded. Payload is the
queryPreviewHash. - error: Emitted if there’s an error retrieving the query results. Payload is the
queryPreviewHash.
Examples
Basic Preview
Simple query preview with default rendering (shows result names):Custom Result Layout
Display results in a custom layout with images:Limited Results with Grid
Limit preview to 4 items and display in a grid:Lazy Loading with Debounce
Load preview only when visible, with debounced requests:Custom Result Item
Customize individual result rendering:Integration Tips
Query previews are cached in the state by default. If you want previews to persist after the component unmounts (for faster re-display), set
persistInCache to true.Query Preview Info
ThequeryPreviewInfo object structure:
Example with Filters
Styling
The component uses these CSS classes:.x-query-preview-wrapper__default-content- Default content wrapper.x-query-preview-wrapper__slot-content- Custom slot content wrapper.x-query-preview- Results list container.x-query-preview__item- Individual result item
Performance Optimization
- Lazy Loading: Use
loadWhenVisiblefor previews that aren’t immediately visible - Debouncing: Set
debounceTimeMsto reduce API calls during rapid interactions - Caching: Enable
persistInCacheto reuse previous preview results - Limit Results: Use
maxItemsToRenderto reduce payload size
Related Components
- Query Suggestions - Autocomplete suggestions (pairs well with previews)
- Next Queries - Related query suggestions
- Search Results - Full search results display
