# TextInput — SvelteKit UI

Package: sveltekit-ui 1.1.94

Page: https://www.sveltekit-ui.com/components/text_input

Category: Input controls

Builds an input (single or multi-line) with support for validations, placeholders, error messaging, toggling password visibility, optional popover editing, and more.

Public component import: `TextInput`

Public manager import: `create_text_input_manager`

## Usage

```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>
```

## Configuration

### `type`

- type: string
- default: text
- allowed_values:
  - text
  - text_area
  - email
  - password
  - number
  - tel
  - url
  - search
- description: Determines the input field type. For multi-line input, specify `text_area`.

### `val`

- type: any
- default: null
- description: Starting value for the text field.

### `label`

- type: string or null
- default: null
- description: A text label displayed above or beside the input.

### `aria_label`

- type: string or function
- default: null
- description: Accessible name for an input or textarea without a visible label. Prefer a visible label when space allows.

### `placeholder`

- type: string
- default: varies by type
- description: The placeholder text for the input.

### `name`

- type: string
- default: text
- description: HTML input `name` attribute.

### `autocomplete`

- type: string
- default: varies by type
- description: HTML autocomplete attribute (e.g., `email`, `current-password`, `off`, etc.).

### `is_required`

- type: boolean
- default: false
- description: If true, the input must have a value.

### `is_nullable`

- type: boolean
- default: false
- description: If true, a Set Null button appears, allowing the value to become `null`.

### `is_disabled`

- type: boolean
- default: false
- description: If true, the input is not editable.

### `error_message`

- type: string or null
- default: null
- description: Displays an error message below the label if present.

### `replace_spaces_with`

- type: string or null
- default: null
- description: If set, replaces all spaces in input with this character/string.

### `is_numbers_only`

- type: boolean
- default: false
- description: If true, removes all non-digits from the user input.

### `border_radius`

- type: number
- default: 1
- description: Applied as a rem value to style the input's rounded corners.

### `ml`

- type: number
- default: 0
- description: Margin-left (rem).

### `mr`

- type: number
- default: 0
- description: Margin-right (rem).

### `mt`

- type: number
- default: 0
- description: Margin-top (rem).

### `mb`

- type: number
- default: 0
- description: Margin-bottom (rem).

### `max_length`

- type: number
- default: 100000
- description: Sets the maximum characters allowed in the input.

### `min`

- type: number
- default: -9007199254740990
- description: The minimum numeric value if `type` = 'number'.

### `max`

- type: number
- default: 9007199254740990
- description: The maximum numeric value if `type` = 'number'.

### `is_show_limit`

- type: boolean
- default: false
- description: If true, shows `length/max_length` at the bottom-right of the input.

### `password_min_length`

- type: number
- default: 7
- description: Minimum password length if `type = 'password'`.

### `is_password_requires_lowercase`

- type: boolean
- default: true
- description: Requires at least one lowercase letter for password validation.

### `is_password_requires_uppercase`

- type: boolean
- default: false
- description: Requires at least one uppercase letter for password validation.

### `is_password_requires_number`

- type: boolean
- default: false
- description: Requires at least one digit for password validation.

### `is_password_requires_special_char`

- type: boolean
- default: false
- description: Requires at least one special symbol for password validation.

### `is_password_tooltip_used`

- type: boolean
- default: true
- description: If true, shows a tooltip that describes password requirements.

### `is_text_hidable`

- type: boolean
- default: varies by type
- description: Toggles if we can show a hide/unhide button (e.g. for password).

### `is_text_hidden`

- type: boolean
- default: varies by type
- description: If true, text is hidden (type='password').

### `is_preview_img`

- type: boolean
- default: false
- description: If true, tries to display a small image from the typed URL (when `type='url'`).

### `preview_img_size`

- type: number
- default: 32
- description: Size in px for the optional preview image if `is_preview_img` and type='url'.

### `is_resizable`

- type: boolean
- default: false
- description: If true and `type='text_area'`, user can resize the textarea.

### `max_height`

- type: number
- default: 30
- description: Max height in rem for a textarea.

### `rows`

- type: number
- default: 5
- description: Number of visible text lines if `type='text_area'`.

### `is_popover`

- type: boolean
- default: false
- description: If true, renders inside a popover for editing. Otherwise, it's displayed inline.

### `popover_header`

- type: string or null
- default: null
- description: When `is_popover=true`, sets the popover's header text.

### `update_button_text`

- type: string or null
- default: null
- description: If set, changes the popover's final button text from 'Finish' to a custom label.

### `is_popover_edit_content`

- type: boolean
- default: false
- description: If 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_change`

- type: function or null
- description: Callback triggered on each input event, receiving the updated value.

### `on_blur`

- type: function or null
- description: Callback triggered on input blur.

### `on_finish`

- type: function or null
- description: 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.

## Methods

### `init()`

- description: Initializes the internal states and managers, called once with the config.

### `set_val()`

- description: Sets the input value from outside the component, re-running validations. Syntax: `manager.set_val(newValue)`.

### `set_focus()`

- description: Focuses the input element if not disabled.

### `set_type()`

- description: Changes the input type dynamically and resets text visibility to that type's default (for example, password inputs become hidden).

### `set_is_text_hidden()`

- description: Toggles hiding or showing the text if `is_text_hidable = true` (e.g. for password fields).

## Returned state

### `val`

- type: any
- description: The current input value.

### `error_message`

- type: string or null
- description: If set, shows an error message. Also toggled by validations (e.g., password or URL).

### `is_valid`

- type: boolean
- description: A boolean indicating if the input passes basic validation (URL, password, email checks, etc.).

### `is_image_url`

- type: boolean
- description: If `is_preview_img = true`, indicates whether the current value is a valid image URL.

### `popover_manager`

- type: object
- description: Controls the popover if `is_popover = true`.

### `popover_edit_button_manager`

- type: object
- description: Displays an edit button if `is_popover_edit_content = true` to open the popover.

### `finish_button_manager`

- type: object
- description: Button manager for the popover's final 'Finish' or update button.

### `set_null_button_manager`

- type: object
- description: If `is_nullable = true`, provides a 'Set Null' button manager to quickly clear the input.
