Input
Input is a single-line text field. It renders a native <input> styled from the design tokens, with optional leading/trailing icons, three sizes, a visual invalid state, and native form attributes (type, id, name, autocomplete, required).
<script setup lang="ts">
import { ref } from 'vue'
import { Input } from '@myghf/ui'
const email = ref('')
</script>
<template>
<Input
v-model="email"
type="email"
name="email"
autocomplete="email"
required
placeholder="you@example.com"
/>
</template>Examples
Basics
type, id, name, autocomplete, and required are first-class props. Any other attribute — aria-*, form, minlength — falls through to the native <input>, so Input also works with an external <label for>.
<script setup lang="ts">
import { ref } from 'vue'
import { Input } from '@myghf/ui'
const email = ref('')
const search = ref('')
const invalidValue = ref('not-an-email')
</script>
<template>
<div class="grid max-w-md gap-4">
<div class="grid gap-1.5">
<label class="text-sm font-medium text-foreground" for="demo-input-email">Email</label>
<Input id="demo-input-email" v-model="email" type="email" placeholder="you@example.com" />
</div>
<Input v-model="search" leading-icon="search" placeholder="Search patients" />
<Input
v-model="invalidValue"
invalid
leading-icon="circle-alert"
aria-label="Invalid field"
/>
</div>
</template>Sizes
sm, default, and lg set the control height. invalid switches the border and focus ring to error-500 and sets aria-invalid; it is a visual + ARIA flag (see Accessibility).
<script setup lang="ts">
import { ref } from 'vue'
import { Input } from '@myghf/ui'
const value = ref('Aswan Heart Centre')
</script>
<template>
<div class="grid max-w-md gap-3">
<Input v-model="value" size="sm" aria-label="Small input" />
<Input v-model="value" aria-label="Default input" />
<Input v-model="value" size="lg" aria-label="Large input" />
</div>
</template>Inside a FormField
Wrap the input in FormField and it inherits the field id, the aria-describedby ids for the description and error, aria-invalid, and required — no manual wiring. Explicit props (and a consumer aria-describedby attribute) still win over the context, so you can opt out per field.
As it appears on your record.
Enter a valid email address.
<script setup lang="ts">
import { ref } from 'vue'
import { FormField, Input } from '@myghf/ui'
const name = ref('')
const email = ref('not-an-email')
</script>
<template>
<div class="grid max-w-sm gap-6">
<FormField id="ff-demo-name" label="Full name" required description="As it appears on your record.">
<Input v-model="name" autocomplete="name" placeholder="Ada Lovelace" />
</FormField>
<FormField id="ff-demo-email" label="Email" error="Enter a valid email address.">
<Input v-model="email" type="email" autocomplete="email" placeholder="you@example.com" />
</FormField>
</div>
</template>Props
| Prop | Type | Default | Description |
|---|---|---|---|
modelValue | string | number | null | — | Bound value, used as the input's value. |
placeholder | string | — | Placeholder text shown while empty. |
disabled | boolean | false | Disables the input and blocks interaction. |
invalid | boolean | undefined (→ FormField, else false) | Applies the error border and focus ring and sets aria-invalid. Falls back to the enclosing FormField. |
leadingIcon | string | — | Lucide icon name rendered before the text (decorative). |
trailingIcon | string | — | Lucide icon name rendered after the text (decorative). |
size | 'sm' | 'default' | 'lg' | 'default' | Control height (h-8 / h-9 / h-10). |
type | string | 'text' | Native input type (email, password, search, …). |
id | string | FormField id | Control id. Falls back to the enclosing FormField id; an explicit value wins. |
name | string | — | Native name, submitted with the form. |
autocomplete | string | — | Native autocomplete hint (for example email, current-password). |
required | boolean | undefined (→ FormField, else false) | Marks the field required. Falls back to the enclosing FormField; an explicit value wins. |
Events
| Event | Payload | Description |
|---|---|---|
update:modelValue | string | Emitted on every input event with the current string value. |
Slots
Input renders no slots. Use leadingIcon / trailingIcon for adornments.
Exposed methods
| Method | Description |
|---|---|
focus() | Focuses the underlying <input>. |
Accessibility
- The control is a real
<input>, so it participates in native form submission and label association. Pair it with a visible<label for="…">and give the input a matchingid(or wrap it in aFormField, which supplies the id). - Every extra attribute falls through, so
aria-label,aria-describedby, andaria-invalidcan be set directly:vue<Input v-model="email" :invalid="!!error" aria-describedby="email-error" /> invalidboth changes colour and setsaria-invalid, so the field is announced as invalid. When the field is inside aFormField,invaliddefaults to the field's state; pass:invalid="false"to override it.requiredreflects to the nativerequiredattribute. Inside aFormFieldit defaults to the field'srequiredflag; an explicit prop wins.- Form-field wiring: inside a
FormField, the input picks up the contextid,aria-describedby(the description and error ids),aria-invalid, andrequired. Explicit props, and a consumeraria-describedbyattribute, take precedence — so a customaria-describedbyis not overwritten. - The leading and trailing icons are rendered by
Icon, which is alwaysaria-hidden, so they never contribute to the accessible name.
Dark mode & RTL
- The field styles from semantic tokens (
bg-surface,text-foreground,border-border,placeholder:text-muted), so it adapts to dark mode automatically. The focus ring usesprimary-500; the invalid state useserror-500in both themes. - Icons are positioned with logical utilities (
start-3/end-3) and text padding usesps-*/pe-*, so the adornments flip to the correct edge under RTL. In an RTL form setdir="rtl"on an ancestor and the input text aligns to the start automatically.
