Skip to main content
Version: Next

QueryBuilder controlElements prop

Refer to the TypeScript reference page for information about the types and interfaces referenced below.

The controlElements prop object allows you to override the default components.

Usage example

function App() {
return (
<QueryBuilder controlElements={{ valueEditor: CustomValueEditor }}>
)
}

Properties

The following control overrides are supported per the Controls interface. Setting a control override to null will hide the element by rendering it as () => null.

PropertyType
actionElementReact.ComponentType<ActionProps>
addGroupActionReact.ComponentType<ActionWithRulesAndAddersProps> | null
addRuleActionReact.ComponentType<ActionWithRulesAndAddersProps> | null
cloneGroupActionReact.ComponentType<ActionWithRulesProps> | null
cloneRuleActionReact.ComponentType<ActionProps> | null
combinatorSelectorReact.ComponentType<CombinatorSelectorProps> | null
dragHandleReact.ForwardRefExoticComponent<DragHandleProps & React.RefAttributes<HTMLSpanElement>> | null
fieldSelectorReact.ComponentType<FieldSelectorProps> | null
inlineCombinatorReact.ComponentType<InlineCombinatorProps> | null
lockGroupActionReact.ComponentType<ActionWithRulesProps> | null
lockRuleActionReact.ComponentType<ActionProps> | null
matchModeEditorReact.ComponentType<MatchModeEditorProps> | null
notToggleReact.ComponentType<NotToggleProps> | null
operatorSelectorReact.ComponentType<OperatorSelectorProps> | null
removeGroupActionReact.ComponentType<ActionWithRulesProps> | null
removeRuleActionReact.ComponentType<ActionProps> | null
ruleReact.ComponentType<RuleProps>
ruleGroupReact.ComponentType<RuleGroupProps>
ruleGroupBodyElementsReact.ComponentType<RuleGroupProps & ReturnType<typeof useRuleGroup>>
ruleGroupHeaderElementsReact.ComponentType<RuleGroupProps & ReturnType<typeof useRuleGroup>>
shiftActionsReact.ComponentType<ShiftActionsProps> | null
valueEditorReact.ComponentType<ValueEditorProps> | null
valueSelectorReact.ComponentType<ValueSelectorProps>
valueSourceSelectorReact.ComponentType<ValueSourceSelectorProps> | null

actionElement

The component for all button-type controls. Default is ActionElement. Receives props per the ActionProps, ActionWithRulesProps, or ActionWithRulesAndAddersProps interface depending on the control, which can be any of the following:

For example, this:

<QueryBuilder controlElements={{ actionElement: MyAwesomeButton }} />

...is equivalent to this:

<QueryBuilder
controlElements={{
addGroupAction: MyAwesomeButton
addRuleAction: MyAwesomeButton
cloneGroupAction: MyAwesomeButton
cloneRuleAction: MyAwesomeButton
lockGroupAction: MyAwesomeButton
lockRuleAction: MyAwesomeButton
removeGroupAction: MyAwesomeButton
removeRuleAction: MyAwesomeButton
}}
/>

addGroupAction

Adds a sub-group to the current group. Default is ActionElement.

Props for addGroupAction

Per the ActionWithRulesAndAddersProps interface:

PropTypeDescription
labelReactNodetranslations.addGroup.label, e.g. "+ Group"
titlestringtranslations.addGroup.title, e.g. "Add group"
classNamestringCSS classNames to be applied
handleOnClick(e: React.MouseEvent, context?: any) => voidAdds a new sub-group to this group
rulesRuleOrGroupArrayThe rules array for this group
ruleOrGroupRuleGroupTypeAnyThis group
levelnumberThe level of this group
contextanyContainer for custom props that are passed to all components
validationboolean | ValidationResultValidation result of this group
disabledbooleanWhether this group is disabled/locked
pathPathPath of this group
schemaSchemaQuery schema

addRuleAction

Adds a rule to the current group. Default is ActionElement.

Props for addRuleAction

Per the ActionWithRulesAndAddersProps interface:

