Skip to content

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).

vue
<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>.

vue
<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).

vue
<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.

vue
<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 ​

PropTypeDefaultDescription
modelValuestring | number | null—Bound value, used as the input's value.
placeholderstring—Placeholder text shown while empty.
disabledbooleanfalseDisables the input and blocks interaction.
invalidbooleanundefined (→ FormField, else false)Applies the error border and focus ring and sets aria-invalid. Falls back to the enclosing FormField.
leadingIconstring—Lucide icon name rendered before the text (decorative).
trailingIconstring—Lucide icon name rendered after the text (decorative).
size'sm' | 'default' | 'lg''default'Control height (h-8 / h-9 / h-10).
typestring'text'Native input type (email, password, search, …).
idstringFormField idControl id. Falls back to the enclosing FormField id; an explicit value wins.
namestring—Native name, submitted with the form.
autocompletestring—Native autocomplete hint (for example email, current-password).
requiredbooleanundefined (→ FormField, else false)Marks the field required. Falls back to the enclosing FormField; an explicit value wins.

Events ​

EventPayloadDescription
update:modelValuestringEmitted on every input event with the current string value.

Slots ​

Input renders no slots. Use leadingIcon / trailingIcon for adornments.

Exposed methods ​

MethodDescription
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 matching id (or wrap it in a FormField, which supplies the id).
  • Every extra attribute falls through, so aria-label, aria-describedby, and aria-invalid can be set directly:
    vue
    <Input v-model="email" :invalid="!!error" aria-describedby="email-error" />
  • invalid both changes colour and sets aria-invalid, so the field is announced as invalid. When the field is inside a FormField, invalid defaults to the field's state; pass :invalid="false" to override it.
  • required reflects to the native required attribute. Inside a FormField it defaults to the field's required flag; an explicit prop wins.
  • Form-field wiring: inside a FormField, the input picks up the context id, aria-describedby (the description and error ids), aria-invalid, and required. Explicit props, and a consumer aria-describedby attribute, take precedence — so a custom aria-describedby is not overwritten.
  • The leading and trailing icons are rendered by Icon, which is always aria-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 uses primary-500; the invalid state uses error-500 in both themes.
  • Icons are positioned with logical utilities (start-3 / end-3) and text padding uses ps-* / pe-*, so the adornments flip to the correct edge under RTL. In an RTL form set dir="rtl" on an ancestor and the input text aligns to the start automatically.

Released under the MIT License.