icon

Morainev0.5.0

Input
formsinput

Input

Text input component with icon slots, loading state, and form field integration.

Import#

import { Input } from 'moraine'

Slot Structure#

Text input shell with optional leading and trailing icon slots.

root
├── leading (optional)
├── input
└── trailing (optional)

Examples#

Variants#

Visual style variants.

function InputVariants() {
const VARIANTS = ['outline', 'subtle', 'ghost', 'none'] as const
return (
<div class="gap-3 grid lg:grid-cols-3 sm:grid-cols-2">
<For each={VARIANTS}>{(variant) => <Input variant={variant} placeholder={variant} />}</For>
</div>
)
}

Sizes#

From xs to xl.

function InputSizes() {
const SIZES = ['xs', 'sm', 'md', 'lg', 'xl'] as const
return (
<div class="gap-3 grid lg:grid-cols-3 sm:grid-cols-2">
<For each={SIZES}>{(size) => <Input size={size} placeholder={`Size: ${size}`} />}</For>
</div>
)
}

With Icons#

Leading and trailing icon slots.

function InputWithIcons() {
return (
<div class="gap-3 grid sm:grid-cols-2">
<Input
leading="i-lucide-search"
placeholder="Search..."
classes={{ leading: 'bg-muted p-3' }}
/>
<Input leading="i-lucide-mail" trailing="i-lucide-check" placeholder="Email" />
<Input
trailing={<span class="text-xs text-muted-foreground/80">.com</span>}
placeholder="Domain"
/>
<Input
leading={
<div class="text-muted-foreground flex gap-1 items-center">
<Icon name="i-lucide-globe" />
https://
</div>
}
placeholder="website.com"
classes={{
input: 'ps-0',
}}
/>
</div>
)
}

States#

Loading, disabled, and type.

function InputStates() {
return (
<div class="gap-3 grid sm:grid-cols-2">
<Input loading placeholder="Loading..." />
<Input disabled placeholder="Disabled" value="Cannot edit" />
<Input type="file" />
<Input type="datetime-local" />
</div>
)
}

API Reference#

Attributes#

Slotroot0 attributes
Input wrapper that positions icons, loading state, and the native input.
No attribute metadata for this slot.

Props#

PropTypeDefaultDescription
autocompleteJSX.InputHTMLAttributes<HTMLInputElement>["autocomplete"] | undefinedoff
The autocomplete attribute for the input.
autofocusboolean | undefinedfalse
Whether the input should automatically receive focus on mount.
autofocusDelaynumber | undefined0
The delay in milliseconds before automatically focusing the input.
childrenJSX.Element
Additional content to render inside the input container.
classClassValue
Class applied to the component root or trigger element.
classesInputT.Classes | undefined
defaultValueInputT.Value
The default value of the input (uncontrolled).
disabledboolean | undefinedfalse
Whether the input is disabled.
idstring | undefined
The ID of the input element.
leadingIconT.Name
Leading icon name.
loadingboolean | undefinedfalse
Whether the input is in a loading state.
loadingIconIconT.Nameicon-loading
The icon to show when the input is in a loading state.
maxLengthstring | number | undefined
The maximum number of characters allowed in the input.
modelModifiersM | undefined
Modifiers for the input value (e.g., trim, lazy, number).
namestring | undefined
The name of the input element, used for form submission.
onBlurJSX.FocusEventHandlerUnion<HTMLInputElement, FocusEvent> | undefined
Event handler for the blur event.
onChange((value: ModifierValue<M>) => void) | undefined
Callback when the input value change is committed.
onFocusJSX.FocusEventHandlerUnion<HTMLInputElement, FocusEvent> | undefined
Event handler for the focus event.
onInputJSX.InputEventHandlerUnion<HTMLInputElement, InputEvent> | undefined
Event handler for the input event.
onValueChange((value: ModifierValue<M>) => void) | undefined
Callback when the input value changes during input.
placeholderstring | undefined
The placeholder text for the input.
readOnlyboolean | undefinedfalse
Whether the input is read-only.
refJSX.HTMLElementTags["div"] extends { ref?: infer Ref; } ? Ref : never | undefined
requiredboolean | undefinedfalse
Whether the input is required.
size"xs" | "sm" | "md" | "lg" | "xl" | undefined
styleJSX.CSSProperties | undefined
stylesInputT.Styles | undefined
trailingIconT.Name
Trailing icon name.
typeJSX.InputHTMLAttributes<HTMLInputElement>["type"] | undefinedtext
The type of the input element.
valueInputT.Value
The current value of the input (controlled).
variant"none" | "outline" | "ghost" | "subtle" | undefined