PropTypeDescription
labelReactNodetranslations.addRule.label, e.g. "+ Rule"
titlestringtranslations.addRule.title, e.g. "Add rule"
classNamestringCSS classNames to be applied
handleOnClick(e: React.MouseEvent, context?: any) => voidAdds a new rule to this rule
rulesRuleOrGroupArrayThe rules array for this rule
ruleOrGroupRuleGroupTypeAnyThis rule
levelnumberThe level of this rule
contextanyContainer for custom props that are passed to all components
validationboolean | ValidationResultValidation result of this rule
disabledbooleanWhether this rule is disabled/locked
pathPathPath of this rule
schemaSchemaQuery schema

cloneGroupAction

Clones the current group. Default is ActionElement.

Props for cloneGroupAction

Per the ActionWithRulesProps interface:

PropTypeDescription
labelReactNodetranslations.cloneRuleGroup.label, e.g. "⧉"
titlestringtranslations.cloneRuleGroup.title, e.g. "Clone group"
classNamestringCSS classNames to be applied
handleOnClick(e: React.MouseEvent) => voidClones this group
rulesRuleOrGroupArrayThe rules array for this group
ruleOrGroupRuleGroupTypeAnyThis group
levelnumberThe level of this group
contextanyContainer for custom props that are passed to all components
validationboolean | ValidationResultValidation result of this group
disabledbooleanWhether this group is disabled/locked
pathPathPath of this group
schemaSchemaQuery schema

cloneRuleAction

Clones the current rule. Default is ActionElement.

Props for cloneRuleAction

Per the ActionProps interface:

PropTypeDescription
labelstringtranslations.cloneRule.label, e.g. "⧉"
titlestringtranslations.cloneRule.title, e.g. "Clone rule"
classNamestringCSS classNames to be applied
handleOnClick(e: React.MouseEvent) => voidClones the rule
ruleOrGroupRuleTypeThis rule
levelnumberThe level of this rule
contextanyContainer for custom props that are passed to all components
validationboolean | ValidationResultValidation result of this rule
disabledbooleanWhether this rule is disabled/locked
pathPathPath of this rule
schemaSchemaQuery schema

combinatorSelector

Selects the combinator property for the current group, or the current independent combinator value. Default is ValueSelector.

Props for combinatorSelector

Per the CombinatorSelectorProps interface:

PropTypeDescription
optionsOptionListSame as combinators prop passed into QueryBuilder
valuestringSelected combinator from the existing query representation, if any
classNamestringCSS classNames to be applied
handleOnChange(value: any) => voidUpdates the group's combinator
rulesRuleOrGroupArrayThe rules array for this group
titlestringtranslations.combinators.title, e.g. "Combinators"
levelnumberThe level of this group
contextanyContainer for custom props that are passed to all components
validationboolean | ValidationResultValidation result of this group
disabledbooleanWhether this group is disabled/locked
pathPathPath of this group
schemaSchemaQuery schema

dragHandle

Provides a draggable handle for reordering rules and groups. Default is DragHandle. Only rendered if drag-and-drop is enabled. Note that this component must be based on React.forwardRef.

Props for dragHandle

Receives the forwarded ref and the following props per the DragHandleProps interface:

PropTypeDescription
labelReactNodetranslations.dragHandle.label, e.g. "⁞⁞"
titlestringtranslations.dragHandle.title, e.g. "Drag handle"
classNamestringCSS classNames to be applied
levelnumberThe level of this rule/group
contextanyContainer for custom props that are passed to all components
validationboolean | ValidationResultValidation result of this rule/group
disabledbooleanWhether this rule/group is disabled/locked
pathPathPath of this rule/group
schemaSchemaQuery schema
ruleOrGroupRuleGroupTypeAny | RuleTypeThis group or rule, depending on the parent component

fieldSelector

Selects the field property for the current rule. Default is ValueSelector.

Props for fieldSelector

Per the FieldSelectorProps interface:

PropTypeDescription
optionsOptionList<Field>Same as fields prop passed into QueryBuilder
valuestringSelected field from the existing query representation, if any
titlestringtranslations.fields.title, e.g. "Fields"
operatorstringSelected operator from the existing query representation, if any
classNamestringCSS classNames to be applied
handleOnChange(value: any) => voidUpdates the rule's field
levelnumberThe level of this rule
contextanyContainer for custom props that are passed to all components
validationboolean | ValidationResultValidation result of this rule
disabledbooleanWhether this rule is disabled/locked
pathPathPath of this rule
schemaSchemaQuery schema
ruleRuleTypeThis rule

