Live preview

Interactive example

Loading example…

Usage

Import the component and its manager, then make it your own.

ComponentTextInput
Managercreate_text_input_manager

svelte

<script>
  // Import the shared stylesheet once in your application's root layout.
  import "sveltekit-ui/style.css"
  import { TextInput, create_text_input_manager } from "sveltekit-ui"

  const manager = create_text_input_manager({
    label: "Email address",
    type: "email",
    name: "email",
    autocomplete: "email",
    placeholder: "you@example.com",
    is_required: true,
  })
</script>

<TextInput {manager} />
<p>Current value: {manager.val ?? ""}</p>

API reference

Configure the manager, call its methods, and read its reactive state.

42 entries in configuration

PropertyTypeDefaultDescription
typestring textDetermines the input field type. For multi-line input, specify `text_area`.
valany nullStarting value for the text field.
labelstring or null nullA text label displayed above or beside the input.
aria_labelstring or function nullAccessible name for an input or textarea without a visible label. Prefer a visible label when space allows.
placeholderstring varies by typeThe placeholder text for the input.
namestring textHTML input `name` attribute.
autocompletestring varies by typeHTML autocomplete attribute (e.g., `email`, `current-password`, `off`, etc.).
is_requiredboolean falseIf true, the input must have a value.
is_nullableboolean falseIf true, a Set Null button appears, allowing the value to become `null`.
is_disabledboolean falseIf true, the input is not editable.
error_messagestring or null nullDisplays an error message below the label if present.
replace_spaces_withstring or null nullIf set, replaces all spaces in input with this character/string.
is_numbers_onlyboolean falseIf true, removes all non-digits from the user input.
border_radiusnumber 1Applied as a rem value to style the input's rounded corners.
mlnumber 0Margin-left (rem).
mrnumber 0Margin-right (rem).
mtnumber 0Margin-top (rem).
mbnumber 0Margin-bottom (rem).
max_lengthnumber 100000Sets the maximum characters allowed in the input.
minnumber -9007199254740990The minimum numeric value if `type` = 'number'.
maxnumber 9007199254740990The maximum numeric value if `type` = 'number'.
is_show_limitboolean falseIf true, shows `length/max_length` at the bottom-right of the input.
password_min_lengthnumber 7Minimum password length if `type = 'password'`.
is_password_requires_lowercaseboolean trueRequires at least one lowercase letter for password validation.
is_password_requires_uppercaseboolean falseRequires at least one uppercase letter for password validation.
is_password_requires_numberboolean falseRequires at least one digit for password validation.
is_password_requires_special_charboolean falseRequires at least one special symbol for password validation.
is_password_tooltip_usedboolean trueIf true, shows a tooltip that describes password requirements.
is_text_hidableboolean varies by typeToggles if we can show a hide/unhide button (e.g. for password).
is_text_hiddenboolean varies by typeIf true, text is hidden (type='password').
is_preview_imgboolean falseIf true, tries to display a small image from the typed URL (when `type='url'`).
preview_img_sizenumber 32Size in px for the optional preview image if `is_preview_img` and type='url'.
is_resizableboolean falseIf true and `type='text_area'`, user can resize the textarea.
max_heightnumber 30Max height in rem for a textarea.
rowsnumber 5Number of visible text lines if `type='text_area'`.
is_popoverboolean falseIf true, renders inside a popover for editing. Otherwise, it's displayed inline.
popover_headerstring or null nullWhen `is_popover=true`, sets the popover's header text.
update_button_textstring or null nullIf set, changes the popover's final button text from 'Finish' to a custom label.
is_popover_edit_contentboolean falseIf true, displays the label/value inline, with a small edit button that opens the popover. Otherwise, the input is always visible inline or in the popover.
on_changefunction or null —Callback triggered on each input event, receiving the updated value.
on_blurfunction or null —Callback triggered on input blur.
on_finishfunction or null —If `is_popover=true`, called when pressing the final button in the popover. Receives the current value. Return `{ is_success: boolean, message?: string }` for success or error feedback.