Skip to content

Commit 8902c1b

Browse files
authored
Merge pull request #266 from rvsia/add-helpertext-to-single-checkbox
fix(pf3): add helpertext to single checkbox
2 parents c0f3941 + c542bf2 commit 8902c1b

File tree

3 files changed

+144
-2
lines changed

3 files changed

+144
-2
lines changed

packages/pf3-component-mapper/src/form-fields/form-fields.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,17 @@ const selectComponent = ({
2929
initialValue,
3030
loadOptions,
3131
meta,
32+
helperText,
3233
...rest
3334
}) => ({
3435
[componentTypes.TEXT_FIELD]: () =>
3536
<FormControl { ...input } placeholder={ placeholder } disabled={ isDisabled } readOnly={ isReadOnly } { ...rest } />,
3637
[componentTypes.TEXTAREA_FIELD]: () =>
3738
<FormControl { ...input } disabled={ isDisabled } readOnly={ isReadOnly } { ...rest } componentClass="textarea" placeholder={ placeholder }/>,
38-
[componentTypes.CHECKBOX]: () => <Checkbox { ...input } disabled={ isDisabled || isReadOnly }>{ label }</Checkbox>,
39+
[componentTypes.CHECKBOX]: () =>(<Checkbox { ...input } disabled={ isDisabled || isReadOnly }>
40+
{ label }
41+
{ helperText && <FieldLevelHelp content={ helperText } /> }
42+
</Checkbox>),
3943
[componentTypes.RADIO]: () => (
4044
<RagioGroup
4145
options={ options }
@@ -93,7 +97,7 @@ const FinalFormField = ({
9397
{ rest.isRequired ? <RequiredLabel label={ label } /> : label }
9498
{ helperText && <FieldLevelHelp content={ helperText } /> }
9599
</ControlLabel> }
96-
{ selectComponent({ ...rest, invalid, label, meta })() }
100+
{ selectComponent({ ...rest, invalid, label, meta, helperText })() }
97101
{ renderHelperText(invalid && meta.error, description) }
98102
</FormGroup>
99103
);

packages/pf3-component-mapper/src/tests/__snapshots__/form-fields.test.js.snap

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,136 @@ exports[`FormFields <CheckboxGroup /> should render single checkbox variant 1`]
6969
</CheckboxGroup>
7070
`;
7171

72+
exports[`FormFields <CheckboxGroup /> should render single checkbox variant with a helper text 1`] = `
73+
<CheckboxGroup
74+
FieldProvider={[Function]}
75+
helperText="Helper text"
76+
input={
77+
Object {
78+
"name": "single-check-box",
79+
}
80+
}
81+
meta={Object {}}
82+
>
83+
<FieldInterface
84+
FieldProvider={[Function]}
85+
componentType="checkbox"
86+
helperText="Helper text"
87+
input={
88+
Object {
89+
"name": "single-check-box",
90+
}
91+
}
92+
meta={Object {}}
93+
name="single-check-box"
94+
>
95+
<FinalFormField
96+
FieldProvider={[Function]}
97+
componentType="checkbox"
98+
helperText="Helper text"
99+
id="single-check-box"
100+
input={
101+
Object {
102+
"name": "single-check-box",
103+
}
104+
}
105+
meta={Object {}}
106+
name="single-check-box"
107+
noCheckboxLabel={true}
108+
>
109+
<FormGroup
110+
bsClass="form-group"
111+
validationState={null}
112+
>
113+
<div
114+
className="form-group"
115+
>
116+
<Checkbox
117+
bsClass="checkbox"
118+
disabled={false}
119+
inline={false}
120+
name="single-check-box"
121+
title=""
122+
>
123+
<div
124+
className="checkbox"
125+
>
126+
<label
127+
title=""
128+
>
129+
<input
130+
disabled={false}
131+
name="single-check-box"
132+
type="checkbox"
133+
/>
134+
<FieldLevelHelp
135+
buttonClass=""
136+
content="Helper text"
137+
placement="top"
138+
rootClose={true}
139+
>
140+
<OverlayTrigger
141+
defaultOverlayShown={false}
142+
overlay={
143+
<Popover
144+
bsClass="popover"
145+
id="popover"
146+
placement="right"
147+
>
148+
Helper text
149+
</Popover>
150+
}
151+
placement="top"
152+
rootClose={true}
153+
trigger={
154+
Array [
155+
"click",
156+
]
157+
}
158+
>
159+
<Button
160+
active={false}
161+
block={false}
162+
bsClass="btn"
163+
bsStyle="link"
164+
className="popover-pf-info"
165+
disabled={false}
166+
onClick={[Function]}
167+
>
168+
<button
169+
className="popover-pf-info btn btn-link"
170+
disabled={false}
171+
onClick={[Function]}
172+
type="button"
173+
>
174+
<Icon
175+
name="info"
176+
type="pf"
177+
>
178+
<PatternflyIcon
179+
className=""
180+
name="info"
181+
>
182+
<span
183+
aria-hidden="true"
184+
className="pficon pficon-info"
185+
/>
186+
</PatternflyIcon>
187+
</Icon>
188+
</button>
189+
</Button>
190+
</OverlayTrigger>
191+
</FieldLevelHelp>
192+
</label>
193+
</div>
194+
</Checkbox>
195+
</div>
196+
</FormGroup>
197+
</FinalFormField>
198+
</FieldInterface>
199+
</CheckboxGroup>
200+
`;
201+
72202
exports[`FormFields <Radio /> should render correctly 1`] = `
73203
<Radio
74204
FieldProvider={[Function]}

packages/pf3-component-mapper/src/tests/form-fields.test.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { SwitchField, CheckboxGroup, Radio, TextareaField, TextField } from '../
44
import { mount } from 'enzyme';
55
import MockFieldProvider from '../../../../__mocks__/mock-field-provider';
66
import MultipleChoiceList from '../form-fields/multiple-choice-list';
7+
import { FieldLevelHelp } from 'patternfly-react';
78

89
describe('FormFields', () => {
910
describe('<SwitchField />', () => {
@@ -111,6 +112,13 @@ describe('FormFields', () => {
111112
it('should render single checkbox variant', () => {
112113
const wrapper = mount(<CheckboxGroup { ...initialProps } />);
113114
expect(toJson(wrapper)).toMatchSnapshot();
115+
expect(wrapper.find(FieldLevelHelp)).toHaveLength(0);
116+
});
117+
118+
it('should render single checkbox variant with a helper text', () => {
119+
const wrapper = mount(<CheckboxGroup { ...initialProps } helperText="Helper text"/>);
120+
expect(toJson(wrapper)).toMatchSnapshot();
121+
expect(wrapper.find(FieldLevelHelp)).toHaveLength(1);
114122
});
115123

116124
it('should render multiple choice variant', () => {

0 commit comments

Comments
 (0)