Skip to content

Commit

Permalink
Fixed #962 - Add onTargetSelect and onSourceSelect props to Picklist
Browse files Browse the repository at this point in the history
  • Loading branch information
mertsincan committed Jul 19, 2019
1 parent 7beefe3 commit fec26e2
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions src/components/picklist/PickList.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ export class PickList extends Component {
onMoveToSource: null,
onMoveAllToSource: null,
onMoveToTarget: null,
onMoveAllToTarget: null
onMoveAllToTarget: null,
onSourceSelect: null,
onTargetSelect: null
}

static propTypes = {
Expand All @@ -53,6 +55,8 @@ export class PickList extends Component {
onMoveAllToSource: PropTypes.func,
onMoveToTarget: PropTypes.func,
onMoveAllToTarget: PropTypes.func,
onSourceSelect: PropTypes.func,
onTargetSelect: PropTypes.func
}

constructor(props) {
Expand Down Expand Up @@ -173,6 +177,14 @@ export class PickList extends Component {

DomHandler.scrollInView(listContainer, listItem);
}

onSelectionChange(e, stateKey, callback) {
this.setState({[stateKey]: e.value});

if (callback) {
callback(e);
}
}

componentDidUpdate() {
if(this.reorderedListElement) {
Expand All @@ -192,13 +204,13 @@ export class PickList extends Component {
{this.props.showSourceControls && <PickListControls list={this.props.source} selection={this.state.selectedItemsSource}
onReorder={this.onSourceReorder} className="p-picklist-source-controls" />}

<PickListSubList ref={(el) => this.sourceListElement = ReactDOM.findDOMNode(el)} list={this.props.source} selection={this.state.selectedItemsSource} onSelectionChange={(e) => this.setState({selectedItemsSource: e.value})} itemTemplate={this.props.itemTemplate}
header={this.props.sourceHeader} style={this.props.sourceStyle} className="p-picklist-source-wrapper" listClassName="p-picklist-source" metaKeySelection={this.props.metaKeySelection} tabIndex={this.props.tabIndex} />
<PickListSubList ref={(el) => this.sourceListElement = ReactDOM.findDOMNode(el)} list={this.props.source} selection={this.state.selectedItemsSource} onSelectionChange={(e) => this.onSelectionChange(e, 'selectedItemsSource', this.props.onSourceSelect)} itemTemplate={this.props.itemTemplate}
header={this.props.sourceHeader} style={this.props.sourceStyle} className="p-picklist-source-wrapper" listClassName="p-picklist-source" metaKeySelection={this.props.metaKeySelection} tabIndex={this.props.tabIndex}/>

<PickListTransferControls onTransfer={this.onTransfer} source={this.props.source} target={this.props.target}
sourceSelection={this.state.selectedItemsSource} targetSelection={this.state.selectedItemsTarget} />

<PickListSubList ref={(el) => this.targetListElement = ReactDOM.findDOMNode(el)} list={this.props.target} selection={this.state.selectedItemsTarget} onSelectionChange={(e) => this.setState({selectedItemsTarget: e.value})} itemTemplate={this.props.itemTemplate}
<PickListSubList ref={(el) => this.targetListElement = ReactDOM.findDOMNode(el)} list={this.props.target} selection={this.state.selectedItemsTarget} onSelectionChange={(e) => this.onSelectionChange(e, 'selectedItemsTarget', this.props.onTargetSelect)} itemTemplate={this.props.itemTemplate}
header={this.props.targetHeader} style={this.props.targetStyle} className="p-picklist-target-wrapper" listClassName="p-picklist-targe" metaKeySelection={this.props.metaKeySelection} tabIndex={this.props.tabIndex}/>

{this.props.showTargetControls && <PickListControls list={this.props.target} selection={this.state.selectedItemsTarget}
Expand Down

0 comments on commit fec26e2

Please sign in to comment.