AntD Customization
formContext
You can customize the look of the form by passing options to Ant-Design theme fields.
The formContext antd object accepts the properties listed below, such as descriptionLocation and readonlyAsDisabled.
descriptionLocation can be 'below' | 'tooltip', the default is 'below' which places the description below the form item.
You can set it to tooltip that put the description inside the tooltip.
antd draws a tooltip only beside a label, so a field whose template draws no label, such as a checkbox, still shows its description below.
Note that you should have antd 4.7+ to use 'tooltip'.
The antd theme draws readOnly fields as disabled. Setting {readonlyAsDisabled: false} on the formContext turns that off.
<Form
formContext={{
descriptionLocation: 'tooltip',
readonlyAsDisabled: false,
// other props...
}}
/>
These are the formContext properties that you can modify to adjust the antd presentation. AntdFormContext, exported from @rjsf/antd, types them, to pass as the F type argument of generateForm() or to extend with your own:
colon: Whether antd draws its colon after a label, replacing one the label ends in, defaults to true; antd hides its colon on a label above its control, where the defaultlabelColputs itcolSpan: The columns of antd's 24-column grid an object's property spans, for every property or as a record keyed by the name of the widget it renders (textfor a plain string, the format's name for a string whoseformatnames a widget, such asdata-urlorhostname,selectfor a boolean with labelled options), the field aui:fieldor its$idnames, or the type of the field it renders, tried in that order, defaults to 24; a record gives a property with no entry 24 columns if it is the only visible property, an object, an array or a textarea, and 12 otherwisedescriptionLocation: Where to display the description, either 'below' or 'tooltip', defaults to 'below'labelAlign: The alignment of the labels antd'sForm.Itemdraws for a field and for an additional property's key, and of the headings of objects and arrays, one of 'start', 'end', 'left' or 'right' (antd 6 deprecates 'left' and 'right'); 'start' and 'left' put them at the start of their column, the others at its end. Unset, antd aligns a field's label, and a heading starts its column under the defaultlabelColor one with aspanor anxlof 24 and ends it under any otherlabelCol. antd sometimes starts field labels whateverlabelAlignsays, and a heading can't see an enclosing antdForm; see the upgrade guide for those caseslabelCol: The antdColprops of a field's label, defaults to{ span: 24 }. A heading takes only itsclassName, while the rest, such asstyleandoffset, goes to field labels onlyreadonlyAsDisabled: Whether to make the antd theme treat readOnly fields as disabled, defaults to truerowGutter: The gutter between the columns of a row, as antd'sRowtakes it, defaults to 24; anAltDateWidgetspaces its date parts by half of each side of a[horizontal, vertical]pair, or by half of a single gutter both ways, thoughRowapplies a single gutter horizontally only. A valueRowdraws no spacing for, such as0,''or a numeric string like'16', whichRowturns into invalid CSS, gives the date parts nonetoolbarAlign: The vertical alignment of an array item's toolbar, or of an additional property's row, as antd'sRowtakes it, defaults to 'middle' for an array item with a label and 'top' otherwisewrapperCol: The antdColprops of a field's control, defaults to{ span: 24 }wrapperStyle: The style of a field's antdForm.Item, which holds its label and control
import { generateForm, type AntdFormContext } from '@rjsf/antd';
import type { RJSFSchema } from '@rjsf/utils';
const Form = generateForm<unknown, RJSFSchema, AntdFormContext>();
const formContext: AntdFormContext = { labelAlign: 'start', rowGutter: [8, 8] };
<Form formContext={formContext} /* other props... */ />;
Using Antd v5 theme
You can use AntD v5 styling by wrapping your application with StyleProvider from @ant-design/cssinjs.
By default, @rjsf/antd components are using the v4 styling.
import { StyleProvider } from '@ant-design/cssinjs';
const Component = () => {
return (
<StyleProvider>
<YourFormComponents />
</StyleProvider>
);
};