Textfield component

The kit:textfield component provides a versatile input solution for capturing user data. It supports various input types, validation states, and enhanced features like character counting and clearable functionality. Designed for i increase accessibility and user experience in mind in your interphase.

Instead of reinventing textfield logic, Lapikit Textfield enables you to focus on behavior and data flow.

textfield.svelte

kit:textfield wraps a native <input> inside a styled container. It uses a grid layout to slot prepend/append (outside the field) and prependInner/appendInner (inside the field border). The value prop is bindable.

Examples of textfield

Variants

Shows visual variants of the textfield: outlined, filled, or text to match different design systems and UI contexts.

  • filled (default): solid background.

  • outline: visible border.

  • text : transparent background.

  • variant: 'filled' | 'outline' | 'text' = 'filled'

textfield.svelte

message and error

Show helper text or validation errors below the field. The message is visible on focus unless persistentMessage is set.

  • message: string => Helper text shown below the field.
  • errorMessage: string => Message shown when error is true.
  • error: boolean => Activates the error state (red border + message).
  • persistentMessage: boolean => Always shows the message (not only on focus).
  • counter: string => Shows character count. Use with max for limit.
  • max: string => Maximum character count.
textfield.svelte

prependInner and appendInner

Place icons or buttons inside the field border using the prependInner and appendInner snippets.

  • prependInner: Snippet | undefined = undefined => Content inside the field, before the input.
  • appendInner: Snippet | undefined = undefined => Content inside the field, after the input.
  • prepend: Snippet | undefined = undefined => Content outside the field, before it.
  • append: Snippet | undefined = undefined => Content outside the field, after it.
textfield.svelte

clearable

Adds a clear button that appears when the field has a value.

  • clearable: boolean = false
  • persistentClear: boolean = false
textfield.svelte

Without preprocess Lapikit

If you aren’t using the Lapikit preprocessor in svelte.config.js, import the components directly:

API Reference

kit:textfield

propstypedescriptiondefault
valuestring | numberInput value. Bindable.
typeenum'text''email''password''number'Input type.'text'
placeholderstringPlaceholder text.
variantenum'filled''outline''text'Visual style.'filled'
sizeenum'xs''sm''md''lg''xl'Field size.'md'
densityenum'compact''default''comfortable'Padding density.'default'
roundedenum0'xs''sm''md''lg''xl'Border radius.'md'
errorbooleanActivates error state.false
errorMessagestringMessage shown when error is true.
messagestringHelper text below the field.
messagePrefixstringLeading text in the message row.
messageSuffixstringTrailing text in the message row.
persistentMessagebooleanAlways shows the message, not only on focus.false
counterbooleanShows character counter.false
minnumberMinimum character count.
maxnumberMaximum character count.
clearablebooleanShows a clear button when the field has a value.false
persistentClearbooleanAlways shows the clear button.false
disabledbooleanDisables the input.false
readonlybooleanMakes the input read-only.false
hideSpinButtonsbooleanHides the spin buttons on type="number" inputs.false
prefixstringStatic text before the input value.
suffixstringStatic text after the input value.
namestringInput name attribute.
idstringInput id attribute.
autocompletestringInput autocomplete attribute.
inputmodestringInput inputmode attribute.
colorstringForeground color override (--kit-textfield-fg).
backgroundstringBackground color override (--kit-textfield-bg).
prependSnippetContent outside the field, before it.
appendSnippetContent outside the field, after it.
prependInnerSnippetContent inside the field border, before the input.
appendInnerSnippetContent inside the field border, after the input.

kit:textfield works great with Form validation and can be enhanced with Icons and Buttons using snippets.