# Input group

An input with addons on any side.

Source: https://www.zazz.sh/api/primitives/input-group/

## Installation

```bash
pnpm dlx zazz-ui add input-group
```

Also adds `fields`, `kbd`, `button`, `input`, `textarea`, which it depends on.

Run `zazz-ui init` first if the project has no `zazz/` folder yet.

## Examples

### Default

```html
<div data-ui="field">
  <label data-field-slot="label" for="f-search">Search</label>
  <label data-ui="input-group">
    <input
      data-ui="input"
      id="f-search"
      type="search"
      name="q"
      inputmode="search"
      placeholder="Search…"
      autocomplete="off"
      spellcheck="false"
      enterkeyhint="search"
      aria-describedby="f-search-hint"
    />
    <span data-input-group-slot="addon">
      <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 256 256">
        <rect width="256" height="256" fill="none" />
        <circle
          cx="112"
          cy="112"
          r="80"
          fill="none"
          stroke="currentColor"
          stroke-linecap="round"
          stroke-linejoin="round"
          stroke-width="16"
        />
        <line
          x1="168.57"
          y1="168.57"
          x2="224"
          y2="224"
          fill="none"
          stroke="currentColor"
          stroke-linecap="round"
          stroke-linejoin="round"
          stroke-width="16"
        />
      </svg>
    </span>
    <span data-input-group-slot="addon" data-input-group-align="inline-end">
      <button
        data-ui="button"
        data-button-variant="ghost"
        data-button-size="icon-sm"
        type="submit"
        aria-label="Submit search"
      >
        <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 256 256">
          <rect width="256" height="256" fill="none" />
          <line
            x1="40"
            y1="128"
            x2="216"
            y2="128"
            fill="none"
            stroke="currentColor"
            stroke-linecap="round"
            stroke-linejoin="round"
            stroke-width="16"
          />
          <polyline
            points="144 56 216 128 144 200"
            fill="none"
            stroke="currentColor"
            stroke-linecap="round"
            stroke-linejoin="round"
            stroke-width="16"
          />
        </svg>
      </button>
    </span>
  </label>
  <div data-field-slot="description">
    <span data-field-slot="hint" id="f-search-hint">Search across every page in the docs.</span>
  </div>
</div>

<div data-ui="field">
  <label data-field-slot="label" for="f-url">Website</label>
  <label data-ui="input-group">
    <input
      data-ui="input"
      id="f-url"
      type="url"
      name="url"
      inputmode="url"
      required
      placeholder="https://zazz.sh"
      autocomplete="url"
      autocapitalize="off"
      spellcheck="false"
      enterkeyhint="go"
      aria-describedby="f-url-hint"
    />
    <span data-input-group-slot="addon">
      <span data-input-group-slot="text">https://</span>
    </span>
    <span data-input-group-slot="addon" data-input-group-align="inline-end">
      <button data-ui="button" data-button-variant="primary" data-button-size="sm" type="submit">
        Apply
      </button>
    </span>
  </label>
  <div data-field-slot="description">
    <span data-field-slot="hint" id="f-url-hint">Where people can find you online.</span>
    <span data-field-slot="error" role="alert">Enter a valid URL, e.g. https://zazz.sh.</span>
  </div>
</div>

<div data-ui="field">
  <label data-field-slot="label" for="f-prompt">Prompt</label>
  <label data-ui="input-group">
    <textarea
      id="f-prompt"
      data-ui="textarea"
      name="prompt"
      inputmode="text"
      placeholder="Ask anything…"
      aria-describedby="f-prompt-hint"
    ></textarea>
    <span data-input-group-slot="addon" data-input-group-align="block-end">
      <button
        data-ui="button"
        data-button-size="sm"
        type="submit"
        style="
          --ml: auto;
          --bg: var(--color-background);
          --bg--active: var(--color-muted);
          --bg--hover: var(--color-muted);
        "
      >
        <span>Send</span> <kbd>↵</kbd>
      </button>
    </span>
  </label>
  <div data-field-slot="description">
    <span data-field-slot="hint" id="f-prompt-hint"
      >Enter to send · Shift + Enter for a new line.</span
    >
  </div>
</div>
```

### Password group

