# Input

> A single-line text input that takes its label and validation from Field.

```tsx title="hero.tsx"
import { Field, FieldDescription, FieldLabel } from '@langgenius/dify-ui/field'
import { Input } from '@langgenius/dify-ui/input'

export function InputHeroDemo() {
  return (
    <Field name="appName" className="w-full max-w-80">
      <FieldLabel>App name</FieldLabel>
      <Input placeholder="e.g. Customer support bot" autoComplete="off" />
      <FieldDescription>Shown in the app list and on the published WebApp.</FieldDescription>
    </Field>
  )
}
```

## Usage guidelines

- Use `Input` for one line of free text. Multiline text uses `Textarea`, numbers with steppers use `NumberField`, secrets use `PasswordField`, and a prefix, suffix or inline action that shares the input surface uses `InputGroup`.
- Put the input in a [`Field`](/components/field.md) with a `FieldLabel`. The field owns the label, `FieldDescription` and `FieldError` relationships and the `name` the value submits under.
- Use `aria-label` only when the layout has no place for a visible label, such as a search box in a toolbar. A `placeholder` shows an example value and is never the name.
- Inputs that save together belong in a real form boundary: [`Form`](/components/form.md) or a native `<form>`, with a `Button` of `type="submit"`. Keep the submit button enabled while the form is incomplete; submitting runs validation.
- Set the native attributes that describe the value: `type`, `autoComplete`, `inputMode` and `spellCheck={false}` for URLs, emails and identifiers.
- `Input` has a single size. Use `disabled` for a value the user cannot change now, and `readOnly` for a value that can be selected and copied but not edited.

## Anatomy

```tsx
import { Field, FieldDescription, FieldError, FieldLabel } from '@langgenius/dify-ui/field'
import { Input } from '@langgenius/dify-ui/input'
```

```tsx
<Field>
  <FieldLabel />
  <Input />
  <FieldDescription />
  <FieldError />
</Field>
```

## Examples

### States

Set `invalid` on the `Field` when application code owns the validity, and render `<FieldError match>` while it is invalid; editing the URL to include `https://` clears the error. `disabled` on the `Field` disables the label and the input together. A read-only input keeps its focus ring so keyboard users can reach and copy the value.

```tsx title="states.tsx"
import { Field, FieldError, FieldLabel } from '@langgenius/dify-ui/field'
import { Input } from '@langgenius/dify-ui/input'
import * as React from 'react'

function isValidHttpsUrl(value: string) {
  try {
    const url = new URL(value.trim())
    return url.protocol === 'https:' && Boolean(url.hostname)
  } catch {
    return false
  }
}

export function InputStatesDemo() {
  const [repositoryUrl, setRepositoryUrl] = React.useState('github.com/langgenius')
  const invalidUrl = !isValidHttpsUrl(repositoryUrl)

  return (
    <div className="grid w-full max-w-80 gap-3">
      <Field name="knowledgeBaseName">
        <FieldLabel>Knowledge base name</FieldLabel>
        <Input placeholder="e.g. Product FAQ…" autoComplete="off" />
      </Field>
      <Field name="repositoryUrl" invalid={invalidUrl}>
        <FieldLabel>Repository URL</FieldLabel>
        <Input
          type="url"
          placeholder="https://github.com/langgenius/dify"
          value={repositoryUrl}
          onValueChange={setRepositoryUrl}
          autoCapitalize="none"
          autoComplete="off"
          autoCorrect="off"
          spellCheck={false}
        />
        {invalidUrl && <FieldError match>Enter a full URL including https://.</FieldError>}
      </Field>
      <Field name="apiEndpoint">
        <FieldLabel>API endpoint</FieldLabel>
        <Input
          readOnly
          defaultValue="https://api.dify.ai/v1"
          placeholder="https://api.example.com/v1"
        />
      </Field>
      <Field name="workspaceOwner" disabled>
        <FieldLabel>Workspace owner</FieldLabel>
        <Input defaultValue="owner@example.com" placeholder="name@company.com" />
      </Field>
    </div>
  )
}
```

### Validation in a form

Native constraints such as `required` and `type="url"` drive `FieldError`. Each `match` value names the validity state its message covers. Submit the empty form to see the messages; after a submit, they update as the value changes.