inlineCombinator

A small wrapper around the combinatorSelector component. Default is InlineCombinator.

Props for inlineCombinator

Per the InlineCombinatorProps interface, which extends CombinatorSelectorProps:

PropTypeDescription
componentSchema['controls']['combinatorSelector']Same as the combinatorSelector component

lockGroupAction

Locks the current group (sets the disabled property to true). Default is ActionElement.

Props for lockGroupAction

Per the ActionWithRulesProps interface:

PropTypeDescription
labelReactNodetranslations.lockGroup.label or translations.lockGroupDisabled.label, e.g. "🔓" when unlocked and "🔒" when locked
titlestringtranslations.lockGroup.title or translations.lockGroupDisabled.title, e.g. "Lock group" or "Unlock group"
classNamestringCSS classNames to be applied
handleOnClick(e: React.MouseEvent) => voidLocks the group
rulesRuleOrGroupArrayThe rules present for this group
ruleOrGroupRuleGroupTypeAnyThis group
levelnumberThe level of this group
contextanyContainer for custom props that are passed to all components
validationboolean | ValidationResultValidation result of this group
disabledbooleanWhether this group is disabled/locked
disabledTranslationstringtranslations.lockGroupDisabled if parent group is not disabled, otherwise undefined
pathPathPath of this group
schemaSchemaQuery schema

lockRuleAction

Locks the current rule (sets the disabled property to true). Default is ActionElement.

Props for lockRuleAction

Per the ActionWithRulesProps interface:

PropTypeDescription
labelReactNodetranslations.lockRule.label or translations.lockRuleDisabled.label, e.g. "🔓" when unlocked and "🔒" when locked
titlestringtranslations.lockRule.title or translations.lockRuleDisabled.title, e.g. "Lock rule" or "Unlock rule"
classNamestringCSS classNames to be applied
handleOnClick(e: React.MouseEvent) => voidLocks the rule
ruleOrGroupRuleTypeThis rule
levelnumberThe level of this rule
contextanyContainer for custom props that are passed to all components
validationboolean | ValidationResultValidation result of this rule
disabledbooleanWhether this rule is disabled/locked
disabledTranslationstringtranslations.lockRuleDisabled if parent group is not disabled, otherwise undefined
pathPathPath of this rule
schemaSchemaQuery schema

matchModeEditor

Manages the match property for the current rule, including the mode and threshold (see Subqueries). Default is MatchModeEditor.

Props for matchModeEditor

Per the MatchModeEditorProps interface:

PropTypeDescription
matchMatchConfigCurrent match configuration for this rule
optionsOptionList<MatchMode>Available match modes for the current field
fieldstringField name corresponding to this rule
fieldDataFullFieldThe entire object from the fields array for this field
ruleRuleTypeThis rule
selectorComponentComponentType<ValueSelectorProps>Component to use for the match mode selector
numericEditorComponentComponentType<ValueEditorProps>Component to use for the match threshold editor
classNames{ matchMode: string; matchThreshold: string }CSS classNames for sub-components
valuestringCurrent match mode value
classNamestringCSS classNames to be applied
handleOnChange(value: any) => voidUpdates the rule's match configuration
levelnumberThe level of this rule
contextanyContainer for custom props that are passed to all components
validationboolean | ValidationResultValidation result of this rule
disabledbooleanWhether this rule is disabled/locked
pathPathPath of this rule
schemaSchemaQuery schema

notToggle

Toggles the not property of the current group between true and false. Default is NotToggle.

Props for notToggle

Per the NotToggleProps interface:

PropTypeDescription
labelReactNodetranslations.notToggle.label, e.g. "Not"
titlestringtranslations.notToggle.title, e.g. "Invert this group"
classNamestringCSS classNames to be applied
handleOnChange(checked: boolean) => voidUpdates the group's not property
checkedbooleanWhether the input should be checked or not
levelnumberThe level of this group
contextanyContainer for custom props that are passed to all components
validationboolean | ValidationResultValidation result of this group
disabledbooleanWhether this group is disabled/locked
pathPathPath of this group
schemaSchemaQuery schema
ruleGroupRuleGroupTypeAnyThis group

