Skip to content

The open alternative to Salesforce, designed for AI.

4.7 KB
Raw Blame
---
title: Input
description: A text input with native attributes, field integration, and two sizes.
---

import { PageBanner } from "/snippets/page-banner.mdx"

import { StoryEmbed } from '/snippets/ui/StoryEmbed.mdx';
import InputReference from '/snippets/ui/generated/input/input.mdx';

## Overview

`Input` renders a text input and accepts native input attributes such as `type`, `name`, `required`, `disabled`, and `autoComplete`.

<StoryEmbed
  storyId="ui-input-input--display"
  title="Input example"
  height={140}
/>

## Usage

### Uncontrolled state

Use `defaultValue` to set the initial email address. The input owns subsequent changes.

```tsx
import { Field, Input } from 'twenty-ui/primitives/input';

export const EmailField = () => (
  <Field.Root>
    <Field.Label>Email</Field.Label>
    <Input
      name="email"
      type="email"
      autoComplete="email"
      defaultValue="[email protected]"
    />
    <Field.Description>Use your work email address.</Field.Description>
  </Field.Root>
);
```

## Visual choices

Compare small and medium inputs in their default, focused, invalid, and disabled states. Use validation feedback alongside invalid styling.

<StoryEmbed
  storyId="ui-input-input--catalog"
  title="Visual choices for input"
  height={380}
/>

## Plain appearance

Use `variant="plain"` inside an existing row or surface. It removes the fill, border, rounded corners and padding and uses natural height. The parent supplies spacing and row dimensions. Text, placeholder and disabled styling remain shared. The blue outline follows the browser's native `:focus-visible` behavior. For text controls this can include pointer focus and autofocus as well as keyboard focus. Invalid state uses a danger outline without changing layout.

```tsx
import { Field, Input } from 'twenty-ui/primitives/input';

export const InlineSubject = () => (
  <Field.Root>
    <Field.Label>Subject</Field.Label>
    <Input variant="plain" placeholder="Add a subject" />
  </Field.Root>
);
```

`InputGroup` automatically gives its input the plain appearance and keeps the group as the only focus and validation frame. Its `sm` and `md` heights remain 24px and 32px. Standalone plain inputs do not use the fixed height associated with `size`.

## Controlled state

Pass `value` and update it with `onValueChange` to own the same email address in React state. The callback receives the next string value and event details.

```tsx
import { useState } from 'react';
import { Field, Input } from 'twenty-ui/primitives/input';

export const EmailField = () => {
  const [email, setEmail] = useState('[email protected]');

  return (
    <Field.Root>
      <Field.Label>Email</Field.Label>
      <Input
        name="email"
        type="email"
        autoComplete="email"
        value={email}
        onValueChange={setEmail}
      />
      <Field.Description>Use your work email address.</Field.Description>
    </Field.Root>
  );
};
```

## Add an adornment

`InputGroup` owns the surrounding border and layout height. Input size resolves from the explicit child `size`, then the group default, then `md`. The grouped input stretches within the shared border, so use the group's `size` to change the overall field height.

```tsx
import { IconSearch } from 'twenty-ui/icon';
import { Input, InputGroup } from 'twenty-ui/primitives/input';

export const CompactSearch = () => (
  <InputGroup size="sm" startElement={<IconSearch size={16} aria-hidden />}>
    <Input aria-label="Search contacts" />
  </InputGroup>
);
```

## Native control and wrapper customization

Native attributes, handlers, `className`, `style`, and `ref` target the input. The ref receives an `HTMLInputElement`. Use `render` to compose another input component and forward the supplied props and ref to its native input.

`onChange` receives a React change event for the native input. `onValueChange(value, details)` receives the next string and Base UI event details, including `event`, `reason`, `cancel`, and `allowPropagation`. The event targets the input. Canceling the details preserves Base UI's validation policy; it does not undo a native edit. Controlled callers decide which value to commit.

Put layout styles, attributes, and refs on `InputGroup` when customizing the surrounding wrapper. The group owns no value. Native `name`, `form`, `required`, `readOnly`, `disabled`, submission, and reset behavior remain on the input, with Field naming and validation supplied through `Field.Root`.

## Props

The reference includes component-specific and inherited Base UI props. Native input attributes are also accepted. A standalone input defaults to `md`; inside a group, an omitted input `size` inherits the group's size.

<InputReference />

<PageBanner illustration="page-cover-input" />