Skip to content

Commit

Permalink
fix(#2521): fix form-check-label/form-label class on Label
Browse files Browse the repository at this point in the history
  • Loading branch information
BenJenkinson authored and davidacevedo committed May 27, 2022
1 parent f37b25e commit 6aee08b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/Label.js
Expand Up @@ -93,13 +93,17 @@ const Label = (props) => {
}
});

const colFormLabel = size || colClasses.length;
const formLabel = !(check || colFormLabel);

const classes = mapToCssModules(classNames(
className,
hidden ? 'visually-hidden' : false,
check ? 'form-check-label' : false,
size ? `col-form-label-${size}` : false,
colClasses,
colClasses.length ? 'col-form-label' : 'form-label'
colFormLabel ? 'col-form-label' : false,
formLabel ? 'form-label' : false
), cssModule);

return (
Expand Down
18 changes: 18 additions & 0 deletions src/__tests__/Label.spec.js
Expand Up @@ -27,12 +27,30 @@ describe('Label', () => {
expect(wrapper.hasClass('col-form-label')).toBe(true);
});

it('should not render with "form-label" class when a col is provided', () => {
const wrapper = shallow(<Label sm="6">Yo!</Label>);

expect(wrapper.hasClass("form-label")).toBe(false);
});

it('should render with "form-label" class when a col is not provided', () => {
const wrapper = shallow(<Label>Yo!</Label>);

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

it('should render with "form-check-label" class when check is specified', () => {
const wrapper = shallow(<Label check>Yo!</Label>);

expect(wrapper.hasClass("form-check-label")).toBe(true);
});

it('should not render with "form-label" class when check is specified', () => {
const wrapper = shallow(<Label check>Yo!</Label>);

expect(wrapper.hasClass("form-label")).toBe(false);
});

it('should pass col size specific classes as Strings', () => {
const wrapper = shallow(<Label sm="6">Yo!</Label>);

Expand Down

0 comments on commit 6aee08b

Please sign in to comment.