Skip to content

BaseInput

Input component with v-model, validation state, and prefix/suffix slots.

Basic

Value:

<template>
  <div style="max-width:320px">
    <BaseInput v-model="value" label="Email" placeholder="you@example.com" />
    <p style="margin-top:8px;font-size:13px;color:#6b7280">Value: {{ value }}</p>
  </div>
</template>

<script setup lang="ts">
import { ref } from 'vue'
const value = ref('')
</script>

Validation

<template>
  <div style="max-width:320px;display:flex;flex-direction:column;gap:12px">
    <BaseInput
      v-model="value"
      label="Username"
      :required="true"
      :error="hasError"
      :error-message="hasError ? 'This field is required' : undefined"
      placeholder="Enter username"
    />
    <BaseButton size="sm" @click="validate">Validate</BaseButton>
  </div>
</template>

<script setup lang="ts">
import { ref, computed } from 'vue'
const value = ref('')
const touched = ref(false)
const hasError = computed(() => touched.value && !value.value.trim())
function validate() { touched.value = true }
</script>

Prefix & Suffix

$USD

<template>
  <div style="max-width:320px">
    <BaseInput v-model="value" label="Price" placeholder="0.00">
      <template #prefix>$</template>
      <template #suffix>USD</template>
    </BaseInput>
  </div>
</template>

<script setup lang="ts">
import { ref } from 'vue'
const value = ref('')
</script>

Props

PropTypeDefaultDescription
modelValuestring | number''Input value (v-model)
labelstringLabel text above input
placeholderstringInput placeholder
typetext | password | email | number | search | tel | urltextInput type
disabledbooleanfalseDisables the input
readonlybooleanfalseMakes input read-only
requiredbooleanfalseShows asterisk on label
errorbooleanfalseApplies error styling
errorMessagestringError text below input
hintstringHint text (hidden when errorMessage is set)

Events

EventPayloadDescription
update:modelValuestringEmitted on every input
blurFocusEventEmitted on blur
focusFocusEventEmitted on focus

Slots

SlotDescription
prefixContent placed before the input field
suffixContent placed after the input field