Skip to content

Commit

Permalink
Allow local disabled prop override
Browse files Browse the repository at this point in the history
  • Loading branch information
kouak committed Jan 7, 2017
1 parent da8133c commit 4ac6af5
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/FormsyAutoComplete.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,14 @@ const FormsyAutoComplete = React.createClass({
...rest } = this.props;
return (
<AutoComplete
disabled={this.isFormDisabled()}
{...rest}
errorText={this.getErrorMessage()}
onBlur={this.handleBlur}
onChange={this.handleChange}
onFocus={onFocus}
onKeyDown={this.handleKeyDown}
ref={this.setMuiComponentAndMaybeFocus}
disabled={this.isFormDisabled()}
value={this.state.value}
/>
);
Expand Down
2 changes: 1 addition & 1 deletion src/FormsyCheckbox.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ const FormsyCheckbox = React.createClass({
}
return (
<Checkbox
disabled={this.isFormDisabled()}
{...rest}
checked={value}
disabled={this.isFormDisabled()}
onCheck={this.handleChange}
ref={this.setMuiComponentAndMaybeFocus}
/>
Expand Down
2 changes: 1 addition & 1 deletion src/FormsyDate.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,12 @@ const FormsyDate = React.createClass({
const errorText = this.getErrorMessage() || isRequiredError;
return (
<DatePicker
disabled={this.isFormDisabled()}
{...rest}
errorText={errorText}
onChange={this.handleChange}
ref={this.setMuiComponentAndMaybeFocus}
value={this.getValue()}
disabled={this.isFormDisabled()}
/>
);
},
Expand Down
2 changes: 1 addition & 1 deletion src/FormsyRadioGroup.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,11 @@ const FormsyRadioGroup = React.createClass({

return (
<RadioButtonGroup
disabled={this.isFormDisabled()}
{...rest}
ref={this.setMuiComponentAndMaybeFocus}
onChange={this.handleValueChange}
valueSelected={this.getValue()}
disabled={this.isFormDisabled()}
defaultSelected={value}
>
{children}
Expand Down
2 changes: 1 addition & 1 deletion src/FormsySelect.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,11 @@ const FormsySelect = React.createClass({
const errorText = this.getErrorMessage() || isRequiredError;
return (
<SelectField
disabled={this.isFormDisabled()}
{...rest}
errorText={errorText}
onChange={this.handleChange}
ref={this.setMuiComponentAndMaybeFocus}
disabled={this.isFormDisabled()}
value={value}
>
{this.props.children}
Expand Down
2 changes: 1 addition & 1 deletion src/FormsyText.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -117,13 +117,13 @@ const FormsyText = React.createClass({

return (
<TextField
disabled={this.isFormDisabled()}
{...rest}
errorText={errorText}
onBlur={this.handleBlur}
onChange={this.handleChange}
onKeyDown={this.handleKeyDown}
ref={this.setMuiComponentAndMaybeFocus}
disabled={this.isFormDisabled()}
value={this.getValue()}
underlineStyle={this.state.isValid ? { color: this.validationColor() } : {}}
underlineFocusStyle={this.state.isValid ? { color: this.validationColor() } : {}}
Expand Down
2 changes: 1 addition & 1 deletion src/FormsyTime.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ const FormsyTime = React.createClass({

return (
<TimePicker
disabled={this.isFormDisabled()}
{...rest}
errorText={this.getErrorMessage()}
onChange={this.handleChange}
ref={this.setMuiComponentAndMaybeFocus}
disabled={this.isFormDisabled()}
value={this.getValue()}
/>
);
Expand Down
2 changes: 1 addition & 1 deletion src/FormsyToggle.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ const FormsyToggle = React.createClass({

return (
<Toggle
disabled={this.isFormDisabled()}
{...rest}
onToggle={this.handleChange}
ref={this.setMuiComponentAndMaybeFocus}
disabled={this.isFormDisabled()}
toggled={value}
/>
);
Expand Down
22 changes: 20 additions & 2 deletions test/test.FormsyText.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,10 +161,16 @@ describe('FormsyText', () => {

const inputDOM = wrapper.find('input').node;
expect(inputDOM.disabled).to.eq(true);

// Next, we set `disabled` to false and check the DOM node updates accordingly
wrapper.setProps({
disabled: false,
});
expect(inputDOM.disabled).to.eq(false);
});

it('allows overriding disabled status locally', () => {
const wrapper = mount(
let wrapper = mount(
<TestForm disabled={true}>
<FormsyText
name="text"
Expand All @@ -173,8 +179,20 @@ describe('FormsyText', () => {
</TestForm>
);

const inputDOM = wrapper.find('input').node;
let inputDOM = wrapper.find('input').node;
expect(inputDOM.disabled).to.eq(false);

wrapper = mount(
<TestForm disabled={false}>
<FormsyText
name="text"
disabled={true}
/>
</TestForm>
);

inputDOM = wrapper.find('input').node;
expect(inputDOM.disabled).to.eq(true);
});
});

Expand Down

0 comments on commit 4ac6af5

Please sign in to comment.