# AI field

A one-line field for asking about what the agent did, with a still gradient rim and the send button inset as far from the edge as from the top and bottom.

Tier: free. Type: component. Category: inputs. Tags: agent, chat.

## Install

```bash
npx shadcn@latest add https://pixilui.com/r/ai-field.json
```

One-time setup: add the registry to `components.json`:

```json
{
  "registries": {
    "@pixilui": "https://pixilui.com/r/{name}.json"
  }
}
```

Files: `components/pixilui/ai-field.tsx`.

## Preview

Live preview: https://pixilui.com/components/ai-field

Knobs:

- `size`: `xl`, `lg`, `md`

Signature: The gradient rim sits still at rest, from the focus blue through the running and waiting hues, so the field reads as AI without moving.

Styles: `lively` (default), `quiet`, set with `data-style` on <html>. The item reads the style through the foundation; it needs no prop. Standalone files: lively https://pixilui.com/r/standalone/ai-field.tsx, quiet https://pixilui.com/r/standalone/ai-field.quiet.tsx.

## Code

`components/pixilui/ai-field.tsx`

```tsx
"use client";

/*
  The AI field, locked 1 Dec 2026 (design/explorations/components/locked/inputs, B8): ask a question about
  what the agent did. The frame is the Field's (../field/field); the look is foundation.css section 8.

  Rim       lively: a still gradient rim, focus blue through the running and waiting hues, fully there at
            rest (no motion, no glow). Quiet: the plain rim, and the focus ring on focus.
  Send      a round action inside the field, as far from the right edge as from the top and bottom.
            Enter sends too, never in the middle of composing (Japanese, Chinese input).
  Typing    native: nothing animates on keys.
*/

import { forwardRef, useImperativeHandle, useRef, useState, type ChangeEvent, type ComponentPropsWithoutRef, type KeyboardEvent, type ReactNode } from "react";
import { cn } from "./lib/utils";
import { Field, FieldControl, FieldInput, FieldPrefix, FieldSuffix, type FieldSize } from "./field";

export type AiFieldProps = Omit<ComponentPropsWithoutRef<"input">, "size" | "prefix" | "onSubmit"> & {
  /** The label above the field ("Ask about these runs"). */
  label?: ReactNode;
  /** The icon before the text (the animated ai icon). */
  icon?: ReactNode;
  /** The send button's icon (the animated send-stop icon). */
  sendIcon: ReactNode;
  /** The send button's name. */
  sendLabel?: string;
  /** Runs with the trimmed question on Enter or the send button. Nothing runs for an empty field. */
  onSubmit?: (question: string) => void;
  /** The button height of the same name; xl (44) by default, as the locked page shows it. */
  size?: FieldSize;
  /** Classes for the field. Native attributes and the ref go to the input. */
  className?: string;
};

/** A field for asking about the agent's work, with a still gradient rim and a send inside it. */
export const AiField = forwardRef<HTMLInputElement, AiFieldProps>(function AiField(
  { label, icon, sendIcon, sendLabel = "Ask", onSubmit, size = "xl", className, value, defaultValue, onChange, onKeyDown, id, ...props },
  ref,
) {
  const input = useRef<HTMLInputElement | null>(null);
  useImperativeHandle(ref, () => input.current!, []);
  const [inner, setInner] = useState(String(defaultValue ?? ""));
  const current = value != null ? String(value) : inner;
  const send = () => {
    const q = (input.current?.value ?? current).trim();
    if (q) onSubmit?.(q);
  };
  return (
    <Field className={className} label={label} glow="ai" size={size} filled={current.length > 0} inputId={id}>
      <FieldControl>
        {icon != null ? <FieldPrefix>{icon}</FieldPrefix> : null}
        <FieldInput
          ref={input}
          type="text"
          value={value}
          defaultValue={defaultValue}
          onChange={(event: ChangeEvent<HTMLInputElement>) => {
            if (value == null) setInner(event.target.value);
            onChange?.(event);
          }}
          onKeyDown={(event: KeyboardEvent<HTMLInputElement>) => {
            onKeyDown?.(event);
            if (event.defaultPrevented || event.nativeEvent.isComposing || event.key !== "Enter") return;
            event.preventDefault();
            send();
          }}
          {...props}
        />
        <FieldSuffix>
          {/* the send: the accent disc with the light icon, as the locked page draws it (inputs.page.css .in-send) */}
          <button type="button" aria-label={sendLabel} onClick={send} className={cn("pixilui-field-action cursor-pointer rounded-full bg-accent-solid text-accent-contrast [&_svg]:size-4")}>
            {sendIcon}
          </button>
        </FieldSuffix>
      </FieldControl>
    </Field>
  );
});
```

## Usage

When to use:

- Asking a question about runs, a table or a trace, in a page header or a panel.

When not to use:

- A full chat composer with attachments: use the composer.

```tsx
import { useState } from "react";
import { IconAi } from "@/components/pixilui/icons/ai";
import { IconSendStop } from "@/components/pixilui/icons/send-stop";
import { AiField } from "@/components/pixilui/ai-field";

// The first option of each knob is the demo's default; the docs preview starts there.
export const knobs = {
  size: ["xl", "lg", "md"],
} as const;

/** A question about today's runs; the last one asked shows under it. */
export default function AiFieldDemo({ size = "xl" }: KnobValues<typeof knobs>) {
  const [asked, setAsked] = useState<string | null>(null);
  return (
    <div className="flex w-full max-w-md flex-col gap-3">
      <AiField label="Ask about these runs" icon={<IconAi />} sendIcon={<IconSendStop />} placeholder="Why did three refunds fail today?" onSubmit={setAsked} size={size} />
      <p className="type-caption text-muted">{asked ? `Asked: ${asked}` : "Nothing asked yet"}</p>
    </div>
  );
}
```

## Examples

None.

## API

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `className` | `string` |  | Classes for the field. Native attributes and the ref go to the input. |
| `label` | `ReactNode` |  | The label above the field ("Ask about these runs"). |
| `icon` | `ReactNode` |  | The icon before the text (the animated ai icon). |
| `sendIcon` (required) | `ReactNode` |  | The send button's icon (the animated send-stop icon). |
| `sendLabel` | `string` | `"Ask"` | The send button's name. |
| `onSubmit` | `(question: string) => void` |  | Runs with the trimmed question on Enter or the send button. Nothing runs for an empty field. |
| `size` | `FieldSize` | `"xl"` | The button height of the same name; xl (44) by default, as the locked page shows it. |

Also accepts every native `<input>` attribute except `size`, `prefix`, `onSubmit`, and a ref to it.

## Keyboard

- `Enter`: Sends the question, never in the middle of composing.

## Accessibility

- The send button is labelled (sendLabel, "Ask").

## Motion

- None of its own: the rim is still, by design. Quiet keeps the plain rim and the focus ring.

## Responsive

- Fills its container's width; the label row and the message wrap.

## Performance

- Native typing: nothing renders per key beyond the value; the look is CSS in the foundation (section 8).

## Notes for AI

- <AiField label="Ask about these runs" icon={<IconAi />} sendIcon={<IconSendStop />} onSubmit={ask} />.
- Defaults to the xl size (44).

## Related

- [Input](https://pixilui.com/components/input/markdown): A text field with its label, help and error, a unit or icon on either side, and a rule that checks on blur and Enter and says what's wrong in plain words.
- [Search field](https://pixilui.com/components/search-field/markdown): A search field with its ⌘K hint at rest, a clear button once there is text, Esc to clear, and Enter that never fires mid-composition.
