Input
A text field with its label, hint and error message. Same markup and props in every style: switch the style in the header to see it change.
Basic
Field connects the label, the input and the hint for you. In HTML, match the for/id and aria-describedby yourself.
We'll never share it.
<div class="vin-field" style="width: 100%; max-width: 320px">
<label class="vin-label" for="email">Email</label>
<input id="email" class="vin-input" type="email" placeholder="you@example.com" aria-describedby="email-hint">
<p class="vin-hint" id="email-hint">We'll never share it.</p>
</div>We'll never share it.
import { Field } from "@/components/vin/input";
export function InputBasic() {
return <Field label="Email" type="email" placeholder="you@example.com" hint="We'll never share it." style={{ width: "100%", maxWidth: 320 }} />;
}The Vue version renders the same markup as the HTML tab, so it looks and works the same.
<script setup lang="ts">
import Field from "@/components/vin/input.vue";
</script>
<template>
<Field label="Email" type="email" placeholder="you@example.com" hint="We'll never share it." style="width: 100%; max-width: 320px" />
</template>The Svelte version renders the same markup as the HTML tab, so it looks and works the same.
<script lang="ts">
import Field from "$lib/components/vin/input-field.svelte";
</script>
<Field label="Email" type="email" placeholder="you@example.com" hint="We'll never share it." style="width: 100%; max-width: 320px" />Sizes
Three heights that line up with the Button sizes. Inputs without a visible label need an aria-label.
<div class="vin-field" style="width: 100%; max-width: 320px">
<input class="vin-input vin-input--sm" aria-label="Small input" placeholder="Small">
<input class="vin-input" aria-label="Medium input" placeholder="Medium">
<input class="vin-input vin-input--lg" aria-label="Large input" placeholder="Large">
</div>import { Input } from "@/components/vin/input";
export function InputSizes() {
return (
<div className="vin-field" style={{ width: "100%", maxWidth: 320 }}>
<Input size="sm" aria-label="Small input" placeholder="Small" />
<Input aria-label="Medium input" placeholder="Medium" />
<Input size="lg" aria-label="Large input" placeholder="Large" />
</div>
);
}The Vue version renders the same markup as the HTML tab, so it looks and works the same.
<script setup lang="ts">
import { Input } from "@/components/vin/input.vue";
</script>
<template>
<div class="vin-field" style="width: 100%; max-width: 320px">
<Input size="sm" aria-label="Small input" placeholder="Small" />
<Input aria-label="Medium input" placeholder="Medium" />
<Input size="lg" aria-label="Large input" placeholder="Large" />
</div>
</template>The Svelte version renders the same markup as the HTML tab, so it looks and works the same.
<script lang="ts">
import Input from "$lib/components/vin/input.svelte";
</script>
<div class="vin-field" style="width: 100%; max-width: 320px">
<Input size="sm" aria-label="Small input" placeholder="Small" />
<Input aria-label="Medium input" placeholder="Medium" />
<Input size="lg" aria-label="Large input" placeholder="Large" />
</div>Error, disabled, multi-line
An error message marks the input invalid and is read out with it. Use multiline for longer text.
That username is taken.
<div style="display: grid; gap: 16px; width: 100%; max-width: 320px">
<div class="vin-field">
<label class="vin-label" for="username">Username</label>
<input id="username" class="vin-input" value="vinish" aria-invalid="true" aria-describedby="username-error">
<p class="vin-error" id="username-error">That username is taken.</p>
</div>
<div class="vin-field">
<label class="vin-label" for="plan">Plan</label>
<input id="plan" class="vin-input" value="Free" disabled>
</div>
<div class="vin-field">
<label class="vin-label" for="bio">Bio</label>
<textarea id="bio" class="vin-input" rows="3" placeholder="A few words about you"></textarea>
</div>
</div>That username is taken.
import { Field } from "@/components/vin/input";
export function InputStates() {
return (
<div style={{ display: "grid", gap: 16, width: "100%", maxWidth: 320 }}>
<Field label="Username" defaultValue="vinish" error="That username is taken." />
<Field label="Plan" defaultValue="Free" disabled />
<Field label="Bio" multiline rows={3} placeholder="A few words about you" />
</div>
);
}The Vue version renders the same markup as the HTML tab, so it looks and works the same.
<script setup lang="ts">
import Field from "@/components/vin/input.vue";
</script>
<template>
<div style="display: grid; gap: 16px; width: 100%; max-width: 320px">
<Field label="Username" default-value="vinish" error="That username is taken." />
<Field label="Plan" default-value="Free" disabled />
<Field label="Bio" multiline :rows="3" placeholder="A few words about you" />
</div>
</template>The Svelte version renders the same markup as the HTML tab, so it looks and works the same.
<script lang="ts">
import Field from "$lib/components/vin/input-field.svelte";
</script>
<div style="display: grid; gap: 16px; width: 100%; max-width: 320px">
<Field label="Username" value="vinish" error="That username is taken." />
<Field label="Plan" value="Free" disabled />
<Field label="Bio" multiline rows={3} placeholder="A few words about you" />
</div>Installation
React, Vue and Svelte: add the component to your project with the CLI. It reads your framework from vin.json and also copies any component this one needs. Then import it:
npx @vinish/ui add inputimport { Field, Input, Label } from "@/components/vin/input";import Field, { Input, Label, inputClasses } from "@/components/vin/input.vue";import Input, { inputClasses } from "$lib/components/vin/input.svelte";
import Field from "$lib/components/vin/input-field.svelte";
import Label from "$lib/components/vin/input-label.svelte";The import paths assume the default folders: @/components/vin (React and Vue, with the usual @ → src alias) and $lib/components/vin (SvelteKit). Use your own if you chose another folder in init. How the Vue and Svelte versions pass values and content is in Frameworks.
Plain HTML: the classes come with the style's stylesheet. It needs no JavaScript.
API
From spec/input.json, which every framework version is tested against.
| Prop | Values | Default | In HTML |
|---|---|---|---|
size | smmdlg | md | vin-input--{value} |
label (Field)Field only: the visible label, linked to the input. | string | — | <label class="vin-label" for="…"> |
hint (Field)Field only: help text under the input. | string | — | <p class="vin-hint" id="…"> + aria-describedby |
error (Field)Field only: an error message. Also marks the input invalid. | string | — | <p class="vin-error"> + aria-invalid="true" |
multiline (Field)Field only: render a textarea. | boolean | false | <textarea class="vin-input"> |
disabled | boolean | false | disabled attribute |
Parts
| React, Vue, Svelte | HTML classes |
|---|---|
<Field><Input><Label> | .vin-field.vin-label.vin-input.vin-input--sm.vin-input--lg.vin-hint.vin-error |
Accessibility
- Every input has a label: a visible <label for> or, if there is no visible label, an aria-label.
- Hints and errors are linked with aria-describedby, so screen readers read them with the field.
- An error sets aria-invalid="true" and is shown as text, not only as a red border.
- Visible focus ring in every style and mode.
Customize
Saved in this browser. Style and accent are in the header.