DocsBlog
  • 0.25.3

  • light

    dark

    system

    Switch mode
  • Cerberus

    Acheron

    Elysium

Get Started
Components
Styling
Theming

Concepts

OverviewCompositionTesting

Layout

Aspect RatioBleedBoxCenterContainerDividerFlexFloatGridLink OverlayScrollableStackWrap

Components

AccordionAdmonitionAvatarButtonCarouselCheckboxClipboardCollapsibleComboboxConfirm ModalCTAModalDate PickerDialogFieldFieldsetFile UploaderIcon ButtonInputLoading StatesMenuNotificationsNumber InputPin InputProgressPrompt ModalRadioRatingSelectSplit ButtonSwitchTableTabsTagTextTextareaToggleTooltip

Utilities

Client OnlyDownload TriggerEnvironmentFeature FlagsFocus TrapForFormat ByteFormat NumberFormat Relative TimeFrameHighlightJSON Tree ViewLocaleLocal StoragePortalPresenceShowsplitPropsTheme

Fieldset

The Fieldset component groups form fields together with a shared legend and helper/error text.

  • npm
  • source
  • recipe
  • Ark
import { Fieldset, FieldsetParts } from '@cerberus/react'

Usage

Form Section Example

The Fieldset component can be used to group related form elements together using the usage prop which can be either formSection or fieldGroup (default).

Update your profileYou can update your profile information here.
This is an error message for the fieldset group.
Copy
radio-group.tsx
import {
Fieldset,
Field,
Input,
RadioGroup,
Radio,
} from '@cerberus/react'
import { Box, VStack } from 'styled-system/jsx'
export function BasicDemo() {
return (
<Box w="1/2">
<Fieldset
invalid
legend="Update your profile"
helperText="You can update your profile information here."
errorText="This is an error message for the fieldset group."
usage="formSection"
>
<VStack alignItems="flex-start" gap="lg" paddingBlock="lg" w="full">
<Field
ids={{
control: 'first_name',
}}
label="What is your first name?"
required
>
<Input name="first_name" />
</Field>
<Field
ids={{
control: 'display_name',
}}
label="What is your display name?"
required
>
<Input name="last_name" />
</Field>
</VStack>
</Fieldset>
</Box>
)
}

Field Group Example

When use need to label a group of Radio or Checkbox inputs, use the usage prop with the value fieldGroup.

Who is your favorite?
Copy
radio-group.tsx
import {
Fieldset,
RadioGroup,
Radio,
} from '@cerberus/react'
import { Box } from 'styled-system/jsx'
function FieldsetGroupDemo() {
return (
<Box w="1/2">
<Fieldset legend="Who is your favorite?">
<RadioGroup name="favorite" defaultValue="cerberus">
<Radio value="cerberus">Cerberus</Radio>
<Radio value="hades">Hades</Radio>
<Radio value="zeus">Zeus</Radio>
</RadioGroup>
</Fieldset>
</Box>
)
}

Primitives

You can utilize the primitive components or the css prop to customize the Fieldset.

ComponentDescription
FieldsetRootThe context provider for the Fieldset parts
FieldsetLegendThe label of the fieldset
FieldsetHelperTextThe label description for the Fieldset
FieldsetErrorTextThe error message for the Fieldset
Custom LegendThis is some custom Helper Text
This is a custom Error Text
Copy
custom fieldset
import { Field, FieldsetParts, Input } from '@cerberus/react'
import { Box } from 'styled-system/jsx'
function CustomDemo() {
return (
<Box w="1/2">
<FieldsetParts.Root invalid>
<FieldsetParts.Legend
css={{
textStyle: 'heading-lg',
}}
>
Custom Legend
</FieldsetParts.Legend>
<FieldsetParts.HelperText
css={{
color: 'page.text.200',
fontStyle: 'italic',
textStyle: 'body-sm',
}}
>
This is some custom Helper Text
</FieldsetParts.HelperText>
<Box paddingBlock="lg" w="full">
<Field label="This is a custom example">
<Input />
</Field>
</Box>
<FieldsetParts.ErrorText
css={{
bgColor: 'danger.bg.initial',
color: 'danger.text.100',
p: 4,
rounded: 'lg',
}}
>
This is a custom Error Text
</FieldsetParts.ErrorText>
</FieldsetParts.Root>
</Box>
)
}

API

Props

The Fieldset component is an abstraction of the primitives and accepts the following props:

NameDefaultDescription
usagefieldGroupThe type of fieldset to display.

The Fieldset component also accepts all the props of the FieldsetRoot primitive props

Parts

The FieldsetParts API is an Object containing the full family of components.

Note

It is best to only use the FieldsetParts if you are building a custom solution. Importing Object based components will ship every property it includes into your bundle, regardless if you use it or not.

NameDescription
RootThe FieldsetRoot component which is the Provider for the family.
LegendThe FieldsetLegend component which displays the label.
HelperTextThe FieldsetHelperText component which displays the description text.
ErrorTextThe FieldsetErrorText component which displays the error text when the group is marked invalid.

On this page

  • Edit this page on Github
Cerberus Design System | Docs