Skip to content

Commit 57be108

Browse files
Vojtěch Václav Portešvojtechportes
authored andcommitted
feat: Set single root group as default
1 parent ed7f56f commit 57be108

4 files changed

Lines changed: 20 additions & 5 deletions

File tree

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ When `draggable` is `false`, no drag handles or drop zones are rendered.
261261

262262
#### `singleRootGroup`
263263

264-
When `singleRootGroup` is `true`, the builder is locked to exactly one root group.
264+
`singleRootGroup` is enabled by default. When it is `true`, the builder is locked to exactly one root group.
265265

266266
- root-level rules cannot be added
267267
- additional root-level groups cannot be added
@@ -273,6 +273,8 @@ Nested rules and groups inside the root group still work normally.
273273

274274
If the incoming `data` contains root-level rules or multiple root items, React Query Builder wraps them into a single root group automatically.
275275

276+
Set `singleRootGroup={false}` if you want to allow root-level rules, multiple root groups, and root-level drag-and-drop slots.
277+
276278
#### `groupTypes`
277279

278280
Controls what kinds of groups users can add:

example/src/main.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ const App: React.FC = () => {
146146
React.useState<DenormalizedQuery>(initialQueryTree);
147147
const [readOnly, setReadOnly] = React.useState(false);
148148
const [draggable, setDraggable] = React.useState(false);
149-
const [singleRootGroup, setSingleRootGroup] = React.useState(false);
149+
const [singleRootGroup, setSingleRootGroup] = React.useState(true);
150150
const [theme, setTheme] = React.useState<IThemeProviderProps>({
151151
colors,
152152
});

src/builder.test.tsx

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,12 @@ describe('#components/Builder', () => {
7575
it('Adds a group at the root level', () => {
7676
const onChange = jest.fn();
7777
const wrapper = mount(
78-
<Builder fields={fields} data={[]} onChange={onChange} />
78+
<Builder
79+
fields={fields}
80+
data={[]}
81+
singleRootGroup={false}
82+
onChange={onChange}
83+
/>
7984
);
8085

8186
wrapper.find('[data-test="AddRootGroup"]').first().simulate('click');
@@ -90,7 +95,12 @@ describe('#components/Builder', () => {
9095
it('Adds a rule at the root level', () => {
9196
const onChange = jest.fn();
9297
const wrapper = mount(
93-
<Builder fields={fields} data={[]} onChange={onChange} />
98+
<Builder
99+
fields={fields}
100+
data={[]}
101+
singleRootGroup={false}
102+
onChange={onChange}
103+
/>
94104
);
95105

96106
wrapper.find('[data-test="AddRootRule"]').first().simulate('click');
@@ -115,6 +125,7 @@ describe('#components/Builder', () => {
115125
children: [],
116126
},
117127
]}
128+
singleRootGroup={false}
118129
onChange={onChange}
119130
/>
120131
);
@@ -134,6 +145,7 @@ describe('#components/Builder', () => {
134145
fields={fields}
135146
data={[]}
136147
groupTypes="without-modifiers"
148+
singleRootGroup={false}
137149
onChange={onChange}
138150
/>
139151
);
@@ -164,6 +176,7 @@ describe('#components/Builder', () => {
164176
fields={fields}
165177
data={[]}
166178
groupTypes="both"
179+
singleRootGroup={false}
167180
onChange={jest.fn()}
168181
/>
169182
);

src/builder.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ export const Builder: FC<IBuilderProps> = ({
185185
strings = defaultStrings,
186186
readOnly = false,
187187
draggable = false,
188-
singleRootGroup = false,
188+
singleRootGroup = true,
189189
groupTypes = 'with-modifiers',
190190
onChange,
191191
}) => {

0 commit comments

Comments
 (0)