# TextArrayInput — SvelteKit UI

Package: sveltekit-ui 1.1.94

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

Category: Input controls

Builds an input for managing an array of text items. The user enters a string in a text field and clicks a button to add it to the array. They can reorder items (shift them up or down) or delete them. Optionally displayed in a popover when `is_popover` is true.

Public component import: `TextArrayInput`

Public manager import: `create_text_array_input_manager`

## Usage

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

  const manager = create_text_array_input_manager({
    label: "Project tags",
    placeholder: "Add a tag",
    val: ["svelte", "design"],
    max_length: 24,
  })
</script>

<TextArrayInput {manager} />
<p>Tags: {(manager.val ?? []).join(", ")}</p>
```

## Configuration

### `val`

- type: array of strings or null
- default: null
- description: The initial list of text items.

### `label`

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

### `placeholder`

- type: string or null
- default: null
- description: Placeholder text for the single-line input used when adding new items.

### `is_no_spaces`

- type: boolean
- default: false
- description: If true, replaces spaces with nothing (like a no-space validator).

### `max_length`

- type: number
- default: 255
- description: Maximum length allowed per item in the array.

### `is_disabled`

- type: boolean
- default: false
- description: If true, prevents adding or removing items, shifting them, etc.

### `ml`

- type: number
- default: 0
- description: Margin left in rem.

### `mr`

- type: number
- default: 0
- description: Margin right in rem.

### `mt`

- type: number
- default: 0
- description: Margin top in rem.

### `mb`

- type: number
- default: 0
- description: Margin bottom in rem.

### `border_radius`

- type: number
- default: 1
- description: Border radius (in rem) for the added item containers.

### `is_popover`

- type: boolean
- default: false
- description: If true, the text array input is displayed inside a popover. Otherwise, it's shown inline.

### `header`

- type: string
- default: Text Array Input
- description: Popover header text if `is_popover` is true.

### `on_change`

- type: function or null
- description: Callback triggered whenever the array changes (items added, removed, or shifted). Receives the updated array.

### `on_finish`

- type: function or null
- description: Called when the user finalizes (clicks 'Finish' if in a popover). Receives the final array.

## Methods

### `init()`

- description: Initializes state and managers. Called once with the config.

### `set_val()`

- description: Sets the entire array of text items programmatically.

### `add_item()`

- description: Adds the current text from `input_text_manager.val` to the array (if valid).

### `delete_item()`

- description: Removes the item at a given index.

### `shift_item()`

- description: Reorders items by moving one item up or down (the `shift_by` can be -1 or +1).

### `finish()`

- description: Closes the popover (if used) and calls `on_finish` with the final array.

## Returned state

### `val`

- type: array of strings or null
- description: The current list of items. Updated whenever items are added, deleted, or shifted.

### `input_text_manager`

- type: object
- description: The text input manager for the single-line text field used to add items.

### `add_button_manager`

- type: object
- description: Button manager for the 'add item' button.

### `val_prepped`

- type: array of objects
- description: Metadata for each existing item in the array, including reorder and delete button managers.

### `popover_manager`

- type: object
- description: If `is_popover` is true, controls the popover. You can open or close it with `manager.popover_manager.open()` or `manager.popover_manager.close()`.

### `finish_button_manager`

- type: object
- description: Button manager for the 'Finish' button (only relevant when `is_popover` is true).
