Skip to content

Commit

Permalink
Added showInlineError prop to AutoFields (closes #827).
Browse files Browse the repository at this point in the history
  • Loading branch information
Monteth authored Apr 20, 2021
1 parent 3a559de commit 6b1e3b2
Show file tree
Hide file tree
Showing 12 changed files with 180 additions and 12 deletions.
20 changes: 19 additions & 1 deletion packages/uniforms-antd/__tests__/AutoFields.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { AutoFields } from 'uniforms-antd';
import { AutoField, AutoFields } from 'uniforms-antd';

import createContext from './_createContext';
import mount from './_mount';
Expand Down Expand Up @@ -86,3 +86,21 @@ test('<AutoFields> - wraps fields in specified element', () => {

expect(wrapper.find('section').find('input')).toHaveLength(3);
});

test('<AutoFields> - pass props to the children', () => {
const element = <AutoFields showInlineError />;
const wrapper = mount(
element,
createContext({
x: { type: String },
y: { type: String },
z: { type: String },
}),
);

const hasShowInlineErrorMap = wrapper
.find(AutoField)
.map(node => node.prop('showInlineError'));
expect(hasShowInlineErrorMap).toHaveLength(3);
expect(hasShowInlineErrorMap).toBeTruthy();
});
12 changes: 11 additions & 1 deletion packages/uniforms-antd/src/AutoFields.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@ export type AutoFieldsProps = {
element?: ComponentType | string;
fields?: string[];
omitFields?: string[];
showInlineError?: boolean;
};

export default function AutoFields({
autoField = AutoField,
element = 'div',
fields,
omitFields = [],
showInlineError,
...props
}: AutoFieldsProps) {
const { schema } = useForm();
Expand All @@ -24,6 +26,14 @@ export default function AutoFields({
props,
(fields ?? schema.getSubfields())
.filter(field => !omitFields.includes(field))
.map(field => createElement(autoField, { key: field, name: field })),
.map(field =>
createElement(
autoField,
Object.assign(
{ key: field, name: field },
showInlineError === undefined ? null : { showInlineError },
),
),
),
);
}
20 changes: 19 additions & 1 deletion packages/uniforms-bootstrap3/__tests__/AutoFields.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { AutoFields } from 'uniforms-bootstrap3';
import { AutoFields, AutoField } from 'uniforms-bootstrap3';

import createContext from './_createContext';
import mount from './_mount';
Expand Down Expand Up @@ -86,3 +86,21 @@ test('<AutoFields> - wraps fields in specified element', () => {

expect(wrapper.find('section').find('input')).toHaveLength(3);
});

test('<AutoFields> - pass props to the children', () => {
const element = <AutoFields showInlineError />;
const wrapper = mount(
element,
createContext({
x: { type: String },
y: { type: String },
z: { type: String },
}),
);

const hasShowInlineErrorMap = wrapper
.find(AutoField)
.map(node => node.prop('showInlineError'));
expect(hasShowInlineErrorMap).toHaveLength(3);
expect(hasShowInlineErrorMap).toBeTruthy();
});
12 changes: 11 additions & 1 deletion packages/uniforms-bootstrap3/src/AutoFields.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@ export type AutoFieldsProps = {
element?: ComponentType | string;
fields?: string[];
omitFields?: string[];
showInlineError?: boolean;
};

export default function AutoFields({
autoField = AutoField,
element = 'div',
fields,
omitFields = [],
showInlineError,
...props
}: AutoFieldsProps) {
const { schema } = useForm();
Expand All @@ -24,6 +26,14 @@ export default function AutoFields({
props,
(fields ?? schema.getSubfields())
.filter(field => !omitFields.includes(field))
.map(field => createElement(autoField, { key: field, name: field })),
.map(field =>
createElement(
autoField,
Object.assign(
{ key: field, name: field },
showInlineError === undefined ? null : { showInlineError },
),
),
),
);
}
20 changes: 19 additions & 1 deletion packages/uniforms-bootstrap4/__tests__/AutoFields.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { AutoFields } from 'uniforms-bootstrap4';
import { AutoFields, AutoField } from 'uniforms-bootstrap4';

import createContext from './_createContext';
import mount from './_mount';
Expand Down Expand Up @@ -86,3 +86,21 @@ test('<AutoFields> - wraps fields in specified element', () => {

expect(wrapper.find('section').find('input')).toHaveLength(3);
});

test('<AutoFields> - pass props to the child AutoField', () => {
const element = <AutoFields showInlineError />;
const wrapper = mount(
element,
createContext({
x: { type: String },
y: { type: String },
z: { type: String },
}),
);

const hasShowInlineErrorMap = wrapper
.find(AutoField)
.map(node => node.prop('showInlineError'));
expect(hasShowInlineErrorMap).toHaveLength(3);
expect(hasShowInlineErrorMap).toBeTruthy();
});
12 changes: 11 additions & 1 deletion packages/uniforms-bootstrap4/src/AutoFields.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@ export type AutoFieldsProps = {
element?: ComponentType | string;
fields?: string[];
omitFields?: string[];
showInlineError?: boolean;
};

export default function AutoFields({
autoField = AutoField,
element = 'div',
fields,
omitFields = [],
showInlineError,
...props
}: AutoFieldsProps) {
const { schema } = useForm();
Expand All @@ -24,6 +26,14 @@ export default function AutoFields({
props,
(fields ?? schema.getSubfields())
.filter(field => !omitFields.includes(field))
.map(field => createElement(autoField, { key: field, name: field })),
.map(field =>
createElement(
autoField,
Object.assign(
{ key: field, name: field },
showInlineError === undefined ? null : { showInlineError },
),
),
),
);
}
20 changes: 19 additions & 1 deletion packages/uniforms-bootstrap5/__tests__/AutoFields.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { AutoFields } from 'uniforms-bootstrap5';
import { AutoFields, AutoField } from 'uniforms-bootstrap5';

import createContext from './_createContext';
import mount from './_mount';
Expand Down Expand Up @@ -86,3 +86,21 @@ test('<AutoFields> - wraps fields in specified element', () => {

expect(wrapper.find('section').find('input')).toHaveLength(3);
});

test('<AutoFields> - pass props to the children', () => {
const element = <AutoFields showInlineError />;
const wrapper = mount(
element,
createContext({
x: { type: String },
y: { type: String },
z: { type: String },
}),
);

const hasShowInlineErrorMap = wrapper
.find(AutoField)
.map(node => node.prop('showInlineError'));
expect(hasShowInlineErrorMap).toHaveLength(3);
expect(hasShowInlineErrorMap).toBeTruthy();
});
12 changes: 11 additions & 1 deletion packages/uniforms-bootstrap5/src/AutoFields.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@ export type AutoFieldsProps = {
element?: ComponentType | string;
fields?: string[];
omitFields?: string[];
showInlineError?: boolean;
};

export default function AutoFields({
autoField = AutoField,
element = 'div',
fields,
omitFields = [],
showInlineError,
...props
}: AutoFieldsProps) {
const { schema } = useForm();
Expand All @@ -24,6 +26,14 @@ export default function AutoFields({
props,
(fields ?? schema.getSubfields())
.filter(field => !omitFields.includes(field))
.map(field => createElement(autoField, { key: field, name: field })),
.map(field =>
createElement(
autoField,
Object.assign(
{ key: field, name: field },
showInlineError === undefined ? null : { showInlineError },
),
),
),
);
}
20 changes: 19 additions & 1 deletion packages/uniforms-material/__tests__/AutoFields.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { AutoFields } from 'uniforms-material';
import { AutoField, AutoFields } from 'uniforms-material';

import createContext from './_createContext';
import mount from './_mount';
Expand Down Expand Up @@ -86,3 +86,21 @@ test('<AutoFields> - wraps fields in specified element', () => {

expect(wrapper.find('section').find('input')).toHaveLength(3);
});

test('<AutoFields> - pass props to the children', () => {
const element = <AutoFields showInlineError />;
const wrapper = mount(
element,
createContext({
x: { type: String },
y: { type: String },
z: { type: String },
}),
);

const hasShowInlineErrorMap = wrapper
.find(AutoField)
.map(node => node.prop('showInlineError'));
expect(hasShowInlineErrorMap).toHaveLength(3);
expect(hasShowInlineErrorMap).toBeTruthy();
});
12 changes: 11 additions & 1 deletion packages/uniforms-material/src/AutoFields.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@ export type AutoFieldsProps = {
element?: ComponentType | string;
fields?: string[];
omitFields?: string[];
showInlineError?: boolean;
};

export default function AutoFields({
autoField = AutoField,
element = 'div',
fields,
omitFields = [],
showInlineError,
...props
}: AutoFieldsProps) {
const { schema } = useForm();
Expand All @@ -24,6 +26,14 @@ export default function AutoFields({
props,
(fields ?? schema.getSubfields())
.filter(field => !omitFields.includes(field))
.map(field => createElement(autoField, { key: field, name: field })),
.map(field =>
createElement(
autoField,
Object.assign(
{ key: field, name: field },
showInlineError === undefined ? null : { showInlineError },
),
),
),
);
}
20 changes: 19 additions & 1 deletion packages/uniforms-semantic/__tests__/AutoFields.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { AutoFields } from 'uniforms-semantic';
import { AutoField, AutoFields } from 'uniforms-semantic';

import createContext from './_createContext';
import mount from './_mount';
Expand Down Expand Up @@ -86,3 +86,21 @@ test('<AutoFields> - wraps fields in specified element', () => {

expect(wrapper.find('section').find('input')).toHaveLength(3);
});

test('<AutoFields> - pass props to the children', () => {
const element = <AutoFields showInlineError />;
const wrapper = mount(
element,
createContext({
x: { type: String },
y: { type: String },
z: { type: String },
}),
);

const hasShowInlineErrorMap = wrapper
.find(AutoField)
.map(node => node.prop('showInlineError'));
expect(hasShowInlineErrorMap).toHaveLength(3);
expect(hasShowInlineErrorMap).toBeTruthy();
});
12 changes: 11 additions & 1 deletion packages/uniforms-semantic/src/AutoFields.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@ export type AutoFieldsProps = {
element?: ComponentType | string;
fields?: string[];
omitFields?: string[];
showInlineError?: boolean;
};

export default function AutoFields({
autoField = AutoField,
element = 'div',
fields,
omitFields = [],
showInlineError,
...props
}: AutoFieldsProps) {
const { schema } = useForm();
Expand All @@ -24,6 +26,14 @@ export default function AutoFields({
props,
(fields ?? schema.getSubfields())
.filter(field => !omitFields.includes(field))
.map(field => createElement(autoField, { key: field, name: field })),
.map(field =>
createElement(
autoField,
Object.assign(
{ key: field, name: field },
showInlineError === undefined ? null : { showInlineError },
),
),
),
);
}

0 comments on commit 6b1e3b2

Please sign in to comment.