Skip to content

Commit 312b29e

Browse files
TheSharpieOneeddywashere
authored andcommitted
fix(label): add disabled class when form-check-inline and disabled (#159)
Adds the disabled class when the label has both the inline and check props. This is the way bootstrap disables inline radio and checkboxes since there is no wrapping element.
1 parent 4a8baf6 commit 312b29e

2 files changed

Lines changed: 21 additions & 0 deletions

File tree

src/Label.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ const propTypes = {
2121
hidden: PropTypes.bool,
2222
check: PropTypes.bool,
2323
inline: PropTypes.bool,
24+
disabled: PropTypes.bool,
2425
size: PropTypes.string,
2526
for: PropTypes.string,
2627
tag: PropTypes.string,
@@ -43,6 +44,7 @@ const Label = (props) => {
4344
tag: Tag,
4445
check,
4546
inline,
47+
disabled,
4648
size,
4749
for: htmlFor,
4850
...attributes,
@@ -70,6 +72,7 @@ const Label = (props) => {
7072
className,
7173
hidden ? 'sr-only' : false,
7274
check ? `form-check-${inline ? 'inline' : 'label'}` : false,
75+
check && inline && disabled ? 'disabled' : false,
7376
size ? `col-form-label-${size}` : false,
7477
colClasses,
7578
colClasses.length ? 'col-form-label' : false

src/__tests__/Label.spec.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,12 @@ describe('Label', () => {
5757
expect(wrapper.hasClass('form-check-inline')).toBe(false);
5858
});
5959

60+
it('should not render with "disabled" class when check and disabled props are truthy and inline is not', () => {
61+
const wrapper = shallow(<Label check disabled>Yo!</Label>);
62+
63+
expect(wrapper.hasClass('disabled')).toBe(false);
64+
});
65+
6066
it('should render with "form-check-inline" class when check and inline props are truthy', () => {
6167
const wrapper = shallow(<Label check inline>Yo!</Label>);
6268

@@ -69,12 +75,24 @@ describe('Label', () => {
6975
expect(wrapper.hasClass('form-check-label')).toBe(false);
7076
});
7177

78+
it('should not render with "disabled" class when check, inline, and disabled props are truthy', () => {
79+
const wrapper = shallow(<Label check inline disabled>Yo!</Label>);
80+
81+
expect(wrapper.hasClass('disabled')).toBe(true);
82+
});
83+
7284
it('should not render with "form-check-inline" class when inline prop is truthy and check is not', () => {
7385
const wrapper = shallow(<Label inline>Yo!</Label>);
7486

7587
expect(wrapper.hasClass('form-check-inline')).toBe(false);
7688
});
7789

90+
it('should not render with "disabled" class when inline and disabled props are truthy and check is not', () => {
91+
const wrapper = shallow(<Label inline disabled>Yo!</Label>);
92+
93+
expect(wrapper.hasClass('disabled')).toBe(false);
94+
});
95+
7896
it('should not render with "form-check-inline" nor "form-check-label" by default', () => {
7997
const wrapper = shallow(<Label>Yo!</Label>);
8098

0 commit comments

Comments
 (0)