# Text Field

> A labelled input with an optional hint and error message.

```tsx
import { TextField } from '@brand-studio/ui';

export default function TextFieldDemo() {
  return (
    <div style={{ width: '100%', maxWidth: 360 }}>
      <TextField label="Email" type="email" placeholder="you@example.com" hint="We only use it for your receipt." />
    </div>
  );
}
```

## Installation

```sh
npm install @brand-studio/ui
```

React 18 or 19 is a peer dependency. Import the stylesheet once and wrap the app in a brand theme:

```tsx
import '@brand-studio/ui/styles.css';
import { BrandTheme, TextField } from '@brand-studio/ui';
import brand from './brand.json';

<BrandTheme palette={brand.tokens} mode="system">
  {/* your app */}
</BrandTheme>
```

## Usage

```tsx
import { TextField } from '@brand-studio/ui';
```

```tsx
<TextField label="Email" type="email" hint="We only use it for your receipt." />
```

## Examples

### Error

An error sets `aria-invalid` and joins the message to `aria-describedby`.

```tsx
import { TextField } from '@brand-studio/ui';

export default function TextFieldError() {
  return (
    <div style={{ width: '100%', maxWidth: 360 }}>
      <TextField label="Postcode" defaultValue="12" error="Enter a full postcode, such as SW1A 1AA." />
    </div>
  );
}
```

## Accessibility

- The label is always visible and linked to the input.
- Hint and error ids are added to any `aria-describedby` you pass, not swapped for it.

## API Reference

| Prop | Type | Default |
|---|---|---|
| `label` | `string` | – |
| `hint?` | `string` | – |
| `error?` | `string` | – |

Source: https://brandstudio.js.org/docs/components/text-field/
