Skip to content

Commit 6aee08b

Browse files
BenJenkinsondavidacevedo
authored andcommitted
fix(reactstrap#2521): fix form-check-label/form-label class on Label
1 parent f37b25e commit 6aee08b

2 files changed

Lines changed: 23 additions & 1 deletion

File tree

src/Label.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,13 +93,17 @@ const Label = (props) => {
9393
}
9494
});
9595

96+
const colFormLabel = size || colClasses.length;
97+
const formLabel = !(check || colFormLabel);
98+
9699
const classes = mapToCssModules(classNames(
97100
className,
98101
hidden ? 'visually-hidden' : false,
99102
check ? 'form-check-label' : false,
100103
size ? `col-form-label-${size}` : false,
101104
colClasses,
102-
colClasses.length ? 'col-form-label' : 'form-label'
105+
colFormLabel ? 'col-form-label' : false,
106+
formLabel ? 'form-label' : false
103107
), cssModule);
104108

105109
return (

src/__tests__/Label.spec.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,30 @@ describe('Label', () => {
2727
expect(wrapper.hasClass('col-form-label')).toBe(true);
2828
});
2929

30+
it('should not render with "form-label" class when a col is provided', () => {
31+
const wrapper = shallow(<Label sm="6">Yo!</Label>);
32+
33+
expect(wrapper.hasClass("form-label")).toBe(false);
34+
});
35+
3036
it('should render with "form-label" class when a col is not provided', () => {
3137
const wrapper = shallow(<Label>Yo!</Label>);
3238

3339
expect(wrapper.hasClass('form-label')).toBe(true);
3440
});
3541

42+
it('should render with "form-check-label" class when check is specified', () => {
43+
const wrapper = shallow(<Label check>Yo!</Label>);
44+
45+
expect(wrapper.hasClass("form-check-label")).toBe(true);
46+
});
47+
48+
it('should not render with "form-label" class when check is specified', () => {
49+
const wrapper = shallow(<Label check>Yo!</Label>);
50+
51+
expect(wrapper.hasClass("form-label")).toBe(false);
52+
});
53+
3654
it('should pass col size specific classes as Strings', () => {
3755
const wrapper = shallow(<Label sm="6">Yo!</Label>);
3856

0 commit comments

Comments
 (0)