Skip to content

Commit

Permalink
Merge pull request #422 from appfolio/correctFormRowWidth
Browse files Browse the repository at this point in the history
Correct FormRow and FormLabelGroup width
  • Loading branch information
gthomas-appfolio authored Jun 19, 2018
2 parents ab2490a + a607e14 commit 2b80c81
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 8 deletions.
12 changes: 7 additions & 5 deletions src/components/Alert.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export default class AlertComponent extends React.Component {
}

static defaultProps = {
className: '',
color: 'warning',
dismissible: false,
icon: false
Expand All @@ -35,23 +36,24 @@ export default class AlertComponent extends React.Component {
};
}

componentWillReceiveProps() {
this.setState({ visible: true });
}

toggle = () => {
this.setState({ visible: !this.state.visible });
}

componentWillReceiveProps() {
this.setState({ visible: true });
}

render() {
const { color, children, className, dismissible, icon } = this.props;
const { color, children, className, dismissible, icon, ...props } = this.props;

return (
<Alert
color={color}
isOpen={this.state.visible}
toggle={dismissible ? this.toggle : null}
className={className}
{...props}
>
<div className="d-flex align-items-start">
{icon ? <Icon name={ICON_MAP[color]} size="lg" className="mr-3 mt-1" /> : null}
Expand Down
2 changes: 1 addition & 1 deletion src/components/FormLabelGroup.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const FormLabelGroup = (props) => {
const rowColor = color || (feedback && 'danger');
const labelWidth = stacked ? 12 : 3;
const labelAlignment = stacked ? '' : 'text-sm-right';
const inputContainerWidth = stacked ? 12 : 9;
const inputContainerWidth = (stacked || !label) ? 12 : 9;

return (
<FormGroup row className={rowClassName} color={rowColor}>
Expand Down
2 changes: 1 addition & 1 deletion src/components/FormRow.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ const FormRow = (props) => {
const labelWidth = stacked ? 12 : 3;
const labelAlignment = stacked ? '' : 'text-sm-right';

const inputContainerWidth = stacked ? 12 : 9;
const inputContainerWidth = (stacked || !label) ? 12 : 9;

// TODO this should use FormLabelGroup vs duplicated code here:
return (
Expand Down
8 changes: 7 additions & 1 deletion test/components/FormLabelGroup.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ describe('<FormLabelGroup />', () => {

it('should have an outer column for the row where the children are rendered', () => {
const col = component.find(Col).at(0);
assert.equal(col.prop('sm'), 9);
assert.equal(col.prop('sm'), 12);
});

it('should have an inner column wrapping the children', () => {
Expand Down Expand Up @@ -75,6 +75,12 @@ describe('<FormLabelGroup />', () => {
const star = label.find('Required');
assert.equal(star.length, 1);
});

it('should have an outer column for the row where the children are rendered', () => {
const component = shallow(<FormLabelGroup {...props} required>Hello World</FormLabelGroup>);
const col = component.find(Col).at(0);
assert.equal(col.prop('sm'), 9);
});
});

describe('with a node label', () => {
Expand Down

0 comments on commit 2b80c81

Please sign in to comment.