Input

The Input component provides a styled text input with support for validation, labels, and helper text.

Installation

npm install @duskmoon-dev/el-input

Usage

import '@duskmoon-dev/el-input/register';
<el-dm-input label="Email" placeholder="Enter your email"></el-dm-input>

Live Demo

Input Examples

Properties

PropertyTypeDefaultDescription
valuestring''Input value
labelstring''Label text
placeholderstring''Placeholder text
type'text' | 'email' | 'password' | 'number' | 'tel' | 'url''text'Input type
disabledbooleanfalseDisables the input
readonlybooleanfalseMakes input read-only
requiredbooleanfalseMarks as required
errorstring''Error message to display
helperstring''Helper text below input

Basic Examples

With Label

<el-dm-input label="Username" placeholder="Enter username"></el-dm-input>

With Helper Text

<el-dm-input
  label="Password"
  type="password"
  helper="Must be at least 8 characters"
></el-dm-input>

With Error

Input with Error State

<el-dm-input
  label="Email"
  type="email"
  value="invalid-email"
  error="Please enter a valid email address"
></el-dm-input>

Input Types

Text

<el-dm-input type="text" label="Name"></el-dm-input>

Email

<el-dm-input type="email" label="Email"></el-dm-input>

Password

<el-dm-input type="password" label="Password"></el-dm-input>

Number

<el-dm-input type="number" label="Quantity"></el-dm-input>

States

Disabled

Disabled Input

<el-dm-input label="Disabled" disabled value="Cannot edit"></el-dm-input>

Read-only

Read-only Input

<el-dm-input label="Read-only" readonly value="View only"></el-dm-input>

Required

<el-dm-input label="Required Field" required></el-dm-input>

Events

EventDescription
inputFired when the value changes
changeFired when the value changes and input loses focus
focusFired when the input receives focus
blurFired when the input loses focus

Event Handling

const input = document.querySelector('el-dm-input');
input.addEventListener('input', (event) => {
  console.log('Value:', event.target.value);
});

CSS Custom Properties

PropertyDefaultDescription
--input-padding-x0.75remHorizontal padding
--input-padding-y0.5remVertical padding
--input-border-radius0.375remBorder radius
--input-border-colorvar(--color-outline)Border color
--input-focus-colorvar(--color-primary)Focus ring color
--input-error-colorvar(--color-error)Error state color

Accessibility

  • Labels are properly associated with inputs
  • Error messages are announced to screen readers
  • Focus states are clearly visible
  • Required fields are indicated with aria-required