# Form Layout

A neutral responsive grid for form-related content.

`FormLayout` arranges form-related content with a responsive CSS Grid. It does not manage labels, errors, field state, validation, parsing, or submission.

```tsx
import { Button, Field, FormLayout, Input, Select, Text, Textarea } from "@zentara-co/zenos-ui";
import { type SubmitEvent, useState } from "react";

function FormExample() {
  const [created, setCreated] = useState(false);

  return (
    <FormLayout
      as="form"
      columns={{ base: 1, md: 2 }}
      gap="4"
      className="w-full max-w-2xl"
      onSubmit={(event: SubmitEvent<HTMLFormElement>) => {
        event.preventDefault();
        setCreated(true);
      }}
    >
      <Field.Root required>
        <Field.Label>Project name</Field.Label>
        <Field.Control
          render={<Input name="projectName" placeholder="Security workspace" autoComplete="off" />}
        />
        <Field.Description>Use a name your team will recognize.</Field.Description>
      </Field.Root>
      <Field.Root>
        <Field.Label>Region</Field.Label>
        <Select.Root defaultValue="singapore">
          <Select.Trigger aria-label="Region">
            <Select.Value />
          </Select.Trigger>
          <Select.Content>
            <Select.Item value="singapore">Singapore</Select.Item>
            <Select.Item value="frankfurt">Frankfurt</Select.Item>
          </Select.Content>
        </Select.Root>
      </Field.Root>
      <Field.Root className="md:col-span-2">
        <Field.Label>Notes</Field.Label>
        <Field.Control render={<Textarea placeholder="Deployment context" />} />
      </Field.Root>
      <Button type="submit" variant="primary">
        Create project
      </Button>
      <Text aria-live="polite" color="success" className="self-center">
        {created ? "Project created locally." : ""}
      </Text>
    </FormLayout>
  );
}
```

## Import

```tsx
import { FormLayout } from "@zentara-co/zenos-ui";
```

## Responsive columns

`columns` accepts the shared responsive value shape. Start with one column so controls remain usable on narrow screens, then add columns as space permits.

```tsx
import { Field, FormLayout, Input } from "@zentara-co/zenos-ui";

function FormLayoutColumnsExample() {
  return (
    <FormLayout
      columns={{ base: 1, md: 2, lg: 3 }}
      gap="4"
      className="w-full rounded-xl border border-border bg-background-neutral-card p-4"
    >
      {[
        ["Project name", "Security workspace"],
        ["Owner", "Platform team"],
        ["Environment", "Production"],
      ].map(([label, value]) => (
        <Field.Root key={label}>
          <Field.Label>{label}</Field.Label>
          <Field.Control render={<Input defaultValue={value} />} />
        </Field.Root>
      ))}
    </FormLayout>
  );
}
```

## Row and column gaps

`gap` sets both axes. Use `rowGap` and `columnGap` when vertical form rhythm should differ from spacing between columns. Axis-specific values override the corresponding part of `gap`.

```tsx
import { Field, FormLayout, Input } from "@zentara-co/zenos-ui";

function FormLayoutGapExample() {
  return (
    <FormLayout
      columns={{ base: 1, md: 2 }}
      gap="2"
      rowGap={{ base: "4", md: "8" }}
      columnGap={{ base: "2", md: "6" }}
      className="w-full rounded-xl border border-border bg-background-neutral-card p-4"
    >
      <Field.Root>
        <Field.Label>First name</Field.Label>
        <Field.Control render={<Input defaultValue="Alex" />} />
      </Field.Root>
      <Field.Root>
        <Field.Label>Last name</Field.Label>
        <Field.Control render={<Input defaultValue="Morgan" />} />
      </Field.Root>
      <Field.Root className="md:col-span-2">
        <Field.Label>Role</Field.Label>
        <Field.Control render={<Input defaultValue="Security engineer" />} />
        <Field.Description>
          This field spans both columns while FormLayout continues to own the grid.
        </Field.Description>
      </Field.Root>
    </FormLayout>
  );
}
```

Children can span tracks through application-specific `className` when the form needs a full-width field. FormLayout intentionally does not expose a field-item abstraction.

## Semantic element

FormLayout renders a `div` by default. Use `as="form"` when it owns native form submission, or `as="fieldset"` when it groups related controls inside another form.

```tsx
import { Checkbox, FormLayout, Label, Text } from "@zentara-co/zenos-ui";

function FormLayoutSemanticExample() {
  return (
    <FormLayout
      as="fieldset"
      columns={{ base: 1, md: 2 }}
      gap="4"
      className="w-full rounded-xl border border-border bg-background-neutral-card p-5"
    >
      <Text as="legend" type="heading" size="h6" className="px-1">
        Notification preferences
      </Text>
      <Label className="flex items-center gap-3">
        <Checkbox defaultChecked />
        Security findings
      </Label>
      <Label className="flex items-center gap-3">
        <Checkbox />
        Workspace activity
      </Label>
    </FormLayout>
  );
}
```

Native props follow the selected element. A form accepts `action`, `method`, and `onSubmit`; a fieldset accepts `disabled`, `name`, and its native grouping semantics.

## Alignment

Use `align` to position items within their grid tracks and `justify` to distribute the grid's content. Both accept responsive values. Most forms should keep the defaults so fields stretch consistently; change alignment only when mixed-size controls require it.

## API

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| as | ElementType | div | Rendered semantic element, including form, fieldset, or div. |
| columns | Responsive<1 \| 2 \| ... \| 12> | 1 | Responsive grid column count. |
| gap | Responsive<Spacing> | 4 | Shared row and column gap. |
| rowGap / columnGap | Responsive<Spacing> | — | Axis-specific gap overrides. |
| align | Responsive<start \| center \| end \| stretch \| baseline> | — | Item alignment within grid tracks. |
| justify | Responsive<start \| center \| end \| between \| around \| evenly> | — | Grid content distribution on the inline axis. |
| native props | React.HTMLAttributes<HTMLElement> | — | Forwards native attributes, events, aria-*, data-*, className, style, and ref. |

Unless narrowed above, each DOM-rendering part also accepts its underlying native or Base UI props, including className, style, aria-*, and data-*.

## Responsibility

Compose FormLayout with Field for label, description, error, required, invalid, and disabled semantics. Inputs remain responsible for native control behavior. Form libraries such as React Hook Form or TanStack Form can provide state without changing the layout API.

## Accessibility

Responsive columns must preserve DOM order and a logical keyboard sequence. Avoid visual placement classes that make the reading order differ from the source. Use a real `form` only when the region submits data, and give each `fieldset` a concise `legend`. FormLayout forwards refs, native attributes, `className`, `style`, `aria-*`, and `data-*`.

Source: https://zenos-ui.pages.dev/layout/form-layout/