Skip to content

Commit 4d0c250

Browse files
Add bootstrap 4 compatibility for radios and checkboxes
1 parent 04f3a7c commit 4d0c250

File tree

2 files changed

+41
-37
lines changed

2 files changed

+41
-37
lines changed

src/components/widgets/CheckboxesWidget.js

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -22,32 +22,34 @@ function CheckboxesWidget(props) {
2222
const checked = value.indexOf(option.value) !== -1;
2323
const disabledCls = disabled || readonly ? "disabled" : "";
2424
const checkbox = (
25-
<span>
26-
<input
27-
type="checkbox"
28-
id={`${id}_${index}`}
29-
checked={checked}
30-
disabled={disabled || readonly}
31-
autoFocus={autofocus && index === 0}
32-
onChange={event => {
33-
const all = enumOptions.map(({ value }) => value);
34-
if (event.target.checked) {
35-
onChange(selectValue(option.value, value, all));
36-
} else {
37-
onChange(deselectValue(option.value, value));
38-
}
39-
}}
40-
/>
41-
<span>{option.label}</span>
42-
</span>
25+
<input
26+
className="form-check-input"
27+
type="checkbox"
28+
id={`${id}_${index}`}
29+
checked={checked}
30+
disabled={disabled || readonly}
31+
autoFocus={autofocus && index === 0}
32+
onChange={event => {
33+
const all = enumOptions.map(({ value }) => value);
34+
if (event.target.checked) {
35+
onChange(selectValue(option.value, value, all));
36+
} else {
37+
onChange(deselectValue(option.value, value));
38+
}
39+
}}
40+
/>
4341
);
4442
return inline
45-
? <label key={index} className={`checkbox-inline ${disabledCls}`}>
43+
? <label
44+
key={index}
45+
className={`checkbox-inline form-check form-check-label form-check-inline ${disabledCls}`}>
4646
{checkbox}
47+
<span>{option.label}</span>
4748
</label>
48-
: <div key={index} className={`checkbox ${disabledCls}`}>
49-
<label>
49+
: <div key={index} className={`checkbox form-check ${disabledCls}`}>
50+
<label className="form-check-label">
5051
{checkbox}
52+
<span>{option.label}</span>
5153
</label>
5254
</div>;
5355
})}

src/components/widgets/RadioWidget.js

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -22,28 +22,30 @@ function RadioWidget(props) {
2222
const checked = option.value === value;
2323
const disabledCls = disabled || readonly ? "disabled" : "";
2424
const radio = (
25-
<span>
26-
<input
27-
type="radio"
28-
checked={checked}
29-
name={name}
30-
required={required}
31-
value={option.value}
32-
disabled={disabled || readonly}
33-
autoFocus={autofocus && i === 0}
34-
onChange={_ => onChange(option.value)}
35-
/>
36-
<span>{option.label}</span>
37-
</span>
25+
<input
26+
className="form-check-input"
27+
type="radio"
28+
checked={checked}
29+
name={name}
30+
required={required}
31+
value={option.value}
32+
disabled={disabled || readonly}
33+
autoFocus={autofocus && i === 0}
34+
onChange={_ => onChange(option.value)}
35+
/>
3836
);
3937

4038
return inline
41-
? <label key={i} className={`radio-inline ${disabledCls}`}>
39+
? <label
40+
key={i}
41+
className={`radio-inline form-check form-check-label form-check-inline ${disabledCls}`}>
4242
{radio}
43+
<span>{option.label}</span>
4344
</label>
44-
: <div key={i} className={`radio ${disabledCls}`}>
45-
<label>
45+
: <div key={i} className={`radio form-check ${disabledCls}`}>
46+
<label className="form-check-label">
4647
{radio}
48+
<span>{option.label}</span>
4749
</label>
4850
</div>;
4951
})}

0 commit comments

Comments
 (0)