Skip to content

Commit

Permalink
Merge pull request #15 from casufi/master
Browse files Browse the repository at this point in the history
Added prop searchIndex to allow to search by the label only
  • Loading branch information
stratos-vetsos authored Aug 6, 2018
2 parents 23191f5 + efc7397 commit 84ffb80
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 10 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ stayOpen | boolean | false | If the Select should stay open or not.
commaSeperated | boolean | false | If you want the selected values to be a comma seperated string, turn this to "true". ( Available only with multiple prop set to "true". )
singleLine | boolean | false | Where the selected values ( Select's Header ) should be contained to one line.
lifo | boolean | false | **Last In First Out Mode**. The user's last selection, goes first. ( Available only with multiple prop set to "true". )
searchIndex | boolean | true | Enable search by both Index and Value fields
selectAllButton | boolean | false | Whether a "select all button" should be visible on Select's header.
isDropDown | boolean | true | Set this to true if you want to use the Select as a **Dropdown**. When you select an option, the Select collapses and the header continue to have the placeholder as a value.
tags | boolean | false | Whether to support custom tags.
Expand Down
2 changes: 1 addition & 1 deletion dist/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-selectrix",
"version": "1.0.14",
"version": "1.0.15",
"description": "A beautiful, clean coded select replacement for React.js",
"main": "dist/index.js",
"scripts": {
Expand Down
7 changes: 4 additions & 3 deletions src/PlayGround.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ export default class PlayGround extends React.Component {

let options = [
{
key: 'a',
label: 'Option A'
key: 'a10',
label: 'Option A 10'
},
{
key: 'b',
key: 'b10',
label: 'Option B'
},
{
Expand Down Expand Up @@ -87,6 +87,7 @@ export default class PlayGround extends React.Component {
commaSeperated={ false }
singleLine={ false }
lifo={ false }
searchIndex={ false }
selectAllButton={ true }
height={ 190 }
checkBoxes={ false }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ export default class Searchable extends React.Component {

}

componentWillMount() {
UNSAFE_componentWillMount() {
this.calculateSize( this.props );
}

componentWillReceiveProps( nextProps ) {
UNSAFE_componentWillReceiveProps( nextProps ) {

if( nextProps.settings.multiple && ( this.props.queryString !== nextProps.queryString || this.props.selected.length !== nextProps.selected.length ) || this.props.settings.placeholder.length !== nextProps.settings.placeholder.length ) {
this.calculateSize( nextProps );
Expand Down
6 changes: 4 additions & 2 deletions src/components/Selectrix.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ export default class Selectrix extends React.Component {
} )
}

componentWillMount() {
UNSAFE_componentWillMount() {
this.props.setupInstance( this.props );
}

componentWillReceiveProps( nextProps ) {
UNSAFE_componentWillReceiveProps( nextProps ) {
this.props.updateInstance( nextProps );
}

Expand All @@ -56,6 +56,7 @@ Selectrix.defaultProps = {
defaultValue: false,
multiple: false,
disabled: false,
searchIndex: true,
onChange: () => {},
onOpen: () => {},
onClose: () => {},
Expand Down Expand Up @@ -97,6 +98,7 @@ Selectrix.propTypes = {
] ),
multiple: PropTypes.bool,
disabled: PropTypes.bool,
searchIndex: PropTypes.bool,
onChange: PropTypes.func,
customScrollbar: PropTypes.bool,
searchable: PropTypes.bool,
Expand Down
4 changes: 3 additions & 1 deletion src/reducers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const initialState = {
arrow: true,
multiple: false,
disabled: false,
searchIndex: true,
customScrollbar: false,
searchable: true,
commaSeperated: false,
Expand Down Expand Up @@ -138,6 +139,7 @@ const reducer = ( state = initialState, action ) => {
arrow: action.props.arrow,
multiple: action.props.multiple,
disabled: action.props.disabled,
searchIndex: action.props.searchIndex,
customScrollbar: action.props.customScrollbar,
searchable: action.props.searchable,
stayOpen: action.props.hasOwnProperty( 'stayOpen' )
Expand Down Expand Up @@ -197,7 +199,7 @@ const reducer = ( state = initialState, action ) => {
active: true,
queryString: action.queryString,
resultSet: state.ajax.active && state.ajax.fetchOnSearch ? action.queryString.length < state.ajax.minLength ? [] : state.options : state.options.filter( o =>
o.label.toLowerCase().includes( queryString ) || o.key.toString().toLowerCase().includes( queryString )
o.label.toLowerCase().includes( queryString ) || ( state.settings.searchIndex && o.key.toString().toLowerCase().includes( queryString ) )
)
} ),
focusedItem: null,
Expand Down

0 comments on commit 84ffb80

Please sign in to comment.