Components
Mobile Search
A rounded search field with clear and recent-suggestion controls.
Installation
$ npx veil-ui@latest add mobile-searchUsage
import { MobileSearch } from "@/components/ui/mobile-search";
<MobileSearch
placeholder="Search projects"
suggestions={["Design tokens", "Release notes"]}
onSearch={search}
/>;Examples
Basic
Try a suggestion
Minimal
API reference
The package exports mobile-search along with its composable parts. It forwards standard attributes to its root element; see the examples above for the component-specific props.
Accessibility
- Touch targets are large enough to tap comfortably and keep visible focus rings for keyboard and switch users.
- Gesture interactions (swipe, pull to refresh) have visible button alternatives so they are not the only way to act.
- Sheets, drawers and dialogs follow the underlying accessible primitives for focus trapping and escape handling.
Vue and plain HTML
This component also ships for Vue (Reka UI) and plain HTML. Install it with npx veil-ui add mobile-search --framework vue or switch the framework in components.json.
<script setup lang="ts">
import { Clock, Search, X } from "lucide-vue-next";
import { cn } from "@/lib/utils";
const props = withDefaults(
defineProps<{
placeholder?: string;
suggestions?: string[];
defaultValue?: string;
class?: string;
}>(),
{ placeholder: "Search", suggestions: () => [], defaultValue: "" },
);
const emit = defineEmits<{ search: [query: string]; clear: [] }>();
const query = defineModel<string>("modelValue", { default: "" });
if (props.defaultValue && !query.value) query.value = props.defaultValue;
function submit() {
emit("search", query.value);
}
function clear() {
query.value = "";
emit("clear");
}
</script>
<template>
<div data-slot="mobile-search" :class="cn('w-full max-w-sm', props.class)">
<form
role="search"
class="flex items-center gap-2 rounded-full border bg-muted/40 px-3 focus-within:ring-[3px] focus-within:ring-ring/30"
@submit.prevent="submit"
>
<Search class="size-4 shrink-0 text-muted-foreground" aria-hidden="true" />
<input
v-model="query"
type="search"
:placeholder="placeholder"
:aria-label="placeholder"
class="h-11 min-w-0 flex-1 bg-transparent text-sm outline-none placeholder:text-muted-foreground [&::-webkit-search-cancel-button]:hidden"
/>
<button
v-if="query"
type="button"
aria-label="Clear search"
class="rounded-full p-1 text-muted-foreground transition-colors hover:text-foreground"
@click="clear"
>
<X class="size-4" aria-hidden="true" />
</button>
</form>
<ul v-if="suggestions.length > 0" class="mt-3 grid gap-1" aria-label="Recent searches">
<li v-for="suggestion in suggestions" :key="suggestion">
<button
type="button"
class="flex w-full items-center gap-2 rounded-md px-2 py-2 text-left text-sm text-muted-foreground transition-colors hover:bg-accent hover:text-accent-foreground"
@click="query = suggestion; submit()"
>
<Clock class="size-3.5" aria-hidden="true" />
{{ suggestion }}
</button>
</li>
</ul>
</div>
</template>