Skip to content

Commit 9b0124f

Browse files
committed
Added logic to disable the 'Edit item...' <ButtonWidget> when the number 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.
1 parent 9ebd9ca commit 9b0124f

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

‎webpack_in/entry.jsx‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,15 @@ class ButtonWidget extends React.Component {
2626
render() {
2727
return (
2828
<button style={{ margin: '1em'}}
29+
disabled={ this.props.isDisabled }
2930
onClick={ this.props.onClick }>{ this.props.caption }</button>
3031
);
3132
}
3233
}
3334

3435
ButtonWidget.propTypes = {
3536
caption: PropTypes.string.isRequired,
37+
isDisabled: PropTypes.bool,
3638
onClick: PropTypes.func
3739
};
3840

@@ -131,6 +133,8 @@ class ListWidget extends React.Component {
131133
}
132134

133135
render() {
136+
const arrItemsSelected = this.state.items.filter(objItem => objItem.is_checked);
137+
134138
return (
135139
<div style={ objStyleCommon }>
136140
<div style={ objStyleContent }>
@@ -163,8 +167,10 @@ class ListWidget extends React.Component {
163167
this.setState(this._mutateStateToAddItem(this.state,
164168
strItemNew));
165169
}}/>
166-
<ButtonWidget caption="Edit item..." />
167-
<ButtonWidget caption="Remove item..." />
170+
<ButtonWidget caption="Edit item..."
171+
isDisabled={ arrItemsSelected.length !== 1 }/>
172+
<ButtonWidget caption="Remove item..."
173+
isDisabled={ arrItemsSelected.length === 0 }/>
168174
</div>
169175
</div>
170176
);

0 commit comments

Comments
 (0)