diff --git a/examples/Bootstrap4/App.jsx b/examples/Bootstrap4/App.jsx index ffbb9cec..e63356ab 100644 --- a/examples/Bootstrap4/App.jsx +++ b/examples/Bootstrap4/App.jsx @@ -3,8 +3,8 @@ import * as React from 'react'; import * as ReactDOM from 'react-dom'; -import { FormWithConstraints, FieldFeedback } from '../../src/index'; -import { FieldFeedbacks, FormGroup, FormControlLabel, FormControlInput } from '../../src/Bootstrap4'; +import { FormWithConstraints, FieldFeedbacks } from '../../src/index'; +import { FieldFeedback, FormGroup, FormControlLabel, FormControlInput } from '../../src/Bootstrap4'; import './index.html'; diff --git a/src/Bootstrap4.tsx b/src/Bootstrap4.tsx index 6737062d..025f3bfd 100644 --- a/src/Bootstrap4.tsx +++ b/src/Bootstrap4.tsx @@ -3,7 +3,7 @@ import * as PropTypes from 'prop-types'; import { Input, FormWithConstraintsChildContext, - FieldFeedbacks as FieldFeedbacks_, FieldFeedbacksProps + FieldFeedback as FieldFeedback_, FieldFeedbackProps } from './index'; export interface FormGroupProps extends React.HTMLAttributes { @@ -132,12 +132,12 @@ export class FormControlInput extends React.Component { } -const FieldFeedbacks: React.SFC = props => { +const FieldFeedback: React.SFC = props => { const { className, children, ...other } = props; const classes = className !== undefined ? `${className} form-control-feedback` : 'form-control-feedback'; - return {children}; + return {children}; }; -export { FieldFeedbacks }; +export { FieldFeedback }; export interface LabelWithFormControlStyleProps extends React.LabelHTMLAttributes { diff --git a/src/Enzyme.test.tsx b/src/Enzyme.test.tsx index e0782507..12612ae7 100644 --- a/src/Enzyme.test.tsx +++ b/src/Enzyme.test.tsx @@ -26,9 +26,9 @@ test('with Bootstrap4', () => {
- + - +
); diff --git a/src/Enzyme.ts b/src/Enzyme.ts index c78eb97d..6c49e69f 100644 --- a/src/Enzyme.ts +++ b/src/Enzyme.ts @@ -2,14 +2,13 @@ import * as React from 'react'; import { ShallowWrapper } from 'enzyme'; import { FieldFeedback, FieldFeedbackProps, FieldFeedbacks } from './index'; -import * as Bootstrap4 from './Bootstrap4'; // Return the list of FieldFeedback associated with an input name // Algorithm: find the FieldFeedbacks that matches the input name (for prop) and then return its children function findFieldFeedbackList(wrapper: ShallowWrapper<{}, {}>, inputName: string) { const fieldFeedbacksList = wrapper.findWhere(node => { let found = false; - if (node.type() === FieldFeedbacks || node.type() === Bootstrap4.FieldFeedbacks) { + if (node.type() === FieldFeedbacks) { if (node.prop('for') === inputName) { found = true; } diff --git a/src/FieldFeedbacks.test.tsx b/src/FieldFeedbacks.test.tsx index 5b1461ab..d9e5f212 100644 --- a/src/FieldFeedbacks.test.tsx +++ b/src/FieldFeedbacks.test.tsx @@ -211,7 +211,7 @@ describe('render()', () => { } }); expect(component.html()).toEqual( - '
Suffering from being missing
' + '
Suffering from being missing
' ); }); @@ -229,9 +229,7 @@ describe('render()', () => { expect(form.fieldsStore.fields).toEqual({ username: fieldWithoutFeedback }); - expect(component.html()).toEqual( - '
' - ); + expect(component.html()).toEqual(null); }); describe('show prop', () => { @@ -259,7 +257,7 @@ describe('render()', () => { }); expect(component.html()).toEqual( - '
Suffering from being missing
Suffering from being missing
Suffering from being missing
' + '
Suffering from being missing
Suffering from being missing
Suffering from being missing
' ); }); @@ -287,7 +285,7 @@ describe('render()', () => { }); expect(component.html()).toEqual( - '
Suffering from being missing
' + '
Suffering from being missing
' ); }); @@ -315,7 +313,7 @@ describe('render()', () => { }); expect(component.html()).toEqual( - '
Suffering from being missing
Suffering from being missing
' + '
Suffering from being missing
Suffering from being missing
' ); }); }); @@ -343,13 +341,11 @@ describe('reRender()', () => { } }); expect(component.html()).toEqual( - '
Suffering from being missing
' + '
Suffering from being missing
' ); form.fieldsStore.updateField('username', fieldWithoutFeedback); - expect(component.html()).toEqual( - '
' - ); + expect(component.html()).toEqual(null); }); test('unknown field updated', () => { @@ -373,7 +369,7 @@ describe('reRender()', () => { } }); expect(component.html()).toEqual( - '
Suffering from being missing
' + '
Suffering from being missing
' ); const assert = console.assert; @@ -387,7 +383,7 @@ describe('reRender()', () => { console.assert = assert; expect(component.html()).toEqual( - '
Suffering from being missing
' + '
Suffering from being missing
' ); }); }); diff --git a/src/FieldFeedbacks.tsx b/src/FieldFeedbacks.tsx index 5408e82c..a6d33d92 100644 --- a/src/FieldFeedbacks.tsx +++ b/src/FieldFeedbacks.tsx @@ -7,7 +7,7 @@ import { EventEmitter } from './EventEmitter'; // FIXME See https://github.com/M import Input from './Input'; import { FieldEvent } from './FieldsStore'; -export interface FieldFeedbacksProps extends React.HTMLAttributes { +export interface FieldFeedbacksProps { for: string; /** @@ -116,7 +116,7 @@ export class FieldFeedbacks extends withValidateEventEmitter(FieldFeedbacksCompo } render() { - const { for: fieldName, show, children, ...divProps } = this.props; - return
{children}
; + const { children } = this.props; + return children !== undefined ? children : null; } }