> For the complete documentation index, see [llms.txt](https://docs.rierino.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.rierino.com/sdk-core-ui/components/text-field.md). Agents can also search and read this documentation through its [MCP server](https://docs.rierino.com/~gitbook/mcp).

# TextField

Lets people type a single line or several lines of text.

{% code title="text-field/demo.tsx" %}

```tsx
import { useState } from "react";
import { TextField } from "@rierino-open/core-ui";

export default function TextFieldDemo() {
  const [name, setName] = useState("");

  return (
    <div style={{ width: 280 }}>
      <TextField
        aria-label="Product name"
        placeholder="Product name"
        value={name}
        onChange={(e) => setName(e.target.value)}
      />
    </div>
  );
}
```

{% endcode %}

## Usage

{% tabs %}
{% tab title="React app" %}

```tsx
import { TextField } from '@rierino-open/core-ui';

<TextField
  aria-label="Product name"
  value={name}
  onChange={(e) => setName(e.target.value)}
/>
```

{% endtab %}

{% tab title="Hosted editor" %}

```jsx
import CoreUI from '@rierino-open/core-ui';
const { TextField } = CoreUI;

<TextField
  aria-label="Product name"
  value={name}
  onChange={(e) => setName(e.target.value)}
/>
```

{% endtab %}
{% endtabs %}

Unlike most Core UI components, `onChange` receives the **DOM change event**, not the new value. Read the text from `e.target.value`.

## Examples

### Controlled and uncontrolled

Pass `value` and `onChange` to keep the text in your own state. To let the field manage its own value, pass `initialValue` instead and read the value when you need it, for example on blur.

{% code title="text-field/controlled.tsx" %}

```tsx
import { useState } from "react";
import { TextField } from "@rierino-open/core-ui";

export default function TextFieldControlled() {
  const [title, setTitle] = useState("Summer collection");

  return (
    <div style={{ display: "grid", gap: 12, width: 280 }}>
      {/* Controlled: the value lives in state and is updated from onChange. */}
      <TextField aria-label="Title" value={title} onChange={(e) => setTitle(e.target.value)} />
      <span style={{ fontSize: 12 }}>Value: {title}</span>

      {/* Uncontrolled: the field keeps its own value, starting from initialValue. */}
      <TextField aria-label="Notes" initialValue="Starts with this text" />
    </div>
  );
}
```

{% endcode %}

### Input types

`type` sets the HTML input type, so the browser offers the matching keyboard, masking or validation. The value is always a string, including for `type="number"`.

{% code title="text-field/types.tsx" %}

```tsx
import { TextField } from "@rierino-open/core-ui";

export default function TextFieldTypes() {
  return (
    <div style={{ display: "grid", gap: 12, width: 280 }}>
      <TextField aria-label="Email" type="email" placeholder="name@example.com" />
      <TextField aria-label="Password" type="password" placeholder="Password" />
      <TextField aria-label="Quantity" type="number" placeholder="Quantity" />
    </div>
  );
}
```

{% endcode %}

### Adornments

`InputProps.startAdornment` and `InputProps.endAdornment` place content inside the border, before and after the text: an icon, a unit or a button. The field doesn't pad adornments, so give them a margin.

{% code title="text-field/adornments.tsx" %}

```tsx
import { TextField } from "@rierino-open/core-ui";
import { Search } from "lucide-react";

export default function TextFieldAdornments() {
  return (
    <div style={{ display: "grid", gap: 12, width: 280 }}>
      <TextField
        aria-label="Search"
        placeholder="Search products"
        InputProps={{
          startAdornment: <Search size={16} style={{ marginLeft: 12, color: "#8F97AE" }} />,
        }}
      />
      <TextField
        aria-label="Weight"
        type="number"
        initialValue={12}
        InputProps={{
          endAdornment: <span style={{ marginRight: 12, fontSize: 11, color: "#8F97AE" }}>kg</span>,
        }}
      />
    </div>
  );
}
```

{% endcode %}

### Multiline

`multiline` renders a `<textarea>`. `rows` sets its height in lines. The text area doesn't resize or grow as people type.

{% code title="text-field/multiline.tsx" %}

```tsx
import { TextField } from "@rierino-open/core-ui";

export default function TextFieldMultiline() {
  return (
    <div style={{ width: 360 }}>
      <TextField
        aria-label="Description"
        multiline
        rows={4}
        initialValue="Lightweight linen shirt with a relaxed fit."
      />
    </div>
  );
}
```

{% endcode %}

{% hint style="warning" %}
**No placeholder on multiline fields**

`placeholder` is only passed to single-line fields. A multiline field ignores it.
{% endhint %}

### Validation

TextField doesn't validate the text itself. Check the value yourself, set `isInvalid`, and show your own message next to the field. The border turns red while the field is invalid.

{% code title="text-field/validation.tsx" %}

```tsx
import { useState } from "react";
import { TextField } from "@rierino-open/core-ui";

export default function TextFieldValidation() {
  const [email, setEmail] = useState("ada@");
  const isInvalid = email !== "" && !/^[^@\s]+@[^@\s]+\.[^@\s]+$/.test(email);

  return (
    <div style={{ display: "grid", gap: 6, width: 280 }}>
      <TextField
        aria-label="Email"
        type="email"
        value={email}
        isInvalid={isInvalid}
        onChange={(e) => setEmail(e.target.value)}
      />
      {isInvalid && <span style={{ fontSize: 11, color: "#EB475A" }}>Enter a valid email address.</span>}
    </div>
  );
}
```

{% endcode %}

### Disabled

{% code title="text-field/disabled.tsx" %}

```tsx
import { TextField } from "@rierino-open/core-ui";

export default function TextFieldDisabled() {
  return (
    <div style={{ width: 280 }}>
      <TextField aria-label="Product ID" initialValue="PRD-10482" isDisabled />
    </div>
  );
}
```

{% endcode %}

### Acting on Enter

Use `onKeyDown` to act on a key, such as applying a search on `Enter`. Call `e.preventDefault()` so the key doesn't also submit a surrounding form.

{% code title="text-field/keyboard.tsx" %}

```tsx
import { useState } from "react";
import { TextField } from "@rierino-open/core-ui";

export default function TextFieldKeyboard() {
  const [query, setQuery] = useState("");
  const [applied, setApplied] = useState("");

  return (
    <div style={{ display: "grid", gap: 12, width: 280 }}>
      <TextField
        aria-label="Search"
        placeholder="Type and press Enter"
        value={query}
        onChange={(e) => setQuery(e.target.value)}
        onKeyDown={(e) => {
          if (e.key === "Enter") {
            e.preventDefault();
            setApplied(query);
          }
        }}
      />
      <span style={{ fontSize: 12 }}>Searching for: {applied || "nothing yet"}</span>
    </div>
  );
}
```

{% endcode %}

## Accessibility

* **Give every field a label.** TextField has no visible label of its own. Pass `aria-label`, or point `aria-labelledby` at the element that labels it. A placeholder is not a label: it disappears once people start typing.
* Renders a native `<input>` (or `<textarea>`), so keyboard editing, autofill and screen reader support work as usual.
* `isDisabled` disables the input: it can't be focused, edited or submitted with a form.
* `isInvalid` only changes the border colour. Show an error message as text too, so the problem isn't communicated by colour alone.

## Styling

The field is two elements: a wrapper that draws the border (`className` goes here, and it carries the `Rie-textfield` class), and the input inside it (`Rie-input`).

| Attribute           | On      | Present when                  |
| ------------------- | ------- | ----------------------------- |
| `data-focus-within` | Wrapper | The input has focus           |
| `data-hovered`      | Wrapper | The pointer is over the field |
| `data-invalid`      | Wrapper | `isInvalid` is set            |
| `data-disabled`     | Wrapper | `isDisabled` is set           |

The border colours come from [theme variables](https://docs.rierino.com/sdk-core-ui/foundations/colors.md#theme-variables): `--border-color` at rest, `--border-color-focus` while focused, `--border-color-invalid` when invalid and `--border-color-disabled` when disabled. To change the text inside, target the input:

```css
.Rie-Search-field .Rie-input {
  font-size: 13px;
}
```

## API reference

| Prop           | Type                                                                    | Default  | Description                                                                                 |
| -------------- | ----------------------------------------------------------------------- | -------- | ------------------------------------------------------------------------------------------- |
| `className`    | `string`                                                                |          | Classes added to the field's wrapper, which draws the border.                               |
| `type`         | `React.HTMLInputTypeAttribute`                                          | `"text"` | The input type, such as `text`, `password`, `email` or `number`. Ignored when `multiline`.  |
| `value`        | `string \| number \| readonly string[]`                                 |          | The current value, for a controlled field. Update it from `onChange`.                       |
| `initialValue` | `string \| number \| readonly string[]`                                 |          | The starting value, for an uncontrolled field.                                              |
| `placeholder`  | `string`                                                                |          | Hint text shown while the field is empty. Single-line fields only.                          |
| `isDisabled`   | `boolean`                                                               |          | Whether the field is disabled: it can't be focused or edited, and is dimmed.                |
| `InputProps`   | `{ startAdornment?: React.ReactNode; endAdornment?: React.ReactNode; }` |          | Content shown inside the border, before and after the input, such as an icon or a unit.     |
| `isInvalid`    | `boolean`                                                               |          | Whether the value is invalid. Shows the border in `--border-color-invalid`.                 |
| `autoFocus`    | `boolean`                                                               | `false`  | Whether the field is focused when it first renders.                                         |
| `onChange`     | `React.ChangeEventHandler<HTMLInputElement \| HTMLTextAreaElement>`     |          | Called on every change, with the DOM change event. Read the text from `event.target.value`. |
| `onKeyDown`    | `React.KeyboardEventHandler<HTMLInputElement \| HTMLTextAreaElement>`   |          | Called on every key press in the field, for example to act on Enter.                        |
| `onBlur`       | `React.FocusEventHandler<HTMLInputElement \| HTMLTextAreaElement>`      |          | Called when the field loses focus.                                                          |
| `onFocus`      | `React.FocusEventHandler<HTMLInputElement \| HTMLTextAreaElement>`      |          | Called when the field receives focus.                                                       |
| `rows`         | `number`                                                                |          | The number of visible text lines when `multiline`.                                          |
| `multiline`    | `boolean`                                                               |          | Renders a `<textarea>` instead of an `<input>`, for longer text.                            |
| `aria-label`   | `string`                                                                |          | Labels the field for screen readers. TextField has no visible label of its own.             |

TextField also accepts the native attributes of `<input>`, such as `name`, `id`, `maxLength`, `autoComplete` and `aria-*`, and passes them to the input (or the textarea when `multiline`). Use `isDisabled` and `initialValue` instead of `disabled` and `defaultValue`.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.rierino.com/sdk-core-ui/components/text-field.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