```html
<div data-ui="field">
  <label data-field-slot="label" for="f-login-password">Password</label>
  <ui-password>
    <label data-ui="password-group">
      <input
        data-ui="input"
        id="f-login-password"
        name="password"
        type="password"
        autocomplete="new-password"
        minlength="8"
        required
        placeholder="••••••••"
        aria-describedby="f-login-password-hint f-login-password-warning"
      />
      <span data-password-group-slot="addon" data-password-group-align="inline-end">
        <button
          data-ui="button"
          data-password-group-slot="toggle"
          id="f-login-password-toggle"
          data-button-variant="ghost"
          data-button-size="icon-sm"
          type="button"
          aria-pressed="false"
          aria-label="Show password"
          aria-describedby="f-login-password-warning"
        >
          <svg
            data-password-group-slot="icon icon-show"
            xmlns="http://www.w3.org/2000/svg"
            viewBox="0 0 256 256"
            aria-hidden="true"
          >
            <rect width="256" height="256" fill="none" />
            <path
              d="M128,56C48,56,16,128,16,128s32,72,112,72,112-72,112-72S208,56,128,56Z"
              fill="none"
              stroke="currentColor"
              stroke-linecap="round"
              stroke-linejoin="round"
              stroke-width="16"
            />
            <circle
              cx="128"
              cy="128"
              r="40"
              fill="none"
              stroke="currentColor"
              stroke-linecap="round"
              stroke-linejoin="round"
              stroke-width="16"
            />
          </svg>
          <svg
            data-password-group-slot="icon icon-hide"
            xmlns="http://www.w3.org/2000/svg"
            viewBox="0 0 256 256"
            aria-hidden="true"
          >
            <rect width="256" height="256" fill="none" />
            <line
              x1="48"
              y1="40"
              x2="208"
              y2="216"
              fill="none"
              stroke="currentColor"
              stroke-linecap="round"
              stroke-linejoin="round"
              stroke-width="16"
            />
            <path
              d="M154.9,157.6A40,40,0,0,1,101,98.4"
              fill="none"
              stroke="currentColor"
              stroke-linecap="round"
              stroke-linejoin="round"
              stroke-width="16"
            />
            <path
              d="M73.8,69.7C33.6,90.6,16,128,16,128s32,72,112,72a118.1,118.1,0,0,0,54.1-12.8"
              fill="none"
              stroke="currentColor"
              stroke-linecap="round"
              stroke-linejoin="round"
              stroke-width="16"
            />
            <path
              d="M208.6,169.1C229.8,149.1,240,128,240,128S208,56,128,56a126,126,0,0,0-20.5,1.6"
              fill="none"
              stroke="currentColor"
              stroke-linecap="round"
              stroke-linejoin="round"
              stroke-width="16"
            />
          </svg>
        </button>
      </span>
    </label>
  </ui-password>
  <div data-field-slot="description">
    <span data-field-slot="hint" id="f-login-password-hint">Use eight or more characters.</span>
    <span data-field-slot="error" role="alert">Password must be at least 8 characters.</span>
  </div>
  <span style="--sr: only" id="f-login-password-warning"
    >Warning: showing the password makes it visible to anyone near your screen.</span
  >
</div>
```

## Attributes

| Attribute | Kind | Values |
| --- | --- | --- |
| `data-ui="input-group"` | identity | free value |
| `data-input-group-align` | preset | `block-end` `block-start` `inline-end` `inline-start` |
| `data-input-group-slot` | slot | `addon` `text` |

Requires: fields, input, textarea, button.

## Hooks

| Hook | Default | State |
| --- | --- | --- |
| `--ui-input-group-cursor` | `text` | — |
| `--ui-input-group-display` | `flex` | — |
| `--ui-input-group-flex-wrap` | `wrap` | — |
| `--ui-input-group-font-size` | `var(--font-size-sm)` | — |
| `--ui-input-group-font-weight` | `var(--font-weight-strong)` | — |
| `--ui-input-group-gap` | `var(--spacing)` | — |
| `--ui-input-group-items` | `center` | — |
| `--ui-input-group-min-h` | `var(--ui-field-h)` | — |
| `--ui-input-group-p` | `0` | — |
| `--ui-input-group-shadow` | `0 0 transparent` | — |
| `--ui-input-group-text` | `var(--color-muted-foreground)` | — |
| `--ui-input-group-textarea-min-h` | `3lh` | — |
| `--ui-input-group-textarea-px` | `calc(var(--spacing) * 2)` | — |
| `--ui-input-group-textarea-py` | `calc(var(--spacing) * 1.5)` | — |
| `--ui-input-group-w` | `100%` | — |
