Skip to content

Commit

Permalink
Added logic to disable the 'Edit item...' <ButtonWidget> when the num…
Browse files Browse the repository at this point in the history
…ber of items selected via checkboxes is any number other than 1, and to disable the 'Remove item...' <ButtonWidget> when the number of selected items is 0.
  • Loading branch information
maratbn committed Aug 5, 2018
1 parent 9ebd9ca commit 9b0124f
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions webpack_in/entry.jsx
Expand Up @@ -26,13 +26,15 @@ class ButtonWidget extends React.Component {
render() {
return (
<button style={{ margin: '1em'}}
disabled={ this.props.isDisabled }
onClick={ this.props.onClick }>{ this.props.caption }</button>
);
}
}

ButtonWidget.propTypes = {
caption: PropTypes.string.isRequired,
isDisabled: PropTypes.bool,
onClick: PropTypes.func
};

Expand Down Expand Up @@ -131,6 +133,8 @@ class ListWidget extends React.Component {
}

render() {
const arrItemsSelected = this.state.items.filter(objItem => objItem.is_checked);

return (
<div style={ objStyleCommon }>
<div style={ objStyleContent }>
Expand Down Expand Up @@ -163,8 +167,10 @@ class ListWidget extends React.Component {
this.setState(this._mutateStateToAddItem(this.state,
strItemNew));
}}/>
<ButtonWidget caption="Edit item..." />
<ButtonWidget caption="Remove item..." />
<ButtonWidget caption="Edit item..."
isDisabled={ arrItemsSelected.length !== 1 }/>
<ButtonWidget caption="Remove item..."
isDisabled={ arrItemsSelected.length === 0 }/>
</div>
</div>
);
Expand Down

0 comments on commit 9b0124f

Please sign in to comment.