Skip to content
This repository was archived by the owner on Mar 9, 2023. It is now read-only.

Commit c831a22

Browse files
authored
Merge pull request #9 from aerogear/nested-layout
2 parents ca28742 + a823ce2 commit c831a22

File tree

2 files changed

+24
-13
lines changed

2 files changed

+24
-13
lines changed

__tests__/NestField.tsx

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import React from 'react';
2+
import { Card } from '@patternfly/react-core';
23
import { AutoField, NestField } from 'uniforms-patternfly';
34

45
import createContext from './_createContext';
@@ -46,8 +47,8 @@ test('<NestField> - renders custom content if given', () => {
4647
);
4748

4849
expect(wrapper.find(AutoField)).toHaveLength(0);
49-
expect(wrapper.find('article')).toHaveLength(1);
50-
expect(wrapper.find('article').prop('data-test')).toBe('content');
50+
expect(wrapper.find('article').at(1)).toHaveLength(1);
51+
expect(wrapper.find('article').at(1).prop('data-test')).toBe('content');
5152
});
5253

5354
test('<NestField> - renders a label', () => {
@@ -83,19 +84,19 @@ test('<NestField> - renders a wrapper with unknown props', () => {
8384

8485
expect(
8586
wrapper
86-
.find('div')
87+
.find(Card)
8788
.at(0)
8889
.prop('data-x'),
8990
).toBe('x');
9091
expect(
9192
wrapper
92-
.find('div')
93+
.find(Card)
9394
.at(0)
9495
.prop('data-y'),
9596
).toBe('y');
9697
expect(
9798
wrapper
98-
.find('div')
99+
.find(Card)
99100
.at(0)
100101
.prop('data-z'),
101102
).toBe('z');

src/NestField.tsx

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import React, { HTMLProps } from 'react';
22
import { connectField, joinName, injectName, filterDOMProps } from 'uniforms/es5';
3+
import { Card, CardBody } from '@patternfly/react-core';
34

45
import AutoField from './AutoField';
56

@@ -27,16 +28,25 @@ const Nest = ({
2728
}: NestFieldProps) => {
2829

2930
return (
30-
<div
31+
<Card
3132
{...filterDOMProps(props)}
3233
>
33-
{label && <label>{label}</label>}
34-
{children
35-
? injectName(name, children)
36-
: fields?.map(key => (
37-
<AutoField key={key} disabled={disabled} name={joinName(name, key)} {...itemProps} />
38-
))}
39-
</div>
34+
<CardBody>
35+
{label && <label>{label}</label>}
36+
{children
37+
? injectName(name, children)
38+
: fields?.map(key => (
39+
<>
40+
<AutoField key={key} disabled={disabled} name={joinName(name, key)} {...itemProps} />
41+
{/*
42+
Not ideal to use a <br> tag, but a layout workaround that
43+
won't impact further nested fields
44+
*/}
45+
<br />
46+
</>
47+
))}
48+
</CardBody>
49+
</Card>
4050
);
4151

4252
}

0 commit comments

Comments
 (0)