skip section navigation

Input

Input wraps a native input or textarea with Loafkit’s focus treatment and optional icon. label the actual control, bind its value, and keep validation with the app that knows what the value means.

pick a title you will spot in your reading list.

usage

svelte
<script>
	import { Field, FieldLabel, FieldDescription, Input } from '@ciabi/loafkit-ui';
	let title = $state('');
	let touched = $state(false);
	let invalid = $derived(touched && !title.trim());
</script>

<Field>
	<FieldLabel htmlFor="article-title">Article title</FieldLabel>
	<Input id="article-title" name="title" bind:value={title} required
		aria-describedby="article-title-help" aria-invalid={invalid}
		onValueBlur={() => touched = true} placeholder="The balcony garden" />
	<FieldDescription id="article-title-help">
		{invalid ? 'add a title so you can find it later.' : 'pick a title you will spot in your reading list.'}
	</FieldDescription>
</Field>

values and events

the callbacks receive native events, not bare values. use event.currentTarget.value when you need the entered text.

Input forwards this explicit list rather than arbitrary attributes. use Field, FieldLabel and FieldDescription for composition. native required handles required-value validity; your app still owns submission, server errors and saved data.

write a longer note

svelte
<script lang="ts">
import { Input, Field, FieldLabel } from '@ciabi/loafkit-ui';
let longNote = $state('mint needs its own pot.');
let savedLongNote = $state('');
</script>

<Field><FieldLabel htmlFor="input-long-note">garden note</FieldLabel>
	<Input id="input-long-note" multiline bind:value={longNote} placeholder="what do you want to remember?" />
</Field>
<button type="button" disabled={!longNote.trim()} onclick={() => savedLongNote = longNote}>keep note</button>
{#if savedLongNote}<p role="status">kept: {savedLongNote}</p>{/if}

a leading icon

create SearchMark.svelte beside your example:

svelte
<span aria-hidden="true">⌕</span>
svelte
<script lang="ts">
	import { Input, Field, FieldLabel } from '@ciabi/loafkit-ui';
	import SearchMark from './SearchMark.svelte';
	let searchTerm = $state('');
</script>

<Field>
	<FieldLabel htmlFor="article-search">find an article</FieldLabel>
	<Input id="article-search" placeholder="title or topic" Icon={SearchMark} bind:value={searchTerm} />
</Field>

API reference

Input

Component
placeholder

suggested content shown when empty; not a label.

value
Default: ''

the bindable native control value.

Icon
Default: null

optional leading Svelte icon.

width
Default: '100%'

CSS width for the wrapper.

minWidth
Default: '0'

CSS minimum width for the wrapper.

id
Default: null

unique ID used by the component and its control relationships.

type
Default: 'text'

native input type when multiline is false.

multiline
Default: false

uses a four-row textarea instead of an input.

name

the native form field name.

autocomplete

native autocomplete hint.

disabled
Default: false

makes the control unavailable.

required
Default: false

uses native required-value validation.

inputMode

native keyboard input-mode hint.

min

native minimum value.

max

native maximum value.

step

native value increment.

spellcheck

native spelling-check preference.

minLength

native minimum text length.

maxLength

native maximum text length.

aria-label

an explicit accessible name.

aria-describedby

IDs of supporting descriptions.

aria-invalid

explicit native invalid state; validation belongs to your app.

onValueInput

receives the native input event.

onValueBlur

receives the native blur event.

class
Default: ''

extra classes on the input wrapper.

style

inline styles on the input wrapper.