We will send a confirmation link to this address.
A component that provides labeling and validation for form controls. The Field component extends Base UI's Field. It styles Field.Label, Field.Description, and Field.Error, and renders Field.Control as an Input. Use it inside a Form to validate several fields together and show server errors.
Here is the component implementation code that you can copy to your project:
// https://devie-ui.com/components/field
// https://base-ui.com/react/components/field
import { Field as BaseField } from "@base-ui/react/field";
import clsx from "clsx";
import styles from "./Field.module.scss";
import Input from "./Input";
function Root({ className, ...props }: Field.Root.Props) {
return <BaseField.Root className={clsx(styles.root, className)} {...props} />;
}
function Label({ className, ...props }: Field.Label.Props) {
return (
<BaseField.Label className={clsx(styles.label, className)} {...props} />
);
}
function Control(props: Field.Control.Props) {
return <Input {...props} />;
}
function Description({ className, ...props }: Field.Description.Props) {
return (
<BaseField.Description
className={clsx(styles.description, className)}
{...props}
/>
);
}
function Item({ className, ...props }: Field.Item.Props) {
return <BaseField.Item className={clsx(styles.item, className)} {...props} />;
}
function ErrorField({ className, ...props }: Field.Error.Props) {
return (
<BaseField.Error className={clsx(styles.error, className)} {...props} />
);
}
const Field = {
Root,
Label,
Control,
Description,
Item,
Error: ErrorField,
Validity: BaseField.Validity,
};
namespace Field {
export namespace Root {
export type Props = Omit<BaseField.Root.Props, "className"> & {
className?: string;
};
export type State = BaseField.Root.State;
}
export namespace Label {
export type Props = Omit<BaseField.Label.Props, "className"> & {
className?: string;
};
}
export namespace Control {
export type Props = Omit<BaseField.Control.Props, "className"> & {
className?: string;
};
}
export namespace Description {
export type Props = Omit<BaseField.Description.Props, "className"> & {
className?: string;
};
}
export namespace Item {
export type Props = Omit<BaseField.Item.Props, "className"> & {
className?: string;
};
}
export namespace Error {
export type Props = Omit<BaseField.Error.Props, "className"> & {
className?: string;
};
}
export namespace Validity {
export type Props = BaseField.Validity.Props;
export type State = BaseField.Validity.State;
}
}
export default Field;Compose Field.Label, Field.Control, Field.Description, and Field.Error inside Field.Root. Field.Control renders an Input, and the label is associated with it automatically.
We only use it for account notifications.
Set required, minLength, pattern, or type on the control. Use Field.Error with the match prop to show a message for a ValidityState key.
Pass a validate function to Field.Root that returns an error string or null. Set validationMode to onChange, onBlur, or onSubmit to choose when it runs.
Wrap Select, Combobox, Autocomplete, Slider, NumberField, Radio, CheckboxGroup, Checkbox, or Switch in Field.Root to share the same layout and validation.
Used to calculate taxes.
Used to localize UI labels.
Used to format local times.
How many people are in your team.
Reduce alert noise during focus time.
Choose your billing tier.
Select how you want to be notified.
Required to proceed with account creation.
Receive occasional product updates and offers.