Selection and search
These components let a shopper choose things and find things. Use them for sorting, filtering, picking a size or colour, and searching the shop.
Select
A dropdown for picking one option, such as the sort order of a product list.
<script setup lang="ts">
import { ref } from 'vue';
import { FieldWrapper, Select } from '@eldrajs/ui';
import type { SelectOption } from '@eldrajs/ui';
const sortOptions: SelectOption[] = [
{ value: 'featured', label: 'Featured' },
{ value: 'price-asc', label: 'Price: low to high' },
{ value: 'price-desc', label: 'Price: high to low' },
{ value: 'newest', label: 'Newest' },
];
const sort = ref('featured');
const colourOptions: SelectOption[] = [
{ value: 'oatmeal', label: 'Oatmeal', swatch: '#d8c8ad', meta: 'In stock' },
{
value: 'charcoal',
label: 'Charcoal',
swatch: '#3c3c3c',
meta: 'Only 2 left',
metaTone: 'warning',
},
{ value: 'moss', label: 'Moss green', swatch: '#5d6b3a', meta: 'Sold out', disabled: true },
];
const colour = ref('');
</script>
<template>
<FieldWrapper label="Sort by">
<Select v-model="sort" :options="sortOptions" name="sort" />
</FieldWrapper>
<FieldWrapper label="Colour">
<Select
v-model="colour"
:options="colourOptions"
name="colour"
placeholder="Choose a colour"
clearable
/>
</FieldWrapper>
</template>| Prop | Default | What it does |
|---|---|---|
v-model | '' | The chosen value. An empty string means nothing is chosen. |
options | required | The choices. Each has a value and a label, and can add a swatch, hint, meta or disabled. |
placeholder | — | Text shown while nothing is chosen. |
searchable | on above 10 options | Adds a search field to the list. |
clearable | false | Shows a button that clears the choice. |
size | 'md' | sm, md or lg. Matches the height of a text input. |
TIP
Show a sold-out option as disabled with a meta note. Do not remove it, or shoppers think you never had it.
MultiSelect
A dropdown for picking several options at once, such as materials in a filter.
<script setup lang="ts">
import { ref } from 'vue';
import { FieldWrapper, MultiSelect } from '@eldrajs/ui';
import type { SelectOption } from '@eldrajs/ui';
const materialOptions: SelectOption[] = [
{ value: 'wool', label: 'Icelandic wool' },
{ value: 'merino', label: 'Merino' },
{ value: 'cotton', label: 'Organic cotton' },
{ value: 'alpaca', label: 'Alpaca' },
{ value: 'linen', label: 'Linen' },
];
const materials = ref<string[]>(['wool']);
</script>
<template>
<FieldWrapper label="Material">
<MultiSelect
v-model="materials"
:options="materialOptions"
name="material"
placeholder="Any material"
/>
</FieldWrapper>
</template>| Prop | Default | What it does |
|---|---|---|
v-model | [] | The chosen values, as an array. |
options | required | The choices, the same shape as for Select. |
placeholder | 'Any' | Text shown while nothing is chosen. |
showTags | true | Lists the chosen values as removable tags under the field. |
tagPlacement | 'below' | 'inside' puts the tags in the field itself. |
selectAll | true | Adds a "Select all" button to the list. |
Autocomplete
A text field that suggests values as the shopper types, such as a town in an address form.
<script setup lang="ts">
import { computed, ref } from 'vue';
import { Autocomplete, FieldWrapper } from '@eldrajs/ui';
import type { AutocompleteSuggestion } from '@eldrajs/ui';
const towns = [
{ value: 'reykjavik', label: 'Reykjavík', description: '101–155' },
{ value: 'kopavogur', label: 'Kópavogur', description: '200–203' },
{ value: 'hafnarfjordur', label: 'Hafnarfjörður', description: '220–222' },
{ value: 'akureyri', label: 'Akureyri', description: '600–603' },
{ value: 'egilsstadir', label: 'Egilsstaðir', description: '700' },
{ value: 'isafjordur', label: 'Ísafjörður', description: '400' },
];
const town = ref('');
const townSuggestions = computed<AutocompleteSuggestion[]>(() => {
const query = town.value.trim().toLowerCase();
if (!query) return [];
return towns.filter((t) => t.label.toLowerCase().startsWith(query));
});
</script>
<template>
<FieldWrapper label="Town" help="Type “re” or “ak” to see suggestions.">
<Autocomplete
v-model="town"
:suggestions="townSuggestions"
name="town"
autocomplete="address-level2"
/>
</FieldWrapper>
</template>| Prop | Default | What it does |
|---|---|---|
v-model | '' | The text in the field. |
suggestions | [] | The rows to offer for the current text. Each has a value, a label and an optional description. |
loading | false | Shows a spinner while you fetch suggestions. |
minLength | 1 | The list stays closed until the text is this long. |
clearable | false | Shows a button that clears the field. |
TIP
The component does not filter for you. Filter or fetch the suggestions yourself whenever the text changes. Listen to @select to learn which row was picked.
SearchBar
A search field with a live results panel, for the shop header or the search page.
<script setup lang="ts">
import { computed, ref } from 'vue';
import { SearchBar } from '@eldrajs/ui';
import type { SearchResults } from '@eldrajs/ui';
const sweaterImage = '/images/lopi-sweater-thumb.jpg';
const beanieImage = '/images/wool-beanie-thumb.jpg';
// Replace with a call to your search endpoint.
const allResults: SearchResults = {
products: [
{
id: 'p1',
title: 'Lopi wool sweater',
href: '/products/lopi-sweater',
price: '24.900 kr.',
image: sweaterImage,
imageAlt: '',
},
{
id: 'p2',
title: 'Wool beanie',
href: '/products/wool-beanie',
price: '5.900 kr.',
image: beanieImage,
imageAlt: '',
},
],
collections: [{ id: 'c1', title: 'Knitwear', href: '/collections/knitwear' }],
articles: [{ id: 'a1', title: 'How to wash wool', href: '/journal/washing-wool' }],
pages: [],
total: 14,
};
const searchQuery = ref('');
const searchResults = computed(() => (searchQuery.value.trim() ? allResults : undefined));
</script>
<template>
<SearchBar
v-model="searchQuery"
:results="searchResults"
:popular="['Lopi sweater', 'Beanie', 'Mittens']"
:recent="[]"
:shortcut="false"
pill
/>
</template>| Prop | Default | What it does |
|---|---|---|
v-model | '' | The search text. Fetch new results when it changes. |
results | — | The results to show: products, collections, articles, pages and a total. |
action | '/search' | The search page. Pressing Enter goes there with the text as ?q=. |
popular | — | Popular searches, shown before the shopper types and when nothing matches. |
pill | false | Fully rounded field, for a header. |
shortcut | true | Lets the / key jump to the field. |
TIP
Format prices before you pass them in, for example 24.900 kr.. The search bar shows the text as it is.
SearchModal
A full-screen search dialog, for a header that has only a search icon.
<script setup lang="ts">
import { computed, ref } from 'vue';
import { Button, SearchModal } from '@eldrajs/ui';
const searchOpen = ref(false);
const modalQuery = ref('');
// allResults has the same shape as in the SearchBar example.
const modalResults = computed(() => (modalQuery.value.trim() ? allResults : undefined));
</script>
<template>
<Button variant="outline" @click="searchOpen = true">Search the shop</Button>
<SearchModal
v-model="searchOpen"
v-model:query="modalQuery"
:results="modalResults"
:popular="['Lopi sweater', 'Beanie']"
:recent="[]"
:shortcut="false"
/>
</template>| Prop | Default | What it does |
|---|---|---|
v-model | false | Whether the dialog is open. |
v-model:query | '' | The search text. It is reset when the dialog closes. |
results | — | The results to show, the same shape as for SearchBar. |
action | '/search' | The search page. Pressing Enter goes there with the text as ?q=. |
shortcut | true | Opens the dialog on /, and on ⌘K or Ctrl+K. |
TIP
Turn shortcut on for only one search on a page. Two listeners for the same key fight over it.
Chip and ChipGroup
A small labelled pill. Use removable chips for applied filters, and a ChipGroup of selectable chips for quick toggles.
<script setup lang="ts">
import { ref } from 'vue';
import { Chip, ChipGroup } from '@eldrajs/ui';
const appliedFilters = ref(['Wool', 'Size M', 'Under 20.000 kr.']);
function removeFilter(label: string) {
appliedFilters.value = appliedFilters.value.filter((f) => f !== label);
}
const fits = ref<string[]>(['regular']);
</script>
<template>
<div style="display: flex; gap: 0.5rem; flex-wrap: wrap">
<Chip
v-for="filter in appliedFilters"
:key="filter"
:label="filter"
removable
@remove="removeFilter(filter)"
/>
</div>
<ChipGroup v-model="fits" aria-label="Fit">
<Chip value="slim" label="Slim" selectable />
<Chip value="regular" label="Regular" selectable />
<Chip value="relaxed" label="Relaxed" selectable />
</ChipGroup>
</template>| Prop | Default | What it does |
|---|---|---|
label | required | The chip's text. |
removable | false | Adds a remove button. Listen to @remove. |
selectable | false | Makes the chip a toggle button. Use v-model:selected on its own. |
value | — | The chip's value inside a ChipGroup. |
size | 'md' | sm or md. |
ChipGroup v-model / ariaLabel | required | The selected values, and the group's name for screen readers. |
TIP
A chip is either removable or selectable, not both. If you set both, the chip only removes.
VariantPicker
Lets a shopper pick one product option, such as a colour or a size, on a product page.
<script setup lang="ts">
import { ref } from 'vue';
import { VariantPicker } from '@eldrajs/ui';
const sweaterColour = ref('oatmeal');
const sweaterSize = ref('m');
</script>
<template>
<VariantPicker
v-model="sweaterColour"
name="colour"
legend="Colour"
type="swatches"
:options="[
{ value: 'oatmeal', label: 'Oatmeal', swatch: '#d8c8ad', available: true },
{ value: 'charcoal', label: 'Charcoal', swatch: '#3c3c3c', available: true },
{ value: 'moss', label: 'Moss green', swatch: '#5d6b3a', available: false },
]"
/>
<VariantPicker
v-model="sweaterSize"
name="size"
legend="Size"
:options="[
{ value: 's', label: 'S', available: true },
{ value: 'm', label: 'M', available: true },
{ value: 'l', label: 'L', available: true },
{ value: 'xl', label: 'XL', available: false },
]"
/>
</template>| Prop | Default | What it does |
|---|---|---|
v-model | first available option | The chosen value. |
name | required | The radio group name. Also the visible label when legend is not set. |
legend | — | The visible label, when name must be unique per product. |
type | 'pills' | pills for text such as sizes, swatches for colours. |
options | required | Each has a value, a label, available, and a swatch colour for swatches. |
TIP
Give each picker its own name when a page shows several products, for example size-1234. Pickers with the same name act as one group.
CurrencyPicker
Lets a visitor choose which currency the shop shows prices in.
<script setup lang="ts">
import { ref } from 'vue';
import { CurrencyPicker } from '@eldrajs/ui';
const currency = ref('ISK');
</script>
<template>
<CurrencyPicker v-model="currency" :currencies="['ISK', 'EUR', 'USD']" />
<CurrencyPicker v-model="currency" :currencies="['ISK', 'EUR', 'USD']" show-label size="md" />
</template>| Prop | Default | What it does |
|---|---|---|
currencies | required | ISO 4217 codes to offer, the shop's own first. |
v-model | — | The chosen code. |
showLabel | false | Shows the "Currency" label. Leave it off in a header. |
size | 'sm' | sm, md or lg. |
busy | false | Says a change is in progress, for example while the cart is repriced. |
TIP
With fewer than two currencies the picker renders nothing. You can leave it in the header for every shop.
FilterPanel
The filter sidebar for a product list: categories, colours, sizes, a price range and on/off switches.
<script setup lang="ts">
import { ref } from 'vue';
import { FilterPanel } from '@eldrajs/ui';
import type { FilterFacet, FilterSelection } from '@eldrajs/ui';
const facets: FilterFacet[] = [
{
id: 'category',
label: 'Category',
type: 'list',
values: [
{ value: 'sweaters', label: 'Sweaters', count: 18 },
{ value: 'cardigans', label: 'Cardigans', count: 7 },
{ value: 'hats', label: 'Hats', count: 12 },
{ value: 'mittens', label: 'Mittens', count: 0 },
],
},
{
id: 'colour',
label: 'Colour',
type: 'colour',
values: [
{ value: 'oatmeal', label: 'Oatmeal', count: 11, swatch: '#d8c8ad' },
{ value: 'charcoal', label: 'Charcoal', count: 9, swatch: '#3c3c3c' },
{ value: 'moss', label: 'Moss green', count: 4, swatch: '#5d6b3a' },
],
},
{
id: 'size',
label: 'Size',
type: 'size',
values: [
{ value: 's', label: 'S', count: 8 },
{ value: 'm', label: 'M', count: 12 },
{ value: 'l', label: 'L', count: 10 },
{ value: 'xl', label: 'XL', count: 0 },
],
},
{ id: 'price', label: 'Price', type: 'range', min: 3000, max: 40000, step: 500, currency: true },
{
id: 'availability',
label: 'Availability',
type: 'toggle',
values: [{ value: 'in_stock', label: 'In stock only', count: 31 }],
},
];
const filters = ref<FilterSelection>({ category: ['sweaters'] });
</script>
<template>
<FilterPanel v-model="filters" :facets="facets" currency="ISK" locale="is-IS" />
</template>| Prop | Default | What it does |
|---|---|---|
v-model | {} | The selection, keyed by facet id. A list is an array of values; a range is [min, max]. |
facets | — | The filter groups, in the order they are drawn. Each has an id, a label and a type. |
mode | 'sidebar' | sidebar applies each change at once. drawer waits for the "Show N products" button. |
resultCount | — | The number of matching products, shown on the drawer's button. |
currency | the shop's currency | The currency a price range is shown in. |
showApplied | false | Shows the active filters as removable chips above the groups. |
TIP
Count each value without its own facet's filter applied. A value with a count of 0 then shows as unavailable instead of disappearing.