Skip to content

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.

input-basic.html
<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>

Sizes

Three heights that line up with the Button sizes. Inputs without a visible label need an aria-label.

input-sizes.html
<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>

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.

input-states.html
<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>

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:

Terminal
npx @vinish/ui add input
React
import { Field, Input, Label } from "@/components/vin/input";
Vue
import Field, { Input, Label, inputClasses } from "@/components/vin/input.vue";
Svelte
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.

PropValuesDefaultIn HTML
sizesmmdlgmdvin-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.
booleanfalse<textarea class="vin-input">
disabledbooleanfalsedisabled attribute

Parts

React, Vue, SvelteHTML 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.