operatorSelector

Selects the operator property for the current rule. Default is ValueSelector.

Props for operatorSelector

Per the OperatorSelectorProps interface:

PropTypeDescription
fieldstringField name corresponding to this rule
fieldDataFieldThe entire object from the fields array for this field
optionsOptionList<Operator>Return value of getOperators(field, { fieldData })
valuestringSelected operator from the existing query representation, if any
titlestringtranslations.operators.title, e.g. "Operators"
classNamestringCSS classNames to be applied
handleOnChange(value: any) => voidUpdates the rule's operator
levelnumberThe level of this rule
contextanyContainer for custom props that are passed to all components
validationboolean | ValidationResultValidation result of this rule
disabledbooleanWhether this rule is disabled/locked
pathPathPath of this rule
schemaSchemaQuery schema
ruleRuleTypeThis rule

removeGroupAction

Removes the current group from its parent group's rules array. Default is ActionElement.

Props for removeGroupAction

Per the ActionWithRulesProps interface:

PropTypeDescription
labelReactNodetranslations.removeGroup.label, e.g. "⨯"
titlestringtranslations.removeGroup.title, e.g. "Remove group"
classNamestringCSS classNames to be applied
handleOnClick(e: React.MouseEvent) => voidRemoves the group
rulesRuleOrGroupArrayThe rules array for this group
ruleOrGroupRuleGroupTypeAnyThis group
levelnumberThe level of this group
contextanyContainer for custom props that are passed to all components
validationboolean | ValidationResultValidation result of this group
disabledbooleanWhether this group is disabled/locked
pathPathPath of this group
schemaSchemaQuery schema

removeRuleAction

Removes the current rule from its parent group's rules array. Default is ActionElement.

Props for removeRuleAction

Per the ActionProps interface:

PropTypeDescription
labelReactNodetranslations.removeRule.label, e.g. "⨯"
titlestringtranslations.removeRule.title, e.g. "Remove rule"
classNamestringCSS classNames to be applied
handleOnClick(e: React.MouseEvent) => voidRemoves the rule
ruleOrGroupRuleTypeThis rule
levelnumberThe level of this rule
contextanyContainer for custom props that are passed to all components
validationboolean | ValidationResultValidation result of this rule
disabledbooleanWhether this rule is disabled/locked
pathPathPath of this rule
schemaSchemaQuery schema

rule

Rule layout component. Default is Rule.

Props for rule

Per the RuleProps interface:

PropTypeDescription
idstringUnique identifier for this rule
pathPathPath of this rule
ruleRuleTypeThe rule object
translationsTranslationsThe default translations merged with the translations prop
schemaSchemaQuery schema
actionsQueryActionsQuery update functions
contextanyContainer for custom props that are passed to all components
disabledbooleanWhether the rule itself is disabled
shiftUpDisabledbooleanWhether shifting the rule up is disallowed
shiftDownDisabledbooleanWhether shifting the rule down is disallowed
parentDisabledbooleanWhether the parent group of this rule is disabled
tip

If you enable drag-and-drop and want to use a custom Rule component, use the controlElements prop on the QueryBuilderDnD context provider instead of QueryBuilder.

ruleGroup

Rule group layout component. Default is RuleGroup.

Props for ruleGroup

Per the RuleGroupProps interface:

PropTypeDescription
idstringUnique identifier for this group
pathPathPath of this group
ruleGroupRuleGroupTypeAnyThe group object
translationsTranslationsThe default translations merged with the translations prop
schemaSchemaQuery schema
actionsQueryActionsQuery update functions
contextanyContainer for custom props that are passed to all components
disabledbooleanWhether the group itself is disabled
shiftUpDisabledbooleanWhether shifting the group up is disallowed
shiftDownDisabledbooleanWhether shifting the group down is disallowed
parentDisabledbooleanWhether the parent group of this group is disabled
tip

If you enable drag-and-drop and want to use a custom RuleGroup component, use the controlElements prop on the QueryBuilderDnD context provider instead of QueryBuilder.

ruleGroupBodyElements

Rule group body elements. Default is RuleGroupBodyComponents, which returns an array containing only the elements themselves (no HTML or React Native wrapper element). Receives the same props as ruleGroup, in addition to the return value of the useRuleGroup hook.

