1 estrella en GitHub = 1 componente nuevo.

Dar una estrella
Formularios inputvalidation

Error Input

Campo de formulario con estado de validación de error, icono y mensaje de ayuda.

Vista Previa en Vivo

Uso

Copia y pega este código directamente en tu página de Astro:

astro
---
import { ErrorInput } from 'astro-component-kit';
---

<ErrorInput id="user" errorMessage="Username is already taken" value="konstantin" />
--- import { ErrorInput } from 'astro-component-kit'; --- <ErrorInput id="user" errorMessage="Username is already taken" value="konstantin" />

Instalación Manual

Si no estás usando el paquete npm, crea un archivo nuevo y pega el siguiente código: src/components/lib/ErrorInput.astro:

astro
---
/**
 * ErrorInput — A styled input strictly formatted to demonstrate error or invalid validation states.
 * 
 * @param {string} id - The ID for the input form element.
 * @param {string} errorMessage - The message text presented below the input field.
 * @param {string} value - Default starting value mimicking failed data.
 * @param {string} placeholder - Optional standard placeholder.
 * @param {string} name - HTML name binding.
 */
interface Props {
  id: string;
  errorMessage: string;
  value?: string;
  placeholder?: string;
  name?: string;
}

const { id, errorMessage, value = '', placeholder, name } = Astro.props;
---

<div class="error-wrap">
  <input type="text" {id} {name} {value} {placeholder} class="input-error" aria-invalid="true" aria-describedby={`${id}-error`} />
  <span id={`${id}-error`} class="error-msg" aria-live="polite">{errorMessage}</span>
</div>

<style>
  .error-wrap { display: flex; flex-direction: column; gap: 0.4rem; width: 100%; box-sizing: border-box; }
  .input-error { 
    border: 1px solid var(--c-error, #ef4444) !important; 
    background: rgba(239, 68, 68, 0.05) !important; 
    padding: var(--sp-3, 0.8rem); 
    color: var(--c-text-1, #fff); 
    border-radius: var(--r-sm, 10px); outline: none; 
    font-family: inherit; font-size: 0.95rem; box-sizing: border-box;
  }
  .error-msg { font-size: 0.75rem; color: #f87171; font-weight: 500; }
</style>
--- /** * ErrorInput — A styled input strictly formatted to demonstrate error or invalid validation states. * * @param {string} id - The ID for the input form element. * @param {string} errorMessage - The message text presented below the input field. * @param {string} value - Default starting value mimicking failed data. * @param {string} placeholder - Optional standard placeholder. * @param {string} name - HTML name binding. */ interface Props { id: string; errorMessage: string; value?: string; placeholder?: string; name?: string; } const { id, errorMessage, value = '', placeholder, name } = Astro.props; --- <div class="error-wrap"> <input type="text" {id} {name} {value} {placeholder} class="input-error" aria-invalid="true" aria-describedby={`${id}-error`} /> <span id={`${id}-error`} class="error-msg" aria-live="polite">{errorMessage}</span> </div> <style> .error-wrap { display: flex; flex-direction: column; gap: 0.4rem; width: 100%; box-sizing: border-box; } .input-error { border: 1px solid var(--c-error, #ef4444) !important; background: rgba(239, 68, 68, 0.05) !important; padding: var(--sp-3, 0.8rem); color: var(--c-text-1, #fff); border-radius: var(--r-sm, 10px); outline: none; font-family: inherit; font-size: 0.95rem; box-sizing: border-box; } .error-msg { font-size: 0.75rem; color: #f87171; font-weight: 500; } </style>

Información Rápida

Categoría
Formularios
Nombre de archivo
ErrorInput.astro
Dependencias
Ninguna — Astro nativo + CSS puro
Etiquetas
inputvalidation