Skip to content

Commit 84ffb80

Browse files
Merge pull request #15 from casufi/master
Added prop searchIndex to allow to search by the label only
2 parents 23191f5 + efc7397 commit 84ffb80

7 files changed

Lines changed: 16 additions & 10 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ stayOpen | boolean | false | If the Select should stay open or not.
6565
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". )
6666
singleLine | boolean | false | Where the selected values ( Select's Header ) should be contained to one line.
6767
lifo | boolean | false | **Last In First Out Mode**. The user's last selection, goes first. ( Available only with multiple prop set to "true". )
68+
searchIndex | boolean | true | Enable search by both Index and Value fields
6869
selectAllButton | boolean | false | Whether a "select all button" should be visible on Select's header.
6970
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.
7071
tags | boolean | false | Whether to support custom tags.

dist/index.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-selectrix",
3-
"version": "1.0.14",
3+
"version": "1.0.15",
44
"description": "A beautiful, clean coded select replacement for React.js",
55
"main": "dist/index.js",
66
"scripts": {

src/PlayGround.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,11 @@ export default class PlayGround extends React.Component {
3636

3737
let options = [
3838
{
39-
key: 'a',
40-
label: 'Option A'
39+
key: 'a10',
40+
label: 'Option A 10'
4141
},
4242
{
43-
key: 'b',
43+
key: 'b10',
4444
label: 'Option B'
4545
},
4646
{
@@ -87,6 +87,7 @@ export default class PlayGround extends React.Component {
8787
commaSeperated={ false }
8888
singleLine={ false }
8989
lifo={ false }
90+
searchIndex={ false }
9091
selectAllButton={ true }
9192
height={ 190 }
9293
checkBoxes={ false }

src/components/App/partials/Header/partials/Searchable/Searchable.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,11 @@ export default class Searchable extends React.Component {
4141

4242
}
4343

44-
componentWillMount() {
44+
UNSAFE_componentWillMount() {
4545
this.calculateSize( this.props );
4646
}
4747

48-
componentWillReceiveProps( nextProps ) {
48+
UNSAFE_componentWillReceiveProps( nextProps ) {
4949

5050
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 ) {
5151
this.calculateSize( nextProps );

src/components/Selectrix.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@ export default class Selectrix extends React.Component {
2727
} )
2828
}
2929

30-
componentWillMount() {
30+
UNSAFE_componentWillMount() {
3131
this.props.setupInstance( this.props );
3232
}
3333

34-
componentWillReceiveProps( nextProps ) {
34+
UNSAFE_componentWillReceiveProps( nextProps ) {
3535
this.props.updateInstance( nextProps );
3636
}
3737

@@ -56,6 +56,7 @@ Selectrix.defaultProps = {
5656
defaultValue: false,
5757
multiple: false,
5858
disabled: false,
59+
searchIndex: true,
5960
onChange: () => {},
6061
onOpen: () => {},
6162
onClose: () => {},
@@ -97,6 +98,7 @@ Selectrix.propTypes = {
9798
] ),
9899
multiple: PropTypes.bool,
99100
disabled: PropTypes.bool,
101+
searchIndex: PropTypes.bool,
100102
onChange: PropTypes.func,
101103
customScrollbar: PropTypes.bool,
102104
searchable: PropTypes.bool,

src/reducers/index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ const initialState = {
88
arrow: true,
99
multiple: false,
1010
disabled: false,
11+
searchIndex: true,
1112
customScrollbar: false,
1213
searchable: true,
1314
commaSeperated: false,
@@ -138,6 +139,7 @@ const reducer = ( state = initialState, action ) => {
138139
arrow: action.props.arrow,
139140
multiple: action.props.multiple,
140141
disabled: action.props.disabled,
142+
searchIndex: action.props.searchIndex,
141143
customScrollbar: action.props.customScrollbar,
142144
searchable: action.props.searchable,
143145
stayOpen: action.props.hasOwnProperty( 'stayOpen' )
@@ -197,7 +199,7 @@ const reducer = ( state = initialState, action ) => {
197199
active: true,
198200
queryString: action.queryString,
199201
resultSet: state.ajax.active && state.ajax.fetchOnSearch ? action.queryString.length < state.ajax.minLength ? [] : state.options : state.options.filter( o =>
200-
o.label.toLowerCase().includes( queryString ) || o.key.toString().toLowerCase().includes( queryString )
202+
o.label.toLowerCase().includes( queryString ) || ( state.settings.searchIndex && o.key.toString().toLowerCase().includes( queryString ) )
201203
)
202204
} ),
203205
focusedItem: null,

0 commit comments

Comments
 (0)