# Input editors: text, textarea, OTP, duration, multi-select

The Tier-1 editors on the shared contract: SvTextInput, SvTextArea (auto-grow + counter), SvOtpInput (segmented code, paste-distribute), SvDurationInput ("1h 30m" <-> minutes) and SvMultiSelect (portalled checkbox dropdown with search + chips). Standalone or as grid cell editors.

Uses `@svgrid/grid` (MIT). Category: Inputs. Live demo: https://svgrid.com/demos/334-input-editors/

Install: `npm i @svgrid/grid` (Svelte 5).

## About this example

The tier-one input editors of the SvGrid UI kit in Svelte 5 on the shared editor contract: SvTextInput with a clear button, SvTextArea with auto-grow and a character counter against maxlength, SvOtpInput as a segmented code field that distributes a pasted code and fires onComplete, SvDurationInput converting text such as 1h 30m to minutes, and SvMultiSelect as a portalled checkbox dropdown with search and chips capped by maxTagCount. Each is standalone and a grid cell editor.

The Tier-1 input editors: SvTextInput, SvTextArea, SvOtpInput, SvDurationInput and SvMultiSelect. Each is a standalone control on the shared editor contract (label / hint / error / a11y) that also works as a SvGrid cell editor via the interaction contract.

## Imports, features and API used

- Imports: `@svgrid/grid`

## Frequently asked questions

### How does the OTP input handle paste?

Pasting a full code into any box distributes the characters across the segments and fires onComplete with the value; typing moves focus forward and Backspace moves it back.

### What does SvDurationInput store?

A number of minutes. The units style accepts and displays text such as 1h 30m, so users type naturally while your state holds an integer.

### How does the multi-select show many values?

Selected options render as chips; maxTagCount limits how many are shown before a +N summary, and the dropdown keeps checkboxes with a search box.

## Related documentation

- [SvDurationInput](https://svgrid.com/docs/help/ui-components/sv-duration-input.md)
- [SvMultiSelect](https://svgrid.com/docs/help/ui-components/sv-multi-select.md)
- [SvOtpInput](https://svgrid.com/docs/help/ui-components/sv-otp-input.md)
- [SvTextArea](https://svgrid.com/docs/help/ui-components/sv-text-area.md)
- [SvTextInput](https://svgrid.com/docs/help/ui-components/sv-text-input.md)

## Related articles

- [What to Look for in a Svelte 5 UI Component Library](https://svgrid.com/blog/svelte-ui-component-library-what-to-look-for/) - A practical comparison of shadcn-svelte, Skeleton, Flowbite-Svelte, Bits UI, Melt UI, and SvGrid UI - covering Svelte 5 runes support, headless cores, accessibility, theming, and install models.

## Source code (334-input-editors.svelte)

```svelte
<script lang="ts">
  /**
   * The Tier-1 input editors: SvTextInput, SvTextArea, SvOtpInput,
   * SvDurationInput and SvMultiSelect. Each is a standalone control on the shared
   * editor contract (label / hint / error / a11y) that also works as a SvGrid
   * cell editor via the interaction contract.
   */
  import {
    SvTextInput, SvTextArea, SvOtpInput, SvDurationInput, SvMultiSelect,
    type MultiSelectOption,
  } from '@svgrid/grid'

  let name = $state('Ada Lovelace')
  let email = $state('')
  let bio = $state('')
  let code = $state('')
  let minutes = $state<number | null>(90)
  let tags = $state<Array<string | number>>(['svelte', 'grid'])

  const tagOptions: MultiSelectOption[] = [
    { value: 'svelte', label: 'Svelte' },
    { value: 'grid', label: 'Data grid' },
    { value: 'ts', label: 'TypeScript' },
    { value: 'a11y', label: 'Accessibility' },
    { value: 'charts', label: 'Charts' },
    { value: 'forms', label: 'Forms' },
  ]
</script>

<div class="wrap">
  <header>
    <h2>Input editors</h2>
    <p>Standalone controls that double as grid cell editors: Enter commits, Escape cancels, all themed from the grid's <code>--sg-*</code> tokens.</p>
  </header>

  <section>
    <h3>Text &amp; textarea</h3>
    <div class="row">
      <SvTextInput label="Name" value={name} onChange={(v) => (name = v)} clearable />
      <SvTextInput label="Email" type="email" value={email} onChange={(v) => (email = v)} placeholder="you@example.com" />
    </div>
    <SvTextArea label="Bio" value={bio} onChange={(v) => (bio = v)} rows={3} maxlength={140} showCount autoGrow placeholder="A short bio…" />
  </section>

  <section>
    <h3>OTP &amp; duration</h3>
    <div class="row">
      <div>
        <div class="lbl">Verification code</div>
        <SvOtpInput length={6} value={code} onChange={(v) => (code = v)} onComplete={(v) => console.log('code', v)} />
      </div>
      <SvDurationInput label="Estimate" value={minutes} onChange={(m) => (minutes = m)} style="units" />
    </div>
  </section>

  <section>
    <h3>Multi-select</h3>
    <SvMultiSelect label="Topics" options={tagOptions} value={tags} onChange={(v) => (tags = v)} maxTagCount={3} />
    <p class="muted">Selected: {tags.join(', ') || '(none)'}</p>
  </section>
</div>

<style>
  .wrap { padding: 20px; max-width: 820px; display: flex; flex-direction: column; gap: 22px; }
  header h2 { margin: 0 0 4px; font-size: 20px; font-weight: 700; }
  header p { margin: 0; color: var(--sg-muted, #64748b); font-size: 13.5px; line-height: 1.5; }
  header code { background: var(--sg-row-hover-bg, #f1f5f9); padding: 1px 5px; border-radius: 4px; font-size: 12px; }
  section h3 { margin: 0 0 12px; font-size: 13px; text-transform: uppercase; letter-spacing: 0.03em; color: var(--sg-muted, #64748b); }
  .row { display: flex; gap: 18px; flex-wrap: wrap; align-items: flex-start; margin-bottom: 12px; }
  .lbl { font-size: 12.5px; font-weight: 600; color: var(--sg-fg, #0f172a); margin-bottom: 5px; }
  .muted { color: var(--sg-muted, #94a3b8); font-size: 12.5px; margin: 10px 0 0; }
</style>
```

[View this example on GitHub](https://github.com/sv-grid/sv-grid/blob/main/examples/src/demos/334-input-editors.svelte)
