From 6aee08b3bebdbdb1320c4f18382b28d5bc474dd7 Mon Sep 17 00:00:00 2001 From: Ben Jenkinson <59176+BenJenkinson@users.noreply.github.com> Date: Thu, 19 May 2022 12:09:50 +0100 Subject: [PATCH] fix(#2521): fix `form-check-label`/`form-label` class on Label --- src/Label.js | 6 +++++- src/__tests__/Label.spec.js | 18 ++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/Label.js b/src/Label.js index b6c5ffe00..902b40de0 100644 --- a/src/Label.js +++ b/src/Label.js @@ -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 ( diff --git a/src/__tests__/Label.spec.js b/src/__tests__/Label.spec.js index 4aef120a0..7ef2484f4 100644 --- a/src/__tests__/Label.spec.js +++ b/src/__tests__/Label.spec.js @@ -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(); + + expect(wrapper.hasClass("form-label")).toBe(false); + }); + it('should render with "form-label" class when a col is not provided', () => { const wrapper = shallow(); expect(wrapper.hasClass('form-label')).toBe(true); }); + it('should render with "form-check-label" class when check is specified', () => { + const wrapper = shallow(); + + expect(wrapper.hasClass("form-check-label")).toBe(true); + }); + + it('should not render with "form-label" class when check is specified', () => { + const wrapper = shallow(); + + expect(wrapper.hasClass("form-label")).toBe(false); + }); + it('should pass col size specific classes as Strings', () => { const wrapper = shallow();