Skip to content

Inputs - AvInput

✨ Introduction

The AvInput component is a flexible and accessible input component that provides a standardized way to collect user input in forms and interfaces. It supports various input types, validation states, and accessibility features to ensure a consistent user experience.

It adds prefix icon support, enhanced validation messaging, and custom styling while maintaining full compatibility with the French government's design system standards.

🏗️ Structure

The input component consists of the following elements:

  • Wrapper: Container that manages the overall layout and positioning
  • Prefix Icon (optional): Visual icon positioned at the beginning of the input field
  • Input Field: The main input element (can be rendered as input or textarea)
  • Label: Descriptive text for the input field
  • Hint: Optional helper text displayed below the label
  • Error Messages: Validation error messages displayed when validation fails
  • Success Messages: Validation success messages displayed when validation passes

The component integrates focus management, proper ARIA attributes, and responsive design patterns.

🏷️ Props

NameTypeDefaultMandatoryDescription
idstringinput-${crypto.randomUUID()}ID of the input element
descriptionIdstringundefinedID of the description element
hintstringundefinedHint text displayed below the label
isValidbooleanfalseValidation state - valid
isTextareabooleanfalseRender as textarea instead of input
labelVisiblebooleantrueWhether the label is visible
labelstringundefinedLabel text
labelClassstring'b2-light'CSS class for the label
modelValuestring | number | nullundefinedModel value for v-model
placeholderstringundefinedPlaceholder text
type'text' | 'email' | 'password' | 'number' | 'tel' | 'url' | 'search''text'Input type
minDateDateundefinedMinimum date for date inputs
maxDateDateundefinedMaximum date for date inputs
disabledbooleanfalseWhether the input is disabled
requiredbooleanfalseWhether the input is required
maxlengthnumberundefinedMaximum length of input
minlengthnumberundefinedMinimum length of input
errorMessagestring | string[]undefinedError message(s) to display
validMessagestring | string[]undefinedValid message(s) to display
prefixIconstringundefinedPrefix icon name (optional)
widthstringundefinedWidth of the input
noRadiusbooleanfalseRemoves the radii from the input border

🔊 Events

NameData (payload)Description
update:modelValuestring | number | nullEmitted when the input value changes

🎨 Slots

NameDescriptionSlot Props
requiredTipSlot for custom required field indicatorNone
customCaptionsSlot for custom captions, such as character count or additional infocurrentValue: string | number | null, maxlength: number | undefined

🚀 Storybook demos

You can find examples of use and demo of the component on its dedicated Storybook page.

💡 Examples of use

Basic Input

vue
<AvInput
  v-model="fullName"
  label="Full Name"
  placeholder="Enter your full name"
/>

Email Input with Icon

vue
<AvInput
  v-model="email"
  type="email"
  label="Email Address"
  placeholder="Enter your email"
  prefix-icon="mdi:email-outline"
  required
/>

Password Input

vue
<AvInput
  v-model="password"
  type="password"
  label="Password"
  placeholder="Enter your password"
  prefix-icon="mdi:lock-outline"
  :minlength="8"
  required
/>

Textarea

vue
<AvInput
  v-model="message"
  is-textarea
  label="Message"
  placeholder="Enter your message..."
  :maxlength="500"
/>

With Validation

vue
<AvInput
  v-model="username"
  label="Username"
  :error-message="usernameError"
  :valid-message="usernameValid"
  :minlength="3"
  required
/>

Search Input

vue
<AvInput
  v-model="searchQuery"
  type="search"
  label="Search"
  placeholder="Search for items..."
  prefix-icon="mdi:magnify"
/>

With Custom Captions

vue
<AvInput
  v-model="message"
  is-textarea
  label="Message"
  :maxlength="200"
>
  <template #customCaptions="{ currentValue, maxlength }">
    <span class="caption-light">
      {{ currentValue?.toString().length }} / {{ maxlength }} characters
    </span>
  </template>
</AvInput>

Form with Multiple Inputs

vue
<template>
  <form @submit.prevent="handleSubmit">
    <AvInput
      v-model="form.email"
      label="Email"
      type="email"
      prefix-icon="mdi:email-outline"
      :error-message="errors.email"
      required
    />

    <AvInput
      v-model="form.password"
      label="Password"
      type="password"
      prefix-icon="mdi:lock-outline"
      :error-message="errors.password"
      :minlength="8"
      required
    />

    <AvInput
      v-model="form.bio"
      label="Bio"
      is-textarea
      hint="Tell us about yourself"
      :maxlength="500"
    />

    <button type="submit">
      Submit
    </button>
  </form>
</template>