```tsx title="validation.tsx"
import { Button } from '@langgenius/dify-ui/button'
import { Field, FieldDescription, FieldError, FieldLabel } from '@langgenius/dify-ui/field'
import { Form } from '@langgenius/dify-ui/form'
import { Input } from '@langgenius/dify-ui/input'
import * as React from 'react'

type WebhookSettingsValues = {
  webhookUrl: string
  notifyEmail: string
}

export function InputValidationDemo() {
  const [saved, setSaved] = React.useState(false)

  return (
    <Form<WebhookSettingsValues>
      aria-label="Webhook settings"
      className="grid w-full max-w-80 gap-4"
      onChange={() => {
        if (saved) setSaved(false)
      }}
      onFormSubmit={() => setSaved(true)}
    >
      <Field name="webhookUrl">
        <FieldLabel>Webhook URL</FieldLabel>
        <Input
          type="url"
          required
          autoCapitalize="none"
          autoComplete="off"
          autoCorrect="off"
          placeholder="https://example.com/hooks/dify"
          spellCheck={false}
        />
        <FieldDescription>Receives a POST request when a workflow run finishes.</FieldDescription>
        <FieldError match="valueMissing">Webhook URL is required.</FieldError>
        <FieldError match="typeMismatch">
          Enter a valid URL, such as https://example.com/hooks/dify.
        </FieldError>
      </Field>
      <Field name="notifyEmail">
        <FieldLabel>Notification email</FieldLabel>
        <Input
          type="email"
          placeholder="name@company.com"
          autoCapitalize="none"
          autoComplete="email"
          autoCorrect="off"
          spellCheck={false}
        />
        <FieldError match="typeMismatch">Enter a valid email address.</FieldError>
      </Field>
      <div className="flex items-center justify-between gap-3">
        <span role="status" className="min-w-0 truncate system-xs-regular text-text-success">
          {saved ? 'Webhook settings saved' : ''}
        </span>
        <Button type="submit" variant="primary" className="shrink-0">
          Save
        </Button>
      </div>
    </Form>
  )
}
```

### Without a visible label

A search box in a toolbar sits next to the title of the list it filters, so it has no room for a label of its own. It takes `aria-label` instead; the placeholder alone would not name it. The `<search>` element around it marks the search landmark.

```tsx title="toolbar-search.tsx"
import { Input } from '@langgenius/dify-ui/input'
import * as React from 'react'

const apps = [
  { name: 'Customer support bot', mode: 'Chatflow' },
  { name: 'Release notes writer', mode: 'Workflow' },
  { name: 'Contract reviewer', mode: 'Workflow' },
  { name: 'SQL query assistant', mode: 'Agent' },
] as const

export function InputToolbarSearchDemo() {
  const [query, setQuery] = React.useState('')
  const normalized = query.trim().toLowerCase()
  const filtered = normalized
    ? apps.filter(
        (app) =>
          app.name.toLowerCase().includes(normalized) ||
          app.mode.toLowerCase().includes(normalized),
      )
    : apps

  return (
    <div className="flex w-full max-w-sm flex-col gap-3">
      <div className="flex items-center justify-between gap-3">
        <p className="shrink-0 system-md-semibold text-text-primary">Apps</p>
        <search className="w-full max-w-48">
          <Input
            type="search"
            aria-label="Search apps"
            placeholder="e.g. Agent"
            value={query}
            onValueChange={setQuery}
            autoCapitalize="none"
            autoComplete="off"
            autoCorrect="off"
            enterKeyHint="search"
            spellCheck={false}
          />
        </search>
      </div>
      {filtered.length > 0 ? (
        <ul className="divide-y divide-divider-subtle">
          {filtered.map((app) => (
            <li key={app.name} className="flex items-center justify-between gap-3 py-2">
              <span className="min-w-0 truncate system-sm-medium text-text-primary">
                {app.name}
              </span>
              <span className="shrink-0 system-xs-regular text-text-tertiary">{app.mode}</span>
            </li>
          ))}
        </ul>
      ) : (
        <p className="py-3 text-center system-xs-regular text-text-tertiary">No matching apps.</p>
      )}
    </div>
  )
}
```

## API reference

### Input

A standalone single-line text input that integrates with `Field`. Renders an `<input>` element.

Use `InputGroup` with `InputGroupInput` when the field needs a prefix, suffix, or inline action.

Inherits `className`, `render`, `style`, `onValueChange`, `defaultValue`, `value` from [Base UI Input](https://base-ui.com/react/components/input).

**Data attributes**

| Attribute       | Description                                                                 |
| --------------- | --------------------------------------------------------------------------- |
| `data-disabled` | Present when the input is disabled.                                         |
| `data-valid`    | Present when the input is in a valid state (when wrapped in Field.Root).    |
| `data-invalid`  | Present when the input is in an invalid state (when wrapped in Field.Root). |
| `data-touched`  | Present when the input has been touched (when wrapped in Field.Root).       |
| `data-dirty`    | Present when the input's value has changed (when wrapped in Field.Root).    |
| `data-filled`   | Present when the input is filled (when wrapped in Field.Root).              |
| `data-focused`  | Present when the input is focused (when wrapped in Field.Root).             |
