Skip to content

Commit

Permalink
chore(FormField): Converting to foundation component #210 #194
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesmfriedman committed May 2, 2018
1 parent 86fa087 commit 495fda3
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 13 deletions.
2 changes: 2 additions & 0 deletions .vscode/cSpell.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"fabs",
"lastrow",
"listbox",
"mdc's",
"refname",
"reinit",
"rmwc",
Expand All @@ -24,6 +25,7 @@
"Textfield",
"truthy",
"unelevated",
"unminified",
"unmounting"
],
// flagWords - list of words to be always considered incorrect
Expand Down
2 changes: 2 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"fabs",
"lastrow",
"listbox",
"mdc's",
"refname",
"reinit",
"rmwc",
Expand All @@ -22,6 +23,7 @@
"submenu",
"truthy",
"unelevated",
"unminified",
"unmounting"
]
}
17 changes: 17 additions & 0 deletions src/FormField/form-field-ssr.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/**
* @jest-environment node
*/
import React from 'react';
import { renderToString as mount } from 'react-dom/server';
import { FormField } from './';

describe('FormField SSR', () => {
test('renders', () => {
mount(
<FormField>
<input type="checkbox" id="input" />
<label htmlFor="input">Input Label</label>
</FormField>
);
});
});
14 changes: 14 additions & 0 deletions src/FormField/form-field.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import React from 'react';
import { mount } from 'enzyme';
import { FormField } from './';

describe('FormField', () => {
test('renders', () => {
mount(
<FormField>
<input type="checkbox" id="input" />
<label htmlFor="input">Input Label</label>
</FormField>
);
});
});
26 changes: 13 additions & 13 deletions src/FormField/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
// @flow
import * as React from 'react';
import { MDCFormField } from '@material/form-field/dist/mdc.formField';
import { simpleTag, withMDC } from '../Base';
import { simpleTag } from '../Base';
import { withFoundation } from '../Base/MDCFoundation';

type FormFieldRootPropsT = {
/** Position the input after the label. */
Expand All @@ -24,18 +25,17 @@ export const FormFieldRoot: React.ComponentType<
consumeProps: ['alignEnd']
});

export const FormField = withMDC({
mdcConstructor: MDCFormField,
mdcElementRef: true
})(
class extends React.Component<FormFieldRootPropsT> {
static displayName = 'FormField';
render() {
//$FlowFixMe
const { mdcElementRef, ...rest } = this.props;
return <FormFieldRoot elementRef={mdcElementRef} {...rest} />;
}
export class FormField extends withFoundation({
constructor: MDCFormField,
adapter: {}
})<FormFieldRootPropsT> {
static displayName = 'FormField';
render() {
//$FlowFixMe
const { ...rest } = this.props;
const { root_ } = this.foundationRefs;
return <FormFieldRoot {...rest} elementRef={root_} />;
}
);
}

export default FormField;

0 comments on commit 495fda3

Please sign in to comment.