Skip to content

Commit a103763

Browse files
authored
Merge pull request #1796 from payloadcms/fix/groups-within-row
fix: updates margin for group field within a row
2 parents f6e7497 + 1c3a257 commit a103763

File tree

5 files changed

+88
-12
lines changed

5 files changed

+88
-12
lines changed

src/admin/components/forms/field-types/Group/index.scss

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@
2929
border-bottom: 0;
3030
}
3131

32+
&--within-row {
33+
margin: 0;
34+
border-top: 0;
35+
border-bottom: 0;
36+
}
37+
3238
&--within-tab:first-child {
3339
margin-top: 0;
3440
border-top: 0;
@@ -80,4 +86,8 @@
8086

8187
.group-field--within-collapsible+.group-field--within-collapsible {
8288
margin-top: base(-1);
83-
}
89+
}
90+
91+
.group-field--within-row+.group-field--within-row {
92+
margin-top: 0;
93+
}

src/admin/components/forms/field-types/Group/index.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import FieldDescription from '../../FieldDescription';
66
import { Props } from './types';
77
import { useCollapsible } from '../../../elements/Collapsible/provider';
88
import { GroupProvider, useGroup } from './provider';
9+
import { useRow } from '../Row/provider';
910
import { useTabs } from '../Tabs/provider';
1011
import { getTranslation } from '../../../../../utilities/getTranslation';
1112
import { createNestedFieldPath } from '../../Form/createNestedFieldPath';
@@ -35,6 +36,7 @@ const Group: React.FC<Props> = (props) => {
3536

3637
const isWithinCollapsible = useCollapsible();
3738
const isWithinGroup = useGroup();
39+
const isWithinRow = useRow();
3840
const isWithinTab = useTabs();
3941
const { i18n } = useTranslation();
4042

@@ -48,6 +50,7 @@ const Group: React.FC<Props> = (props) => {
4850
baseClass,
4951
isWithinCollapsible && `${baseClass}--within-collapsible`,
5052
isWithinGroup && `${baseClass}--within-group`,
53+
isWithinRow && `${baseClass}--within-row`,
5154
isWithinTab && `${baseClass}--within-tab`,
5255
(!hideGutter && isWithinGroup) && `${baseClass}--gutter`,
5356
className,

src/admin/components/forms/field-types/Row/index.tsx

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import RenderFields from '../../RenderFields';
33
import withCondition from '../../withCondition';
44
import { Props } from './types';
55
import { createNestedFieldPath } from '../../Form/createNestedFieldPath';
6+
import { RowProvider } from './provider';
67

78
import './index.scss';
89

@@ -26,17 +27,19 @@ const Row: React.FC<Props> = (props) => {
2627
].filter(Boolean).join(' ');
2728

2829
return (
29-
<RenderFields
30-
readOnly={readOnly}
31-
className={classes}
32-
permissions={permissions}
33-
fieldTypes={fieldTypes}
34-
indexPath={indexPath}
35-
fieldSchema={fields.map((field) => ({
36-
...field,
37-
path: createNestedFieldPath(path, field),
38-
}))}
39-
/>
30+
<RowProvider>
31+
<RenderFields
32+
readOnly={readOnly}
33+
className={classes}
34+
permissions={permissions}
35+
fieldTypes={fieldTypes}
36+
indexPath={indexPath}
37+
fieldSchema={fields.map((field) => ({
38+
...field,
39+
path: createNestedFieldPath(path, field),
40+
}))}
41+
/>
42+
</RowProvider>
4043
);
4144
};
4245
export default withCondition(Row);
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import React, {
2+
createContext, useContext,
3+
} from 'react';
4+
5+
const Context = createContext(false);
6+
7+
export const RowProvider: React.FC<{ children?: React.ReactNode, withinRow?: boolean }> = ({ children, withinRow = true }) => {
8+
return (
9+
<Context.Provider value={withinRow}>
10+
{children}
11+
</Context.Provider>
12+
);
13+
};
14+
15+
export const useRow = (): boolean => useContext(Context);
16+
17+
export default Context;

test/fields/collections/Group/index.ts

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,49 @@ const GroupFields: CollectionConfig = {
6767
},
6868
],
6969
},
70+
{
71+
type: 'row',
72+
fields: [
73+
{
74+
name: 'groupInRow',
75+
type: 'group',
76+
fields: [
77+
{
78+
name: 'field',
79+
type: 'text',
80+
},
81+
{
82+
name: 'secondField',
83+
type: 'text',
84+
},
85+
{
86+
name: 'thirdField',
87+
type: 'text',
88+
},
89+
],
90+
},
91+
{
92+
name: 'secondGroupInRow',
93+
type: 'group',
94+
fields: [
95+
{
96+
name: 'field',
97+
type: 'text',
98+
},
99+
{
100+
name: 'nestedGroup',
101+
type: 'group',
102+
fields: [
103+
{
104+
name: 'nestedField',
105+
type: 'text',
106+
},
107+
],
108+
},
109+
],
110+
},
111+
],
112+
},
70113
],
71114
};
72115

0 commit comments

Comments
 (0)