Builder
IBuilderProps
export interface IBuilderProps {fields: IBuilderFieldProps[];data: DenormalizedQuery;className?: string;style?: IBuilderStyle;useDefaultContainerStyles?: boolean;colorScheme?: 'light' | 'dark';components?: IBuilderComponentsProps;strings?: IStrings;textMode?: boolean | IBuilderTextModeConfig;defaultMode?: BuilderDefaultMode;readOnly?: boolean;readOnlyProtectsDelete?: boolean;lockable?: boolean;cloneable?: boolean;draggable?: boolean;allowGroupNegation?: boolean;allowFieldComparisons?: boolean;singleRootGroup?: boolean;groupTypes?: 'with-modifiers' | 'without-modifiers' | 'both';newNodePlacement?: 'append' | 'prepend';validator?: IBuilderValidator;onStateChange?: (state: IBuilderStateChange) => void;onFieldOptionsReload?: (field: string) => void;onRuleOptionsReload?: (ruleId: string) => void;onFieldChange?: (change: IBuilderFieldChange) => void;showValidation?: boolean;history?: boolean | IBuilderHistoryConfig;onChange?: (data: DenormalizedQuery) => any;}
IBuilderHistoryConfig
export interface IBuilderHistoryConfig {maxEntries?: number;controls?: boolean;}
Props
fieldsRequired. Defines the available fields, their types, allowed operators, and optional validation metadata.dataRequired. The current denormalized query tree. The builder treats this as controlled input.- Ref support
Buildersupports React refs and can be paired withuseBuilderRef()for imperative access. componentsOptional overrides for internal UI pieces. Omitted entries fall back to default components.stringsOptional localized UI strings used by the built-in controls.textModeOptional. Enables SQL text mode. Passtruefor the default configuration orIBuilderTextModeConfigfor explicit SQL text-mode settings.defaultModeOptional. Controls whether the builder initially opens in'builder'or'text'mode. This only takes effect when text mode is enabled.readOnlyDefaults tofalse. Makes the whole builder non-editable.readOnlyProtectsDeleteDefaults totrue. When enabled, groups cannot be deleted if that would indirectly remove read-only protected descendants. Set it tofalseto allow those parent-group deletes while keeping direct read-only node restrictions.lockableDefaults tofalse. Renders lock controls for rules and groups and writes the resulting lock state back into emitted query data without discarding existing targetedreadOnly.targetsconfigurations.cloneableDefaults tofalse. Renders clone controls for rules and groups and inserts the cloned node directly below the original.draggableDefaults tofalse. Enables drag-and-drop reordering and movement of query nodes.useDefaultContainerStylesDefaults totrue. Set it tofalseto omit the built-in root surface styles while retaining the baseline typography and color styles. The rootdiv,className,style, and data attributes remain available.colorSchemeOptional'light' | 'dark'built-in component scheme. Dark mode requires importing@vojtechportes/react-query-builder/dark-mode.variables.css. Leave this undefined to preserve inherited application variables.allowGroupNegationDefaults totrue. When set tofalse, group negation is disabled across the builder: the group-levelNOTcontrol is hidden, emitted groups are normalized to non-negated form, and SQL text mode rejects group-levelNOT (...)expressions. Operator-level negation such asNOT IN,NOT LIKE,IS NOT NULL, andNOT BETWEENremains supported.allowFieldComparisonsDefaults tofalse. Enables the built-in value-source toggle so supported rules can compare one field against another throughvalueSource: 'field'andvalueField.singleRootGroupDefaults totrue. Wraps root-level items into a single root group and prevents deleting that root group. Text mode requires this to stay enabled.groupTypesDefaults to'with-modifiers'. Controls whether groups use combinator/negation controls, modifierless groups, or both. When text mode is active, builder-compatible SQL round-tripping uses groups with modifiers.newNodePlacementDefaults to'append'. Controls whether newly added rules and groups are inserted at the end or the beginning of their parent when built-in add actions or imperative add methods omit an explicit index.validatorOptional function that receives the denormalized query plus validation context and returns a validation result synchronously or asynchronously.onStateChangeOptional callback fired withdata,isValid, the full validation object, and history state flags such ascanUndoandcanRedo.onFieldOptionsReloadOptional callback fired byreloadFieldOptions(field)for shared field-level runtime options.onRuleOptionsReloadOptional callback fired byreloadRuleOptions(ruleId)for dependency-aware rule-level runtime options.onFieldChangeOptional callback fired with node id, field name, previous value, next value, and denormalized data after a rule field or value changes.showValidationDefaults tofalse. Controls whether validation issues are rendered in the built-in UI.historyOptional. Set totrueto enable undo and redo with default settings, or passIBuilderHistoryConfigto customize retention and built-in controls.onChangeOptional callback fired with the denormalized query tree after changes are emitted.
Field comparisons
Builder field comparison setup
import '@vojtechportes/react-query-builder/styles.css';const data: DenormalizedQuery = [{type: 'GROUP',value: 'AND',isNegated: false,children: [{field: 'ORDER_TOTAL',operator: 'LARGER_EQUAL',valueSource: 'field',valueField: 'ORDER_APPROVAL_LIMIT',},],},];<BuilderallowFieldComparisonsfields={fields}data={data}onChange={setData}/>;
- Opt-in The default UI exposes field-to-field comparisons only when
allowFieldComparisonsis enabled. - Persisted data Preloaded field-comparison rules stay representable through
valueSourceandvalueField, even though validation will block them when the prop is disabled.
Text mode behavior
Text mode types
export interface IBuilderTextModeConfig {format?: 'SQL';defaultMode?: BuilderDefaultMode;}export type BuilderDefaultMode = 'builder' | 'text';
- Format The current text-mode implementation edits SQL.
- Config shape
textModeaccepts eithertrueor{ format?: 'SQL'; defaultMode?: 'builder' | 'text' }. - Default-mode precedence If both
textMode.defaultModeand the top-leveldefaultModeprop are provided, the top-level prop wins. - Syntax and semantic validation The built-in editor highlights invalid SQL syntax plus builder-specific issues such as unknown fields, unsupported operators, and invalid select values.
- Field comparisons When
allowFieldComparisonsis enabled, SQL text mode accepts builder-compatible right-hand-side field references such asORDER_TOTAL >= ORDER_APPROVAL_LIMIT. When disabled, the same expression is reported as a semantic validation issue. - Invalid text flow Invalid text stays local to text mode, the last valid builder query is preserved, and
onChangeis fired only after a valid parse and semantic validation. - History Valid text edits are committed into builder history. Invalid intermediate text is not committed into builder state or history.
- Built-in editor Included in the main package and suitable for freely editable SQL text mode.
- Locked queries The built-in text editor blocks locked or targeted read-only queries because it cannot preserve protected text ranges safely after freeform edits.
- Custom editors Custom text editors receive
protectedRangesso localized read-only SQL fragments can stay visible while remaining non-editable. - Monaco path Use the optional
@vojtechportes/react-query-builder/monacosubpackage when you need a protected-range editor that can preserve locked and targeted read-only query segments.
History config
maxEntriesOptional limit for how many undo steps are retained.controlsOptional toggle for rendering the built-in Undo and Redo buttons inside the builder UI.
Documentation