Skip to content

Commit a485f5b

Browse files
authored
Merge pull request #261 from puppetlabs/tasks/add-formfield-class
Add `innerClassName` prop to Form.Field
2 parents 43a78e6 + 780a665 commit a485f5b

File tree

3 files changed

+27
-14
lines changed

3 files changed

+27
-14
lines changed

packages/react-components/source/react/library/form/FormField.js

+17-12
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ const propTypes = {
4343
onChange: PropTypes.func,
4444
/** Optional additional className */
4545
className: PropTypes.string,
46+
/** Optional additional className for inner field */
47+
innerClassName: PropTypes.string,
4648
/** Optional additional inline styles */
4749
style: PropTypes.shape({}),
4850
/** All additional props are propagated to the inner input elements. See each option for details. TODO: figure out how to get this set up in styleguidist */
@@ -62,6 +64,7 @@ const defaultProps = {
6264
inlineLabelWidth: null,
6365
onChange() {},
6466
className: '',
67+
innerClassName: '',
6568
style: {},
6669
};
6770

@@ -70,15 +73,16 @@ const defaultProps = {
7073
*/
7174
export const formInputInterface = omit(
7275
[
73-
'requiredFieldMessage',
74-
'validateOnLoad',
75-
'validator',
7676
'className',
7777
'description',
78-
'style',
79-
'labelType',
8078
'inline',
8179
'inlineLabelWidth',
80+
'innerClassName',
81+
'labelType',
82+
'requiredFieldMessage',
83+
'style',
84+
'validateOnLoad',
85+
'validator',
8286
],
8387
propTypes,
8488
);
@@ -108,23 +112,24 @@ const getFieldStyle = (style, inlineLabelWidth, tabbed) => {
108112

109113
const FormField = props => {
110114
const {
111-
type,
112-
name,
113-
label,
114-
labelType,
115115
className,
116+
description,
117+
error,
118+
innerClassName,
116119
inline,
117120
inlineLabelWidth,
118-
error,
119-
description,
121+
label,
122+
labelType,
123+
name,
120124
style,
125+
type,
121126
} = props;
122127
const typeName = getTypeName(type);
123128
const tabbed = inline && (type === 'checkbox' || type === 'switch');
124129
const labelStyle = getLabelStyle(inlineLabelWidth, inline);
125130
const fieldStyle = getFieldStyle(style, inlineLabelWidth, tabbed);
126131

127-
const element = <FormFieldElement {...props} />;
132+
const element = <FormFieldElement {...props} className={innerClassName} />;
128133

129134
if (type === 'hidden') {
130135
return element;

packages/react-components/source/react/library/form/internal/FormFieldElement.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,11 @@ const FormFieldElement = props => {
5151

5252
const elementProps = omit(
5353
[
54+
'description',
5455
'inline',
5556
'inlineLabelWidth',
57+
'innerClassName',
5658
'labelType',
57-
'description',
58-
'className',
5959
'style',
6060
'requiredFieldMessage',
6161
'validateOnLoad',

packages/react-components/test/form/FormField.js

+8
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,14 @@ describe('<FormField />', () => {
9595
);
9696
});
9797

98+
it('applies an innerClassName to the inner input element', () => {
99+
expect(
100+
mount(<FormField {...requiredProps} innerClassName="hello-world" />).find(
101+
Input,
102+
),
103+
).to.have.prop('className', 'hello-world');
104+
});
105+
98106
it('renders an Input for all Input supported types', () => {
99107
INPUT_SUPPORTED_TYPES.forEach(type => {
100108
expect(

0 commit comments

Comments
 (0)