Components
Input with Icon
An input with a leading or trailing decorative icon.
Installation
$ npx veil-ui@latest add input-with-iconUsage
import { Search } from "lucide-react";
import { InputWithIcon } from "@/components/ui/input-with-icon";
<InputWithIcon icon={Search} placeholder="Search…" aria-label="Search" />;Examples
Basic
Trailing
API reference
The package exports input-with-icon along with its composable parts. It forwards standard attributes to its root element; see the examples above for the component-specific props.
Accessibility
- The decorative icon is
aria-hidden; the input keeps its own accessible name from a label oraria-label. - Error and disabled states are exposed through native attributes and Radix data attributes.
- Focus-visible rings follow the shared token system in both themes.
Vue and plain HTML
This component also ships for Vue (Reka UI) and plain HTML. Install it with npx veil-ui add input-with-icon --framework vue or switch the framework in components.json.
<script setup lang="ts">
import { computed } from "vue";
import { Input } from "@/components/ui/input";
import { cn } from "@/lib/utils";
import type { InputWithIconProps } from "./types";
defineOptions({ inheritAttrs: false });
const props = withDefaults(defineProps<InputWithIconProps>(), {
position: "left",
});
const iconClasses = computed(() =>
cn(
"pointer-events-none absolute top-1/2 size-4 -translate-y-1/2 text-muted-foreground",
props.position === "left" ? "left-3" : "right-3",
),
);
const inputClasses = computed(() =>
cn(props.position === "left" ? "pl-9" : "pr-9", props.class),
);
</script>
<template>
<div data-slot="input-with-icon" class="relative w-full">
<component :is="props.icon" aria-hidden="true" :class="iconClasses" />
<Input v-bind="$attrs" :class="inputClasses" />
</div>
</template>