Skip to content

Commit

Permalink
Added closeOnChange prop (#74)
Browse files Browse the repository at this point in the history
* Added closeOnChange prop
Useful if you want to implement a confirmation prompt after selection.
  • Loading branch information
LasseSLambertsen authored and peacechen committed Jul 16, 2018
1 parent 9569611 commit 931de35
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ Prop | Type | Optional | Default | Description
`keyExtractor`      | function | Yes     | (data) => data.key   | extract the key from the data item
`labelExtractor`    | function | Yes     | (data) => data.label | extract the label from the data item
`visible` | bool | Yes | false | control open/close state of modal
`closeOnChange`´ | bool | Yes | true | control if modal closes on select
`initValue` | string | Yes | `Select me!` | text that is initially shown on the button
`cancelText` | string | Yes | `cancel` | text of the cancel button
`animationType` | string | Yes | `slide` | type of animation to be used to show the modal. Must be one of `none`, `slide` or `fade`.
Expand Down
6 changes: 5 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const propTypes = {
keyExtractor: PropTypes.func,
labelExtractor: PropTypes.func,
visible: PropTypes.bool,
closeOnChange: PropTypes.bool,
initValue: PropTypes.string,
animationType: Modal.propTypes.animationType,
style: ViewPropTypes.style,
Expand Down Expand Up @@ -65,6 +66,7 @@ const defaultProps = {
keyExtractor: (item) => item.key,
labelExtractor: (item) => item.label,
visible: false,
closeOnChange: true,
initValue: 'Select me!',
animationType: 'slide',
style: {},
Expand Down Expand Up @@ -129,7 +131,9 @@ export default class ModalSelector extends React.Component {
this.props.onChange(item);
}
this.setState({ selected: this.props.labelExtractor(item), changedItem: item });
this.close();

if (this.props.closeOnChange)
this.close();
}

close = () => {
Expand Down

0 comments on commit 931de35

Please sign in to comment.