Field

A control with its label, hint and error. Built on ui-sdk's Field: the label names the control, the hint describes it, and the error marks it invalid and is announced. The error sits in the gap under the control, aligned to its end edge, so showing it never moves the form.

BetaReady to use. Its API can still change in a minor release; the changelog says when.

import { Field, Input } from "@leap-crm/design-system";

Playground

Change a prop and the component follows. Its code is under Props.

As it appears on their ID.

Props

label
optional
hint
error
invalid
disabled
counter

Best practices

When to use it, and the rules that apply in particular places.

GuidancePractice
DoWrap every form control in a Field, like an Input, a Textarea or a Select, so the label names it and the error is announced.
DoWrite error as what to do, like "Please enter a valid email". It takes the hint's place or sits in the gap under the control, so the form doesn't move.
DoSet invalid with no message on a field whose partner holds the error, like a start time when the end time says it must be later.
DoPut a status badge or an info tooltip in labelAside, not in label, so it sits on the label's line without becoming part of the control's name.
Don'tShow CharacterCount from the first character on a long limit. Set showFrom near the limit: a counter over every short entry nags.
Don'tDim a field yourself with opacity. Set disabled, which disables the control and dims the whole field together.

Props

Field

PropTypeDefaultDescription
labelReactNode—Names the control. The red asterisk follows the control's own `required`.
optionalbooleanfalseShows a muted "Optional" after the label.
labelAsideReactNode—Sits on the label's line after it, like a status badge or an info tooltip.
hintReactNode—A line under the control. An error takes its place, so nothing moves.
errorReactNode—The error, like "Please enter a valid email". It shows the field as invalid and is announced.
invalidboolean—Shows the field as invalid without a message, like when another field holds the error.
counterReactNode—At the end of the hint line, like a CharacterCount.
namestring—The name the control submits under, when it doesn't set its own.
disabledboolean—Disables the control and dims the whole field.
classNamestring—Classes added to the root element, merged with its own. Tokens only.
children *ReactNode—The control: an Input, a Textarea or any ui-sdk control.

CharacterCount

PropTypeDefaultDescription
length *number—How many characters the text has now.
max *number—The limit. The count turns red at it.
showFromnumber0The length above which it appears.

Code

What the playground shows, ready to copy.

import { Field, Input } from "@leap-crm/design-system";

<Field label="Full name" hint="As it appears on their ID.">
  <Input defaultValue="Jane Citizen" />
</Field>