Saltar al contenido
SevenOne

Buscar en la documentación

Busca páginas y componentes

Field

Une etiqueta, control, descripción y error. La etiqueta va 8px arriba del control y la descripción 8px debajo, todo con texto de 16px.

Instalación

npx shadcn@latest add @sevenone/field

Uso

import {
  Field,
  FieldContent,
  FieldDescription,
  FieldError,
  FieldGroup,
  FieldLabel,
  FieldLegend,
  FieldSeparator,
  FieldSet,
} from "@/components/ui/field"

Ejemplos

Predeterminado

We will never share your email.

<Field>
  <FieldLabel htmlFor="email" required>Email</FieldLabel>
  <Input id="email" type="email" placeholder="m@example.com" aria-describedby="email-description" />
  <FieldDescription id="email-description">We will never share your email.</FieldDescription>
</Field>

Inválido

Pon data-invalid en el Field y aria-invalid en el control. El FieldError se anuncia de inmediato.

<Field data-invalid>
  <FieldLabel htmlFor="email">Email</FieldLabel>
  <Input id="email" type="email" aria-invalid aria-describedby="email-error" />
  <FieldError id="email-error">Enter a valid email address.</FieldError>
</Field>

Checkbox

orientation="horizontal" pone el control al lado de su etiqueta.

One short email a month. Unsubscribe any time.

<Field orientation="horizontal">
  <Checkbox id="news" defaultChecked aria-describedby="news-description" />
  <FieldContent>
    <FieldLabel htmlFor="news">Email me about new components</FieldLabel>
    <FieldDescription id="news-description">One short email a month. Unsubscribe any time.</FieldDescription>
  </FieldContent>
</Field>

Conjunto de campos

FieldSet y FieldLegend agrupan campos relacionados, y los lectores de pantalla leen la leyenda con cada uno.

Shipping address

Where we send your order.

<FieldSet>
  <FieldLegend>Shipping address</FieldLegend>
  <FieldDescription>Where we send your order.</FieldDescription>
  <FieldGroup>
    <Field>
      <FieldLabel htmlFor="street">Street</FieldLabel>
      <Input id="street" autoComplete="street-address" />
    </Field>
    <div className="grid grid-cols-2 gap-4">
      <Field>
        <FieldLabel htmlFor="city">City</FieldLabel>
        <Input id="city" autoComplete="address-level2" />
      </Field>
      <Field>
        <FieldLabel htmlFor="zip">Postal code</FieldLabel>
        <Input id="zip" autoComplete="postal-code" />
      </Field>
    </div>
    <FieldSeparator />
    <Field orientation="horizontal">
      <Checkbox id="billing" defaultChecked />
      <FieldLabel htmlFor="billing">Same as billing address</FieldLabel>
    </Field>
  </FieldGroup>
</FieldSet>

Accesibilidad

  • El FieldLabel es una etiqueta real: conéctalo al control con htmlFor e id.
  • Conecta el FieldDescription y el FieldError al control con aria-describedby.
  • El FieldError tiene role=alert y el color de texto destructivo (7:1); el mensaje es texto, nunca solo color.
  • Usa FieldSet y FieldLegend en grupos de checkboxes, radios o campos relacionados.