Fieldset
A native fieldset element with an easily stylable legend.
import * as React from 'react';
import { Field } from '@base-ui-components/react/field';
import { Fieldset } from '@base-ui-components/react/fieldset';
import styles from './index.module.css';
export default function ExampleField() {
return (
<Fieldset.Root className={styles.Fieldset}>
<Fieldset.Legend className={styles.Legend}>Billing details</Fieldset.Legend>
<Field.Root className={styles.Field}>
<Field.Label className={styles.Label}>Company</Field.Label>
<Field.Control placeholder="Enter company name" className={styles.Input} />
</Field.Root>
<Field.Root className={styles.Field}>
<Field.Label className={styles.Label}>Tax ID</Field.Label>
<Field.Control placeholder="Enter fiscal number" className={styles.Input} />
</Field.Root>
</Fieldset.Root>
);
}
API reference
Import the component and place its parts the following way:
import { Fieldset } from '@base-ui-components/react/fieldset';
<Fieldset.Root>
<Fieldset.Legend />
</Fieldset.Root>
Root
Groups the fieldset legend and the associated fields.
Renders a <fieldset>
element.
Prop | Type | Default | |
---|
className | string | (state) => string | undefined | |
---|
render | | React.ReactElement | (props, state) => React.ReactElement | undefined | |
---|
Legend
An accessible label that is automatically associated with the fieldset.
Renders a <div>
element.
Prop | Type | Default | |
---|
className | string | (state) => string | undefined | |
---|
render | | React.ReactElement | (props, state) => React.ReactElement | undefined | |
---|