ruleGroupHeaderElements

Rule group header elements. Default is RuleGroupHeaderComponents, which returns a React Fragment containing only the elements themselves (no HTML or React Native wrapper element). Receives the same props as ruleGroup, in addition to the return value of the useRuleGroup hook.

shiftActions

Shifts the current rule/group up or down in the query hierarchy. Default is ShiftActions.

Props for shiftActions

Per the ShiftActionsProps interface:

PropTypeDescription
labels{ shiftUp: ReactNode; shiftDown: ReactNode; }translations.shiftActionUp.label and translations.shiftActionDown.label, e.g. "˄" and "˅"
titles{ shiftUp: string; shiftDown: string; }translations.shiftActionUp.title and translations.shiftActionDown.title, e.g. "Shift up" and "Shift down"
classNamestringCSS classNames to be applied
ruleOrGroupRuleGroupTypeAnyThis rule/group
levelnumberThe level of this rule/group
contextanyContainer for custom props that are passed to all components
validationboolean | ValidationResultValidation result of this rule/group
disabledbooleanWhether this rule/group is disabled/locked
pathPathPath of this rule/group
schemaSchemaQuery schema
shiftUp() => voidMethod to shift the rule/group up one place
shiftDown() => voidMethod to shift the rule/group down one place
shiftUpDisabledbooleanWhether shifting the rule/group up is disallowed
shiftDownDisabledbooleanWhether shifting the rule/group down is disallowed

valueEditor

Updates the value property for the current rule. Default is ValueEditor.

Props for valueEditor

Per the ValueEditorProps interface:

PropTypeDescription
fieldstringField name corresponding to this rule
fieldDataFieldThe entire object from the fields array for this field
operatorstringOperator name corresponding to this rule
valuestringvalue from the existing query representation, if any
titlestringtranslations.value.title, e.g. "Value"
handleOnChange(value: any) => voidUpdates the rule's value
typeValueEditorTypeType of editor to be displayed
inputTypestringIntended @type attribute of the <input>, if type prop is "text"
valuesany[]List of available values for this rule
classNamestringCSS classNames to be applied
valueSourceValueSourceValue source for this rule
listsAsArraysbooleanWhether to manage value lists (i.e. "between"/"in" operators) as arrays
parseNumbersParseNumberMethodWhether to parse real numbers from strings
separatorReactNodeSeparator element for series of editors (i.e. "between" operator)
levelnumberThe level of this rule
contextanyContainer for custom props that are passed to all components
validationboolean | ValidationResultValidation result of this rule
disabledbooleanWhether this rule is disabled/locked
pathPathPath of this rule
schemaSchemaQuery schema
ruleRuleTypeThis rule

valueSelector

The component for all value selector controls. Default is ValueSelector. Receives props per the CombinatorSelectorProps, FieldSelectorProps, OperatorSelectorProps, or ValueSourceSelectorProps interface depending on the control, which can be any of the following:

For example, this:

<QueryBuilder controlElements={{ valueSelector: MyAwesomeSelector }} />

...is equivalent to this:

<QueryBuilder
controlElements={{
combinatorSelector: MyAwesomeSelector
fieldSelector: MyAwesomeSelector
operatorSelector: MyAwesomeSelector
valueSourceSelector: MyAwesomeSelector
}}
/>

valueSourceSelector

Selects the valueSource property for the current rule. Default is ValueSelector.

Props for valueSourceSelector

Per the ValueSourceSelectorProps interface:

PropTypeDescription
fieldstringField name corresponding to this rule
fieldDataFieldThe entire object from the fields array for the selected field
optionsOptionList<ValueSourceOption>Return value of getValueSources(field, operator, { fieldData })
valueValueSourceSelected value source for this rule, if any
titlestringtranslations.valueSourceSelector.title, e.g. "Value source"
classNamestringCSS classNames to be applied
handleOnChange(value: any) => voidUpdates the rule's valueSource
levelnumberThe level of this rule
contextanyContainer for custom props that are passed to all components
validationboolean | ValidationResultValidation result of this rule
disabledbooleanWhether this rule is disabled/locked
pathPathPath of this rule
schemaSchemaQuery schema
ruleRuleTypeThis rule