Skip to content

Commit 29afa77

Browse files
authored
fix(ui): respect admin.condition on row fields (#16954)
RenderField never forwarded `path` to RowField, so its `withCondition` wrapper looked up `passesCondition` at an undefined path and the row was never hidden. Result in row fields never gets hidden no matter what the `admin.condition` is. **Fix** Pass `path` to RowField and stop omitting `path` from RowFieldClientProps so the type matches the other layout fields (e.g. Collapsible). **Before** https://github.com/user-attachments/assets/a76c03da-a699-44a7-9ad2-ad0b2083b860 **After** Also checked other containers like array, tab, group etc. https://github.com/user-attachments/assets/deedc349-6afe-4bcc-89cb-fad71212f1aa
1 parent a8c8da8 commit 29afa77

5 files changed

Lines changed: 25 additions & 6 deletions

File tree

packages/payload/src/admin/fields/Row.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ import type {
2222

2323
type RowFieldClientWithoutType = MarkOptional<RowFieldClient, 'type'>
2424

25-
type RowFieldBaseClientProps = Omit<FieldPaths, 'path'> & Pick<ClientComponentProps, 'forceRender'>
25+
type RowFieldBaseClientProps = FieldPaths & Pick<ClientComponentProps, 'forceRender'>
2626

27-
export type RowFieldClientProps = Omit<ClientFieldBase<RowFieldClientWithoutType>, 'path'> &
27+
export type RowFieldClientProps = ClientFieldBase<RowFieldClientWithoutType> &
2828
RowFieldBaseClientProps
2929

3030
export type RowFieldServerProps = ServerFieldBase<RowField, RowFieldClientWithoutType>

packages/payload/src/admin/forms/Field.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,9 @@ export type FieldPaths = {
6363
* Nested fields will have a path that includes the parent field names
6464
* if they are nested within a group, array, block or named tab.
6565
*
66-
* Collapsibles and unnamed tabs will have arbitrary paths
66+
* Collapsibles, rows and unnamed tabs will have arbitrary paths
6767
* that look like _index-0, _index-1, etc.
6868
*
69-
* Row fields will not have a path.
70-
*
7169
* @example 'parentGroupField.childTextField'
7270
*
7371
* @default field.name

packages/ui/src/forms/RenderFields/RenderField.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ export function RenderField({
125125
return <RichTextField {...baseFieldProps} field={clientFieldConfig} path={path} />
126126

127127
case 'row':
128-
return <RowField {...iterableFieldProps} field={clientFieldConfig} />
128+
return <RowField {...iterableFieldProps} field={clientFieldConfig} path={path} />
129129

130130
case 'select':
131131
return <SelectField {...baseFieldProps} field={clientFieldConfig} path={path} />

test/fields/collections/ConditionalLogic/e2e.spec.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,15 @@ describe('Conditional Logic', () => {
289289
await expect(fieldWithOperationCondition).toBeHidden()
290290
})
291291

292+
test('should hide row field UI when admin.condition is false', async () => {
293+
await page.goto(url.create)
294+
295+
await toggleConditionAndCheckField(
296+
'label[for=field-toggleField]',
297+
'label[for=field-rowFieldWithCondition]',
298+
)
299+
})
300+
292301
test('should hide entire tabs field UI when admin.condition is false', async () => {
293302
await page.goto(url.create)
294303

test/fields/collections/ConditionalLogic/index.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,18 @@ const ConditionalLogic: CollectionConfig = {
3131
condition: ({ toggleField }) => Boolean(toggleField),
3232
},
3333
},
34+
{
35+
type: 'row',
36+
admin: {
37+
condition: ({ toggleField }) => Boolean(toggleField),
38+
},
39+
fields: [
40+
{
41+
name: 'rowFieldWithCondition',
42+
type: 'text',
43+
},
44+
],
45+
},
3446
{
3547
name: 'fieldWithOperationCondition',
3648
type: 'text',

0 commit comments

Comments
 (0)