Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add disabled class to outer field wrapper #557

Merged
merged 2 commits into from
Jun 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions .storybook/styles/components/_forms.scss
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,14 @@ select{
}
}

/*-----------------------
Radio
-----------------------*/
.RadioGroup {
label {
cursor: pointer;
}
}

/*-----------------------
Checkbox
Expand Down Expand Up @@ -197,6 +205,19 @@ input[type="checkbox"]{
}
}

/*-----------------------
Disabled
-----------------------*/

.disabled {
label {
cursor: default;
}

input[type="checkbox"], input[type="radio"] {
cursor: not-allowed;
}
}

/*-----------------------
Error
Expand Down
7 changes: 6 additions & 1 deletion src/forms/labels/labeled-field.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,12 @@ function LabeledField ({
const { name } = input
const { touched, invalid } = meta
return (
<fieldset className={ classnames(className, { 'error': hasInputError({ touched, invalid }) }) }>
<fieldset
className={classnames(className, {
'error': hasInputError({ touched, invalid }),
'disabled': rest.disabled,
})
}>
<LabelComponent { ...{ name, id, label, ...rest } } />
{ children }
{ !hideErrorLabel && <ErrorComponent {...{ ...input, ...meta, ...rest }} /> }
Expand Down
8 changes: 8 additions & 0 deletions stories/forms/inputs/radio-group.story.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,11 @@ storiesOf('RadioGroup', module)
meta={{}}
/>
))
.add('with disabled options', () => (
<RadioGroup
input={inputProps}
meta={{}}
options={options}
disabled={true}
/>
))
7 changes: 7 additions & 0 deletions test/forms/labels/labeled-field.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@ test('adds error class when touched and invalid', () => {
expect(wrapper.find('fieldset').hasClass('error')).toEqual(true)
})

test('adds disabled class when disabled', () => {
const Wrapped = () => <input name="test"/>
const props = { input: { name: 'foo' }, meta: {}, disabled: true }
const wrapper = mount(<LabeledField { ...props } ><Wrapped /></LabeledField>)
expect(wrapper.find('fieldset').hasClass('disabled')).toEqual(true)
})

test('adds InputLabel and InputError', () => {
const Wrapped = () => <input name="test"/>
const props = { input: { name: 'foo' }, meta: { touched: true, invalid: true } }
Expand Down