Dokumentation (english)
Components: Shadcn UI

Field

Understand the design system and contribute to it

Component preview

The live preview for UI components is handled by components/atoms/codedocs/ComponentPreview.tsx. Use it directly inside MDX whenever you want a playground-style embed. Provide componentProps to set default values and propOptions to surface toggle-able props next to the preview.

Preview
Project metadata

Visible to everyone in the workspace.

Notifications
Daily summaries

Send a summary email every morning.

Slack alerts

Send deployment alerts to the #ops channel.

Prop reference

Auto-generated from the component source

Field

  • className
  • orientation = "vertical"

React.ComponentProps<"div"> & VariantProps<typeof fieldVariants>

FieldContent

  • className

React.ComponentProps<"div">

FieldDescription

  • className

React.ComponentProps<"p">

FieldError

  • className
  • children
  • errors

React.ComponentProps<"div"> & { errors?: Array<{ message?: string; } | undefined>; }

FieldGroup

  • className

React.ComponentProps<"div">

FieldLabel

  • className

React.ComponentProps<typeof Label>

FieldLegend

  • className
  • variant = "legend"

React.ComponentProps<"legend"> & { variant?: "legend" | "label"; }

FieldSeparator

  • children
  • className

React.ComponentProps<"div"> & { children?: React.ReactNode; }

FieldSet

  • className

React.ComponentProps<"fieldset">

FieldTitle

  • className

React.ComponentProps<"div">

Code
// owner: Sona
"use client";

import { Button } from "@/components/ui/button";
import {
  Field,
  FieldContent,
  FieldDescription,
  FieldError,
  FieldGroup,
  FieldLabel,
  FieldLegend,
  FieldSeparator,
  FieldSet,
  FieldTitle,
} from "@/components/ui/field";
import { Input } from "@/components/ui/input";
import { Switch } from "@/components/ui/switch";

export default function FieldExample() {
  return (
    <FieldSet>
      <FieldLegend>Project metadata</FieldLegend>
      <FieldGroup>
        <Field>
          <FieldLabel htmlFor="name">Name</FieldLabel>
          <FieldContent>
            <Input id="name" defaultValue="Automation" />
            <FieldDescription>
              Visible to everyone in the workspace.
            </FieldDescription>
          </FieldContent>
        </Field>
        <Field>
          <FieldLabel htmlFor="slug">Slug</FieldLabel>
          <FieldContent>
            <Input id="slug" defaultValue="automation" />
            <FieldError errors={[{ message: "Slug already taken" }]} />
          </FieldContent>
        </Field>
      </FieldGroup>
      <FieldSeparator>Notifications</FieldSeparator>
      <FieldGroup>
        <Field orientation="horizontal">
          <FieldTitle>Daily summaries</FieldTitle>
          <FieldContent>
            <Switch defaultChecked />
            <FieldDescription>
              Send a summary email every morning.
            </FieldDescription>
          </FieldContent>
        </Field>
        <Field orientation="horizontal">
          <FieldTitle>Slack alerts</FieldTitle>
          <FieldContent>
            <Switch />
            <FieldDescription>
              Send deployment alerts to the #ops channel.
            </FieldDescription>
          </FieldContent>
        </Field>
      </FieldGroup>
      <Button className="w-fit">Save changes</Button>
    </FieldSet>
  );
}

On this page


Command Palette

Search for a command to run...

Schnellzugriffe
STRG + KSuche
STRG + DNachtmodus / Tagmodus
STRG + LSprache ändern

Software-Details
Kompiliert vor 15 Tagen
Release: v4.0.0-production
Buildnummer: master@6fbd7b5
Historie: 13 Items