react-select-input-v2 1.0.6 → 1.0.8-react16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -21
- package/README.md +82 -82
- package/es/index.js +68 -91
- package/es/react-select-input.css +92 -92
- package/lib/index.js +70 -89
- package/lib/react-select-input.css +92 -92
- package/package.json +12 -37
- package/src/index.js +270 -0
- package/src/react-select-input.css +92 -0
- package/umd/{react-select-input.js → react-select-input-v2.js} +341 -629
- package/umd/react-select-input-v2.min.js +6 -0
- package/umd/react-select-input-v2.min.js.map +1 -0
- package/umd/react-select-input.min.js +0 -6
- package/umd/react-select-input.min.js.map +0 -1
package/LICENSE
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2018 Samrith Shankar
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2018 Samrith Shankar
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,82 +1,82 @@
|
|
|
1
|
-
# react-select-input
|
|
2
|
-
|
|
3
|
-
[][build]
|
|
4
|
-
[][npm]
|
|
5
|
-
[][license]
|
|
6
|
-
|
|
7
|
-
A simple combination of traditional HTML5 input and select.
|
|
8
|
-
|
|
9
|
-
## v2 underway!
|
|
10
|
-
|
|
11
|
-
I've left this project inactive for way too long (`v1.0.0` was launched a year after initial release!). Going through the code, there are a lot of stuff that could be improved. For all the users, the entire project will undergo a complete rewrite. Many of these changes will be breaking, leading up to the release of v2.
|
|
12
|
-
|
|
13
|
-
**Head over to the [Version 2 thread](https://github.com/samrith-s/react-select-input/issues/2) to know more and discuss!**
|
|
14
|
-
|
|
15
|
-
### Props Overview
|
|
16
|
-
|
|
17
|
-
```javascript
|
|
18
|
-
InputSelect.defaultProps = {
|
|
19
|
-
uniqueKey: 'react-select-input', //String
|
|
20
|
-
style: null, //Object
|
|
21
|
-
value: '', //String
|
|
22
|
-
valueKey: 'value', //String
|
|
23
|
-
labelKey: 'label', //String
|
|
24
|
-
placeholder: 'Enter text', //String
|
|
25
|
-
className: '', //String
|
|
26
|
-
openUp: false, //Boolean
|
|
27
|
-
disableEnter: true, //Boolean
|
|
28
|
-
collapseOnBlur: true, //Boolean
|
|
29
|
-
collapseOnEscape: true, //Boolean
|
|
30
|
-
collapseOnSelect: true, //Boolean
|
|
31
|
-
autoFocus: true, //Boolean
|
|
32
|
-
clearable: true, //Boolean - NO EFFECT
|
|
33
|
-
options: [], //Array
|
|
34
|
-
onSelect: undefined, //Function (option)
|
|
35
|
-
onClear: undefined, // Function
|
|
36
|
-
onChange: undefined, //Function (event)
|
|
37
|
-
onFocus: undefined, //Function (event)
|
|
38
|
-
onBlur: undefined, //Function (event)
|
|
39
|
-
onKeyUp: undefined, //Function (event)
|
|
40
|
-
onKeyDown: undefined, //Function (event)
|
|
41
|
-
noOptions: undefined //JSX
|
|
42
|
-
};
|
|
43
|
-
```
|
|
44
|
-
|
|
45
|
-
### Options
|
|
46
|
-
|
|
47
|
-
| Prop | Type | Default |
|
|
48
|
-
| ---------------- | :-----: | --------------------------------------------------------------------------------------------- |
|
|
49
|
-
| uniqueKey | String | `"react-select-input"` Unique key for the component. |
|
|
50
|
-
| style | Object | `null` Any custom inline styles that need to be passed. |
|
|
51
|
-
| value | String | `""` The value to either populate or control the component. |
|
|
52
|
-
| valueKey | String | `"value"` The key from your options which you want to use as the value key. Should be unique. |
|
|
53
|
-
| labelKey | String | `"label"` The key from your options for pretty display of options. |
|
|
54
|
-
| placeholder | String | `"Enter text"` Placeholder for input. |
|
|
55
|
-
| className | String | `""` Custom classes apart from the default classes to the wrapper. |
|
|
56
|
-
| openUp | Boolean | `false` Whether the select should work as a dropup or dropdown. |
|
|
57
|
-
| disableEnter | Boolean | `true` If the default return key behaviour should be preserved. |
|
|
58
|
-
| collapseOnBlur | Boolean | `true` Clicking outside the ref should collapse the select. |
|
|
59
|
-
| collapseOnEscape | Boolean | `true` While focused, hitting Escape collapse the select. |
|
|
60
|
-
| collapseOnSelect | Boolean | `true` Upon selection collapses the select. |
|
|
61
|
-
| autoFocus | Boolean | `true` On mount, focus the input field. |
|
|
62
|
-
| clearable | Boolean | `true` Show an icon to clear the entire select. |
|
|
63
|
-
| options | Array | `[ ]` Array of options to use while rendering the list. |
|
|
64
|
-
| noOptions | JSX | `undefined` JSX to render when no option matches search. |
|
|
65
|
-
|
|
66
|
-
### Methods
|
|
67
|
-
|
|
68
|
-
| Prop | Parameters | Description |
|
|
69
|
-
| --------- | :--------: | --------------------------------------------------------------------------------------------- |
|
|
70
|
-
| onChange | event | Synthetic event of the input upon change. |
|
|
71
|
-
| onSelect | option | The selected option.<br />Gets triggered during both clicking and arrow navigation selection. |
|
|
72
|
-
| onFocus | event | Synthetic event of the input upon focus. |
|
|
73
|
-
| onBlur | event | Synthetic event of the input upon blur. Native function passed. |
|
|
74
|
-
| onKeyUp | event | Synthetic event of the input upon keyUp. |
|
|
75
|
-
| onKeyDown | event | Synthetic event of the input upon keyDown. |
|
|
76
|
-
| onClear | none | A callback after clear if `clearable`. |
|
|
77
|
-
|
|
78
|
-
Copyright © 2018.
|
|
79
|
-
|
|
80
|
-
[build]: https://travis-ci.org/samrith-s/react-select-input
|
|
81
|
-
[npm]: https://www.npmjs.org/package/react-select-input
|
|
82
|
-
[license]: https://github.com/samrith-s/react-select-input/blob/master/LICENSE
|
|
1
|
+
# react-select-input
|
|
2
|
+
|
|
3
|
+
[][build]
|
|
4
|
+
[][npm]
|
|
5
|
+
[][license]
|
|
6
|
+
|
|
7
|
+
A simple combination of traditional HTML5 input and select.
|
|
8
|
+
|
|
9
|
+
## v2 underway!
|
|
10
|
+
|
|
11
|
+
I've left this project inactive for way too long (`v1.0.0` was launched a year after initial release!). Going through the code, there are a lot of stuff that could be improved. For all the users, the entire project will undergo a complete rewrite. Many of these changes will be breaking, leading up to the release of v2.
|
|
12
|
+
|
|
13
|
+
**Head over to the [Version 2 thread](https://github.com/samrith-s/react-select-input/issues/2) to know more and discuss!**
|
|
14
|
+
|
|
15
|
+
### Props Overview
|
|
16
|
+
|
|
17
|
+
```javascript
|
|
18
|
+
InputSelect.defaultProps = {
|
|
19
|
+
uniqueKey: 'react-select-input', //String
|
|
20
|
+
style: null, //Object
|
|
21
|
+
value: '', //String
|
|
22
|
+
valueKey: 'value', //String
|
|
23
|
+
labelKey: 'label', //String
|
|
24
|
+
placeholder: 'Enter text', //String
|
|
25
|
+
className: '', //String
|
|
26
|
+
openUp: false, //Boolean
|
|
27
|
+
disableEnter: true, //Boolean
|
|
28
|
+
collapseOnBlur: true, //Boolean
|
|
29
|
+
collapseOnEscape: true, //Boolean
|
|
30
|
+
collapseOnSelect: true, //Boolean
|
|
31
|
+
autoFocus: true, //Boolean
|
|
32
|
+
clearable: true, //Boolean - NO EFFECT
|
|
33
|
+
options: [], //Array
|
|
34
|
+
onSelect: undefined, //Function (option)
|
|
35
|
+
onClear: undefined, // Function
|
|
36
|
+
onChange: undefined, //Function (event)
|
|
37
|
+
onFocus: undefined, //Function (event)
|
|
38
|
+
onBlur: undefined, //Function (event)
|
|
39
|
+
onKeyUp: undefined, //Function (event)
|
|
40
|
+
onKeyDown: undefined, //Function (event)
|
|
41
|
+
noOptions: undefined //JSX
|
|
42
|
+
};
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
### Options
|
|
46
|
+
|
|
47
|
+
| Prop | Type | Default |
|
|
48
|
+
| ---------------- | :-----: | --------------------------------------------------------------------------------------------- |
|
|
49
|
+
| uniqueKey | String | `"react-select-input"` Unique key for the component. |
|
|
50
|
+
| style | Object | `null` Any custom inline styles that need to be passed. |
|
|
51
|
+
| value | String | `""` The value to either populate or control the component. |
|
|
52
|
+
| valueKey | String | `"value"` The key from your options which you want to use as the value key. Should be unique. |
|
|
53
|
+
| labelKey | String | `"label"` The key from your options for pretty display of options. |
|
|
54
|
+
| placeholder | String | `"Enter text"` Placeholder for input. |
|
|
55
|
+
| className | String | `""` Custom classes apart from the default classes to the wrapper. |
|
|
56
|
+
| openUp | Boolean | `false` Whether the select should work as a dropup or dropdown. |
|
|
57
|
+
| disableEnter | Boolean | `true` If the default return key behaviour should be preserved. |
|
|
58
|
+
| collapseOnBlur | Boolean | `true` Clicking outside the ref should collapse the select. |
|
|
59
|
+
| collapseOnEscape | Boolean | `true` While focused, hitting Escape collapse the select. |
|
|
60
|
+
| collapseOnSelect | Boolean | `true` Upon selection collapses the select. |
|
|
61
|
+
| autoFocus | Boolean | `true` On mount, focus the input field. |
|
|
62
|
+
| clearable | Boolean | `true` Show an icon to clear the entire select. |
|
|
63
|
+
| options | Array | `[ ]` Array of options to use while rendering the list. |
|
|
64
|
+
| noOptions | JSX | `undefined` JSX to render when no option matches search. |
|
|
65
|
+
|
|
66
|
+
### Methods
|
|
67
|
+
|
|
68
|
+
| Prop | Parameters | Description |
|
|
69
|
+
| --------- | :--------: | --------------------------------------------------------------------------------------------- |
|
|
70
|
+
| onChange | event | Synthetic event of the input upon change. |
|
|
71
|
+
| onSelect | option | The selected option.<br />Gets triggered during both clicking and arrow navigation selection. |
|
|
72
|
+
| onFocus | event | Synthetic event of the input upon focus. |
|
|
73
|
+
| onBlur | event | Synthetic event of the input upon blur. Native function passed. |
|
|
74
|
+
| onKeyUp | event | Synthetic event of the input upon keyUp. |
|
|
75
|
+
| onKeyDown | event | Synthetic event of the input upon keyDown. |
|
|
76
|
+
| onClear | none | A callback after clear if `clearable`. |
|
|
77
|
+
|
|
78
|
+
Copyright © 2018.
|
|
79
|
+
|
|
80
|
+
[build]: https://travis-ci.org/samrith-s/react-select-input
|
|
81
|
+
[npm]: https://www.npmjs.org/package/react-select-input
|
|
82
|
+
[license]: https://github.com/samrith-s/react-select-input/blob/master/LICENSE
|
package/es/index.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
|
|
2
|
+
|
|
1
3
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
2
4
|
|
|
3
5
|
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
|
|
@@ -5,7 +7,7 @@ function _possibleConstructorReturn(self, call) { if (!self) { throw new Referen
|
|
|
5
7
|
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
|
|
6
8
|
|
|
7
9
|
import React, { Component } from 'react';
|
|
8
|
-
|
|
10
|
+
import PropTypes from 'prop-types';
|
|
9
11
|
import Textarea from 'react-autosize-textarea';
|
|
10
12
|
|
|
11
13
|
function escapeRegExp(string) {
|
|
@@ -46,7 +48,6 @@ var SelectInput = function (_Component) {
|
|
|
46
48
|
if (_this.props.collapseOnSelect) state = _this.setIsOpen(state, false);
|
|
47
49
|
state = _this.manipState(state, 'searchMatchOptions', _this.matchingOptions(_this.props.options, state.value));
|
|
48
50
|
_this.setState(state);
|
|
49
|
-
|
|
50
51
|
if (_this.isFunction(_this.props.onSelect)) _this.props.onSelect(option);
|
|
51
52
|
};
|
|
52
53
|
|
|
@@ -59,14 +60,11 @@ var SelectInput = function (_Component) {
|
|
|
59
60
|
var state = _this.manipState(_this.state, 'value', event.target.value);
|
|
60
61
|
state = _this.manipState(state, 'searchMatchOptions', _this.matchingOptions(_this.props.options, event.target.value));
|
|
61
62
|
state = _this.setIsOpen(state, true);
|
|
62
|
-
|
|
63
63
|
if (!state.value) {
|
|
64
64
|
state = _this.manipState(state, 'currentOption', -1);
|
|
65
65
|
state = _this.manipState(state, 'selectedOption', null);
|
|
66
66
|
}
|
|
67
|
-
|
|
68
67
|
if (_this.isFunction(_this.props.onChange)) _this.props.onChange(event);
|
|
69
|
-
|
|
70
68
|
_this.setState(state);
|
|
71
69
|
};
|
|
72
70
|
|
|
@@ -74,7 +72,6 @@ var SelectInput = function (_Component) {
|
|
|
74
72
|
var state = _this.setIsOpen(_this.state, true);
|
|
75
73
|
state = _this.manipState(state, 'searchMatchOptions', _this.matchingOptions(_this.props.options, event.target.value));
|
|
76
74
|
_this.setState(state);
|
|
77
|
-
|
|
78
75
|
if (_this.isFunction(_this.props.onFocus)) _this.props.onFocus(event);
|
|
79
76
|
};
|
|
80
77
|
|
|
@@ -85,65 +82,47 @@ var SelectInput = function (_Component) {
|
|
|
85
82
|
state = _this.manipState(state, 'currentOption', -1);
|
|
86
83
|
state = _this.manipState(state, 'selectedOption', null);
|
|
87
84
|
_this.setState(state);
|
|
88
|
-
|
|
89
85
|
if (_this.isFunction(_this.props.onClear)) _this.props.onClear();
|
|
90
86
|
};
|
|
91
87
|
|
|
92
88
|
_this.handleBlur = function (event) {
|
|
93
89
|
if (_this.props.collapseOnBlur) {
|
|
94
|
-
|
|
95
|
-
_this.setState(state);
|
|
90
|
+
_this.setState(_this.setIsOpen(_this.state, false));
|
|
96
91
|
}
|
|
97
|
-
|
|
98
92
|
if (_this.isFunction(_this.props.onBlur)) _this.props.onBlur(event);
|
|
99
93
|
};
|
|
100
94
|
|
|
101
95
|
_this.handleKeyUp = function (event) {
|
|
102
|
-
if (event.key === 'Enter' && _this.state.currentOption > -1)
|
|
103
|
-
|
|
104
|
-
} else if (event.key === 'Enter' && _this.state.currentOption === -1) {
|
|
105
|
-
_this.handleSelect(_this.pickOption());
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
if (event.key === 'Escape' && _this.props.collapseOnEscape) {
|
|
109
|
-
_this.setState(_this.setIsOpen(_this.state, false));
|
|
110
|
-
}
|
|
111
|
-
|
|
96
|
+
if (event.key === 'Enter' && _this.state.currentOption > -1) _this.handleSelect(_this.pickOption());
|
|
97
|
+
if (event.key === 'Escape' && _this.props.collapseOnEscape) _this.setState(_this.setIsOpen(_this.state, false));
|
|
112
98
|
if (_this.isFunction(_this.props.onKeyUp)) _this.props.onKeyUp(event);
|
|
113
99
|
};
|
|
114
100
|
|
|
115
101
|
_this.handleKeyDown = function (event) {
|
|
116
102
|
if (event.key === 'Enter' && _this.props.disableEnter) event.preventDefault();
|
|
117
|
-
|
|
118
|
-
if (event.key === 'Escape' && _this.props.collapseOnEscape) {
|
|
119
|
-
var state = _this.setIsOpen(_this.state, false);
|
|
120
|
-
_this.setState(state);
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
_this.handleOptionNavigation(event);
|
|
124
|
-
|
|
103
|
+
if (event.key === 'Escape' && _this.props.collapseOnEscape) _this.setState(_this.setIsOpen(_this.state, false));
|
|
125
104
|
if (_this.isFunction(_this.props.onKeyDown)) _this.props.onKeyDown(event);
|
|
105
|
+
_this.handleOptionNavigation(event);
|
|
126
106
|
};
|
|
127
107
|
|
|
128
108
|
_this.handleOptionNavigation = function (event) {
|
|
129
109
|
var state = {};
|
|
130
110
|
var currentOption = _this.state.currentOption;
|
|
131
111
|
|
|
132
|
-
if (event.key === 'ArrowUp' || event.key === 'ArrowDown'
|
|
112
|
+
if (event.key === 'ArrowUp' || event.key === 'ArrowDown') event.preventDefault();
|
|
133
113
|
|
|
134
114
|
if (event.key === 'ArrowUp' && currentOption === -1 && _this.props.openUp) currentOption = _this.state.searchMatchOptions.length;
|
|
135
115
|
|
|
136
116
|
if (_this.props.openUp) {
|
|
137
|
-
if (event.key === 'ArrowDown')
|
|
138
|
-
if (currentOption > -1) currentOption++;else currentOption = -1;
|
|
139
|
-
} else if (event.key === 'ArrowUp') currentOption--;
|
|
117
|
+
if (event.key === 'ArrowDown') currentOption = currentOption > -1 ? currentOption + 1 : -1;else if (event.key === 'ArrowUp') currentOption--;
|
|
140
118
|
} else {
|
|
141
119
|
if (event.key === 'ArrowDown') currentOption++;else if (event.key === 'ArrowUp') currentOption--;
|
|
142
120
|
}
|
|
143
121
|
|
|
144
|
-
if (currentOption < -1) currentOption = -1;else if (currentOption > _this.state.searchMatchOptions.length - 1
|
|
122
|
+
if (currentOption < -1) currentOption = -1;else if (currentOption > _this.state.searchMatchOptions.length - 1) currentOption = _this.state.searchMatchOptions.length - 1;
|
|
145
123
|
|
|
146
124
|
state = _this.manipState(_this.state, 'currentOption', currentOption);
|
|
125
|
+
|
|
147
126
|
var optionRef = currentOption > -1 ? _this['option-' + _this.state.searchMatchOptions[currentOption][_this.props.valueKey]] : null;
|
|
148
127
|
if (optionRef) optionRef.scrollIntoViewIfNeeded(false);
|
|
149
128
|
|
|
@@ -155,12 +134,12 @@ var SelectInput = function (_Component) {
|
|
|
155
134
|
var searchValue = value.replace(/\s/g, '');
|
|
156
135
|
var searchOptions = [];
|
|
157
136
|
|
|
158
|
-
if (options && options.length > 0 && value) searchOptions = options.filter(function (option
|
|
159
|
-
var
|
|
160
|
-
var value = option[_this.props.valueKey] || '';
|
|
137
|
+
if (options && options.length > 0 && value) searchOptions = options.filter(function (option) {
|
|
138
|
+
var val = option[_this.props.valueKey] || '';
|
|
161
139
|
var label = option[_this.props.labelKey] || '';
|
|
162
|
-
|
|
163
|
-
|
|
140
|
+
var regexp = new RegExp(searchValue, 'gi');
|
|
141
|
+
return regexp.test(label.replace(/\s/g, '')) || regexp.test(val.replace(/\s/g, ''));
|
|
142
|
+
});else searchOptions = options.slice();
|
|
164
143
|
|
|
165
144
|
if (_this.props.openUp) searchOptions.reverse();
|
|
166
145
|
|
|
@@ -175,15 +154,13 @@ var SelectInput = function (_Component) {
|
|
|
175
154
|
};
|
|
176
155
|
|
|
177
156
|
_this.setIsOpen = function (state, show) {
|
|
178
|
-
return
|
|
179
|
-
isOpen: show || false
|
|
180
|
-
});
|
|
157
|
+
return _extends({}, state, { isOpen: show || false });
|
|
181
158
|
};
|
|
182
159
|
|
|
183
160
|
_this.manipState = function (state, key, value) {
|
|
184
|
-
var
|
|
161
|
+
var _extends2;
|
|
185
162
|
|
|
186
|
-
return
|
|
163
|
+
return _extends({}, state, (_extends2 = {}, _extends2[key] = value, _extends2));
|
|
187
164
|
};
|
|
188
165
|
|
|
189
166
|
_this.isFunction = function (obj) {
|
|
@@ -191,7 +168,7 @@ var SelectInput = function (_Component) {
|
|
|
191
168
|
};
|
|
192
169
|
|
|
193
170
|
_this.handleOutsideClick = function (event) {
|
|
194
|
-
if (!_this.ris.contains(event.target) && _this.props.collapseOnBlur) _this.setState(
|
|
171
|
+
if (_this.ris && !_this.ris.contains(event.target) && _this.props.collapseOnBlur) _this.setState({ isOpen: false });
|
|
195
172
|
};
|
|
196
173
|
|
|
197
174
|
_this.state = {
|
|
@@ -210,9 +187,10 @@ var SelectInput = function (_Component) {
|
|
|
210
187
|
|
|
211
188
|
SelectInput.prototype.componentDidUpdate = function componentDidUpdate() {
|
|
212
189
|
if (this.props.openUp && this.state.currentOption === -1 && this.state.isOpen && !this.state.selectedOption) {
|
|
213
|
-
this.options.scrollTop = this.options.scrollHeight;
|
|
190
|
+
if (this.options) this.options.scrollTop = this.options.scrollHeight;
|
|
214
191
|
} else if (this.props.openUp && this.state.selectedOption && this.state.isOpen) {
|
|
215
|
-
this['option-' + this.state.selectedOption]
|
|
192
|
+
var ref = this['option-' + this.state.selectedOption];
|
|
193
|
+
if (ref && ref.scrollIntoViewIfNeeded) ref.scrollIntoViewIfNeeded(true);
|
|
216
194
|
}
|
|
217
195
|
};
|
|
218
196
|
|
|
@@ -220,21 +198,11 @@ var SelectInput = function (_Component) {
|
|
|
220
198
|
document.removeEventListener('click', this.handleOutsideClick);
|
|
221
199
|
};
|
|
222
200
|
|
|
223
|
-
|
|
224
|
-
Various renderers
|
|
225
|
-
*/
|
|
201
|
+
// ======= 渲染选项 =======
|
|
226
202
|
|
|
227
|
-
/*
|
|
228
|
-
Handle different events
|
|
229
|
-
*/
|
|
230
203
|
|
|
231
|
-
|
|
232
|
-
Searching function
|
|
233
|
-
*/
|
|
204
|
+
// ======= 事件处理 =======
|
|
234
205
|
|
|
235
|
-
/*
|
|
236
|
-
Various helpers
|
|
237
|
-
*/
|
|
238
206
|
|
|
239
207
|
SelectInput.prototype.render = function render() {
|
|
240
208
|
var _this2 = this;
|
|
@@ -263,22 +231,18 @@ var SelectInput = function (_Component) {
|
|
|
263
231
|
return _this2.input = ref;
|
|
264
232
|
}
|
|
265
233
|
}),
|
|
266
|
-
this.props.clearable
|
|
234
|
+
this.props.clearable && React.createElement(
|
|
267
235
|
'div',
|
|
268
236
|
{ className: 'ris-clearable', onClick: this.handleClear },
|
|
269
237
|
'x'
|
|
270
|
-
)
|
|
271
|
-
this.state.isOpen
|
|
238
|
+
),
|
|
239
|
+
this.state.isOpen && this.state.searchMatchOptions.length > 0 && React.createElement(
|
|
272
240
|
'div',
|
|
273
241
|
{ className: 'ris-options', ref: function ref(_ref3) {
|
|
274
242
|
return _this2.options = _ref3;
|
|
275
243
|
} },
|
|
276
244
|
this.renderOptions(this.state.searchMatchOptions)
|
|
277
|
-
)
|
|
278
|
-
'div',
|
|
279
|
-
{ className: 'ris-options ris-no-options' },
|
|
280
|
-
this.props.noOptions
|
|
281
|
-
) : null : null
|
|
245
|
+
)
|
|
282
246
|
);
|
|
283
247
|
};
|
|
284
248
|
|
|
@@ -289,28 +253,41 @@ export { SelectInput as default };
|
|
|
289
253
|
|
|
290
254
|
|
|
291
255
|
SelectInput.defaultProps = {
|
|
292
|
-
uniqueKey: 'react-select-input',
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
256
|
+
uniqueKey: 'react-select-input',
|
|
257
|
+
value: '',
|
|
258
|
+
valueKey: 'value',
|
|
259
|
+
labelKey: 'label',
|
|
260
|
+
placeholder: 'Enter text',
|
|
261
|
+
openUp: false,
|
|
262
|
+
disableEnter: true,
|
|
263
|
+
collapseOnBlur: true,
|
|
264
|
+
collapseOnEscape: true,
|
|
265
|
+
collapseOnSelect: true,
|
|
266
|
+
autoFocus: true,
|
|
267
|
+
clearable: true,
|
|
268
|
+
options: []
|
|
269
|
+
};
|
|
270
|
+
|
|
271
|
+
SelectInput.propTypes = process.env.NODE_ENV !== "production" ? {
|
|
272
|
+
uniqueKey: PropTypes.string,
|
|
273
|
+
value: PropTypes.string,
|
|
274
|
+
valueKey: PropTypes.string,
|
|
275
|
+
labelKey: PropTypes.string,
|
|
276
|
+
placeholder: PropTypes.string,
|
|
277
|
+
openUp: PropTypes.bool,
|
|
278
|
+
disableEnter: PropTypes.bool,
|
|
279
|
+
collapseOnBlur: PropTypes.bool,
|
|
280
|
+
collapseOnEscape: PropTypes.bool,
|
|
281
|
+
collapseOnSelect: PropTypes.bool,
|
|
282
|
+
autoFocus: PropTypes.bool,
|
|
283
|
+
clearable: PropTypes.bool,
|
|
284
|
+
options: PropTypes.array,
|
|
285
|
+
onChange: PropTypes.func,
|
|
286
|
+
onSelect: PropTypes.func,
|
|
287
|
+
onFocus: PropTypes.func,
|
|
288
|
+
onBlur: PropTypes.func,
|
|
289
|
+
onKeyUp: PropTypes.func,
|
|
290
|
+
onKeyDown: PropTypes.func,
|
|
291
|
+
onClear: PropTypes.func,
|
|
292
|
+
noOptions: PropTypes.node
|
|
293
|
+
} : {};
|