@k8ordo/ui

FormControl

A wrapper that gives a field its label, help text and error text. The field itself is drawn in renderInput.

Import

ts
import { FormControl } from '@k8ordo/ui';

Usage

tsx
<FormControl
  label="Name"
  renderInput={(props) => (
    <TextField
      {...props}
      placeholder="Enter your name"
    />
  )}
/>

Help text

Please enter a valid email address.

tsx
<FormControl
  helpText="Please enter a valid email address."
  label="Email"
  renderInput={(props) => (
    <TextField
      {...props}
      placeholder="[email protected]"
    />
  )}
/>

Error text

This field is required.

tsx
<FormControl
  errorText="This field is required."
  invalid
  label="Email"
  renderInput={(props) => (
    <TextField {...props} />
  )}
/>

Required

tsx
<FormControl
  required
  label="Username"
  renderInput={(props) => (
    <TextField
      {...props}
      placeholder="Required field"
    />
  )}
/>

Disabled

tsx
<FormControl
  disabled
  label="Username"
  renderInput={(props) => (
    <TextField
      {...props}
      placeholder="Disabled field"
    />
  )}
/>

Props

label
Type: string
Default: -
renderInput
Type: (props: { id: string; 'aria-describedby': string | undefined; 'aria-labelledby': string; disabled: boolean; invalid: boolean; required: boolean; }) => ReactElement
Default: -
disabled?
Type: boolean
Default: false
errorText?
Type: string
Default: -
helpText?
Type: string
Default: -
invalid?
Type: boolean
Default: false
labelAs?
Type: 'label'|'legend'
Default: 'label'
ref?
Type: Ref<HTMLElement>
Default: -
required?
Type: boolean
Default: false
PropTypeDefault
labelstring-
renderInput(props: { id: string; 'aria-describedby': string | undefined; 'aria-labelledby': string; disabled: boolean; invalid: boolean; required: boolean; }) => ReactElement-
disabled?booleanfalse
errorText?string-
helpText?string-
invalid?booleanfalse
labelAs?'label'|'legend''label'
ref?Ref<HTMLElement>-
required?booleanfalse

Inherited attributes (except the ones set internally): HTMLAttributes<HTMLElement>

k8ordo

React libraries that use Baseline features without holding back.