@nestio/pam 2.0.5-beta.3 → 2.0.6-beta.0
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/examples/components/Select.jsx +12 -26
- package/examples/index.html +0 -5
- package/lib/components/MultiSelect.js +3 -3
- package/lib/components/MultiSelectOption.js +3 -22
- package/lib/components/OptionListSet.js +3 -11
- package/lib/components/SelectCore.js +26 -84
- package/lib/components/SelectOption.js +11 -43
- package/lib/components/SingleSelect.js +0 -2
- package/lib/components/TagBoxMenuSelect.js +0 -2
- package/lib/components/styles/MultiSelectOption.scss +0 -4
- package/lib/components/styles/SelectOption.scss +0 -12
- package/lib/components/styles/_variables.scss +0 -1
- package/lib/components/styles/icons/05a4d7fb.eot +0 -0
- package/lib/components/styles/icons/05a4d7fb.otf +0 -0
- package/lib/components/styles/icons/05a4d7fb.ttf +0 -0
- package/lib/components/styles/icons/05a4d7fb.woff +0 -0
- package/lib/components/styles/icons/icons.css +57 -1
- package/package.json +1 -1
- package/src/components/MultiSelect.jsx +2 -2
- package/src/components/MultiSelectOption.jsx +3 -21
- package/src/components/OptionListSet.jsx +2 -9
- package/src/components/SelectCore.jsx +11 -62
- package/src/components/SelectOption.jsx +8 -26
- package/src/components/SingleSelect.jsx +0 -2
- package/src/components/TagBoxMenuSelect.jsx +0 -2
- package/src/components/__tests__/MultiSelect.spec.js +2 -0
- package/src/components/__tests__/MultiSelectOption.spec.js +2 -36
- package/src/components/__tests__/OptionListSet.spec.js +1 -24
- package/src/components/__tests__/SelectCore.spec.js +0 -103
- package/src/components/__tests__/SelectOption.spec.js +2 -33
- package/src/components/__tests__/SingleSelectOption.spec.js +1 -2
- package/src/components/styles/MultiSelectOption.scss +0 -4
- package/src/components/styles/SelectOption.scss +0 -12
- package/src/components/styles/_variables.scss +0 -1
- package/src/components/styles/icons/05a4d7fb.eot +0 -0
- package/src/components/styles/icons/05a4d7fb.otf +0 -0
- package/src/components/styles/icons/05a4d7fb.ttf +0 -0
- package/src/components/styles/icons/05a4d7fb.woff +0 -0
- package/src/components/styles/icons/icons.css +57 -1
- package/lib/components/Collapse.js +0 -50
- package/lib/constants.js +0 -7
- package/src/components/Collapse.jsx +0 -30
- package/src/components/__tests__/Collapse.spec.js +0 -26
- package/src/constants.js +0 -2
|
@@ -30,19 +30,18 @@ export default function MultiSelect (props){
|
|
|
30
30
|
onClose={props.onClose}
|
|
31
31
|
onOpen={props.onOpen}
|
|
32
32
|
options={props.options}
|
|
33
|
+
optionSets={props.optionSets}
|
|
33
34
|
renderOptionLabel={props.renderOptionLabel}
|
|
34
35
|
renderValueLabel={props.renderValueLabel}
|
|
35
36
|
value={props.value}
|
|
36
37
|
valueAdapter={valueAdapter}
|
|
37
38
|
ValueComponent={props.ValueComponent}
|
|
38
|
-
collapsibleOptions={props.collapsibleOptions}
|
|
39
39
|
/>
|
|
40
40
|
);
|
|
41
41
|
}
|
|
42
42
|
|
|
43
43
|
MultiSelect.propTypes = {
|
|
44
44
|
ariaLabel: PropTypes.string,
|
|
45
|
-
collapsibleOptions: PropTypes.array,
|
|
46
45
|
filterable: PropTypes.bool,
|
|
47
46
|
menuContainerClassName: PropTypes.string,
|
|
48
47
|
menuContainerText: PropTypes.string,
|
|
@@ -52,6 +51,7 @@ MultiSelect.propTypes = {
|
|
|
52
51
|
onClose: PropTypes.func,
|
|
53
52
|
onOpen: PropTypes.func,
|
|
54
53
|
options: PropTypes.array.isRequired,
|
|
54
|
+
optionSets: PropTypes.array,
|
|
55
55
|
renderOptionLabel: PropTypes.func,
|
|
56
56
|
renderValueLabel: PropTypes.func,
|
|
57
57
|
value: PropTypes.oneOfType([PropTypes.number, PropTypes.string, PropTypes.array]),
|
|
@@ -10,27 +10,11 @@ import styles from './styles/MultiSelectOption.scss';
|
|
|
10
10
|
OptionComponent designed for use in MultiSelects
|
|
11
11
|
*/
|
|
12
12
|
export default function MultiSelectOption (props) {
|
|
13
|
-
const { isSelected, isHighlighted, option
|
|
14
|
-
|
|
15
|
-
function _getCollapsibleClassName(){
|
|
16
|
-
if (currentText) {
|
|
17
|
-
return null;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
if (collapsibleOptions && collapsibleOptions.length) {
|
|
21
|
-
if (option.collapsedBy && collapsibleOptions.indexOf(option.collapsedBy) > -1) {
|
|
22
|
-
return styles['option__indented'];
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
return null;
|
|
27
|
-
}
|
|
28
|
-
|
|
13
|
+
const { isSelected, isHighlighted, option } = props;
|
|
29
14
|
const optionClass = classnames(
|
|
30
15
|
styles.option,
|
|
31
16
|
option.disabled && styles.disabled,
|
|
32
|
-
isHighlighted && styles.highlighted
|
|
33
|
-
_getCollapsibleClassName()
|
|
17
|
+
isHighlighted && styles.highlighted
|
|
34
18
|
);
|
|
35
19
|
|
|
36
20
|
const checkboxClass = classnames({[styles.checked]: isSelected}, {[styles.unchecked]: !isSelected});
|
|
@@ -51,9 +35,7 @@ MultiSelectOption.propTypes = {
|
|
|
51
35
|
isHighlighted: PropTypes.bool.isRequired,
|
|
52
36
|
isSelected: PropTypes.bool.isRequired,
|
|
53
37
|
option: PropTypes.object.isRequired,
|
|
54
|
-
renderOptionLabel: PropTypes.func
|
|
55
|
-
collapsibleOptions: PropTypes.array,
|
|
56
|
-
currentText: PropTypes.string
|
|
38
|
+
renderOptionLabel: PropTypes.func
|
|
57
39
|
};
|
|
58
40
|
|
|
59
41
|
MultiSelectOption.defaultProps = {
|
|
@@ -81,13 +81,13 @@ export default class OptionListSet extends Component {
|
|
|
81
81
|
}
|
|
82
82
|
|
|
83
83
|
renderOptionSet(options, label) {
|
|
84
|
-
const { OptionComponent, EmptyOptionComponent, renderOptionLabel, optionIndex, valueIsSelected, optionSets
|
|
84
|
+
const { OptionComponent, EmptyOptionComponent, renderOptionLabel, optionIndex, valueIsSelected, optionSets } = this.props;
|
|
85
|
+
|
|
85
86
|
let renderedOptions;
|
|
86
87
|
|
|
87
88
|
if (options.length) {
|
|
88
89
|
renderedOptions = options.map((option, index) => {
|
|
89
90
|
index += option.groupIndex || 0;
|
|
90
|
-
|
|
91
91
|
const rendered = (
|
|
92
92
|
<OptionComponent
|
|
93
93
|
id={this.getOptionId(option, index)}
|
|
@@ -97,7 +97,6 @@ export default class OptionListSet extends Component {
|
|
|
97
97
|
isSelected={valueIsSelected(option)}
|
|
98
98
|
renderOptionLabel={renderOptionLabel}
|
|
99
99
|
isHighlighted={index === optionIndex}
|
|
100
|
-
collapsibleState={getCollapsibleState(option.value)}
|
|
101
100
|
{...this.props}
|
|
102
101
|
/>
|
|
103
102
|
);
|
|
@@ -207,7 +206,6 @@ OptionListSet.propTypes = {
|
|
|
207
206
|
OptionComponent
|
|
208
207
|
*/
|
|
209
208
|
renderOptionLabel: PropTypes.func,
|
|
210
|
-
|
|
211
209
|
/**
|
|
212
210
|
Currently highlighted option
|
|
213
211
|
*/
|
|
@@ -216,11 +214,6 @@ OptionListSet.propTypes = {
|
|
|
216
214
|
OptionComponent to be rendered in OptionList
|
|
217
215
|
*/
|
|
218
216
|
OptionComponent: PropTypes.func,
|
|
219
|
-
/**
|
|
220
|
-
Function used to determine if an option is collapsed and can be collapsed
|
|
221
|
-
*/
|
|
222
|
-
|
|
223
|
-
getCollapsibleState: PropTypes.func,
|
|
224
217
|
/**
|
|
225
218
|
Function used to determine if individual options are selected
|
|
226
219
|
*/
|
|
@@ -10,8 +10,6 @@ import uniqueId from 'lodash/uniqueId';
|
|
|
10
10
|
|
|
11
11
|
import styles from './styles/SelectCore.scss';
|
|
12
12
|
|
|
13
|
-
import { OPTION_COLLAPSED, OPTION_NOT_COLLAPSED } from '../constants';
|
|
14
|
-
|
|
15
13
|
/**
|
|
16
14
|
The primary Select component which manages the state for the entire select and renders subcomponents. It controls
|
|
17
15
|
whether the dropdown is opened/closed, which option is currently selected, which open has focus, filtering options
|
|
@@ -30,7 +28,6 @@ class SelectCore extends Component {
|
|
|
30
28
|
this.changeValue = this.changeValue.bind(this);
|
|
31
29
|
this.clearValue = this.clearValue.bind(this);
|
|
32
30
|
this.closeMenu = this.closeMenu.bind(this);
|
|
33
|
-
this.getCollapsibleState = this.getCollapsibleState.bind(this);
|
|
34
31
|
this.onBackspace = this.onBackspace.bind(this);
|
|
35
32
|
this.onDown = this.onDown.bind(this);
|
|
36
33
|
this.onEnter = this.onEnter.bind(this);
|
|
@@ -40,7 +37,6 @@ class SelectCore extends Component {
|
|
|
40
37
|
this.onEscape = this.onEscape.bind(this);
|
|
41
38
|
this.openMenu = this.openMenu.bind(this);
|
|
42
39
|
this.setIndex = this.setIndex.bind(this);
|
|
43
|
-
this.toggleCollapsedValue = this.toggleCollapsedValue.bind(this);
|
|
44
40
|
this.toggleValue = this.toggleValue.bind(this);
|
|
45
41
|
this.valueIsSelected = this.valueIsSelected.bind(this);
|
|
46
42
|
|
|
@@ -52,8 +48,7 @@ class SelectCore extends Component {
|
|
|
52
48
|
isOpen: false,
|
|
53
49
|
optionIndex: this._getInitialOptionIndex(props),
|
|
54
50
|
options: props.options || null,
|
|
55
|
-
loading: false
|
|
56
|
-
collapsedOptions: {}
|
|
51
|
+
loading: false
|
|
57
52
|
};
|
|
58
53
|
|
|
59
54
|
this.menuRef = React.createRef();
|
|
@@ -107,16 +102,10 @@ class SelectCore extends Component {
|
|
|
107
102
|
}
|
|
108
103
|
|
|
109
104
|
componentDidUpdate(prevProps, prevState) {
|
|
110
|
-
const { onOptionsFiltered
|
|
111
|
-
|
|
112
|
-
if (prevState.currentText !== this.state.currentText) {
|
|
113
|
-
if (onOptionsFiltered) {
|
|
114
|
-
onOptionsFiltered(this._getFilteredOptions());
|
|
115
|
-
}
|
|
105
|
+
const { onOptionsFiltered } = this.props;
|
|
116
106
|
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
}
|
|
107
|
+
if (onOptionsFiltered && prevState.currentText !== this.state.currentText) {
|
|
108
|
+
onOptionsFiltered(this._getFilteredOptions());
|
|
120
109
|
}
|
|
121
110
|
}
|
|
122
111
|
|
|
@@ -362,17 +351,6 @@ class SelectCore extends Component {
|
|
|
362
351
|
});
|
|
363
352
|
}
|
|
364
353
|
|
|
365
|
-
toggleCollapsedValue(value){
|
|
366
|
-
this.setState(currentState => {
|
|
367
|
-
const currentCollapsedState = !!currentState.collapsedOptions[value];
|
|
368
|
-
const newValue = Object.assign({}, currentState.collapsedOptions, {[value]: !currentCollapsedState});
|
|
369
|
-
|
|
370
|
-
return {
|
|
371
|
-
collapsedOptions: newValue
|
|
372
|
-
};
|
|
373
|
-
});
|
|
374
|
-
}
|
|
375
|
-
|
|
376
354
|
// Async functions
|
|
377
355
|
/**
|
|
378
356
|
* This is typically triggered when the select gets passed a new value and is used to populate the select with the
|
|
@@ -422,29 +400,6 @@ class SelectCore extends Component {
|
|
|
422
400
|
return this.props.valueAdapter.valueIsSelected(this.state.currentValue, newValue);
|
|
423
401
|
}
|
|
424
402
|
|
|
425
|
-
getCollapsibleState(value){
|
|
426
|
-
if (!this.props.collapsibleOptions) {
|
|
427
|
-
return null;
|
|
428
|
-
}
|
|
429
|
-
|
|
430
|
-
if (this.state.currentText) {
|
|
431
|
-
return null;
|
|
432
|
-
}
|
|
433
|
-
|
|
434
|
-
const isCollapsible = this.props.collapsibleOptions.indexOf(value) > -1;
|
|
435
|
-
|
|
436
|
-
if (!isCollapsible) {
|
|
437
|
-
return null;
|
|
438
|
-
}
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
if (this.state.collapsedOptions[value]) {
|
|
442
|
-
return OPTION_COLLAPSED;
|
|
443
|
-
}
|
|
444
|
-
|
|
445
|
-
return OPTION_NOT_COLLAPSED;
|
|
446
|
-
}
|
|
447
|
-
|
|
448
403
|
// Private methods and helpers
|
|
449
404
|
/**
|
|
450
405
|
* Returns options filtered by props.filterOption and currentText. Is memoized to reduce repeating same computation
|
|
@@ -460,19 +415,13 @@ class SelectCore extends Component {
|
|
|
460
415
|
return this.state.options;
|
|
461
416
|
}
|
|
462
417
|
|
|
463
|
-
const args = [this.state.options, this.props.filterOption, text
|
|
464
|
-
if (this._cachedArgs && this._cachedArgs.
|
|
418
|
+
const args = [this.state.options, this.props.filterOption, text];
|
|
419
|
+
if (this._cachedArgs && this._cachedArgs[0] == args[0] && this._cachedArgs[1] == args[1] && this._cachedArgs[2] == args[2]) {
|
|
465
420
|
return this._cachedResult;
|
|
466
421
|
}
|
|
467
422
|
|
|
468
423
|
this._cachedArgs = args;
|
|
469
424
|
this._cachedResult = this.state.options.filter((option) => {
|
|
470
|
-
if (!text && option.hasOwnProperty('collapsedBy')) {
|
|
471
|
-
const isHidden = this.getCollapsibleState(option.collapsedBy) === OPTION_COLLAPSED;
|
|
472
|
-
if (isHidden) {
|
|
473
|
-
return false;
|
|
474
|
-
}
|
|
475
|
-
}
|
|
476
425
|
return this.props.filterOption(option, text);
|
|
477
426
|
});
|
|
478
427
|
|
|
@@ -591,7 +540,6 @@ class SelectCore extends Component {
|
|
|
591
540
|
setIndex: this.setIndex,
|
|
592
541
|
shouldShowOptionList: this._shouldShowOptionList(),
|
|
593
542
|
toggleValue: this.toggleValue,
|
|
594
|
-
toggleCollapsedValue: this.toggleCollapsedValue
|
|
595
543
|
});
|
|
596
544
|
}
|
|
597
545
|
|
|
@@ -604,7 +552,6 @@ class SelectCore extends Component {
|
|
|
604
552
|
<MenuComponent
|
|
605
553
|
options={options}
|
|
606
554
|
valueIsSelected={this.valueIsSelected}
|
|
607
|
-
getCollapsibleState={this.getCollapsibleState}
|
|
608
555
|
OptionComponent={OptionComponent}
|
|
609
556
|
renderOptionLabel={renderOptionLabel}
|
|
610
557
|
onUp={this.onUp}
|
|
@@ -679,6 +626,11 @@ SelectCore.propTypes = {
|
|
|
679
626
|
*/
|
|
680
627
|
filterOption: PropTypes.func,
|
|
681
628
|
/**
|
|
629
|
+
Function intercepts input value change
|
|
630
|
+
* @param {string} str
|
|
631
|
+
*/
|
|
632
|
+
handleValueChange: PropTypes.func,
|
|
633
|
+
/**
|
|
682
634
|
Function used to fetch async options. Is invoked with currentText and should return a promise with the options
|
|
683
635
|
* @param {string} str
|
|
684
636
|
* @returns {Promise}
|
|
@@ -781,9 +733,6 @@ SelectCore.propTypes = {
|
|
|
781
733
|
disabled: PropTypes.bool,
|
|
782
734
|
filterable: PropTypes.bool,
|
|
783
735
|
onOptionsFiltered: PropTypes.func,
|
|
784
|
-
onChangeText: PropTypes.func,
|
|
785
|
-
collapsibleOptions: PropTypes.array
|
|
786
|
-
|
|
787
736
|
};
|
|
788
737
|
|
|
789
738
|
SelectCore.defaultProps = {
|
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
import cn from 'classnames';
|
|
2
|
-
import isEqual from 'lodash/isEqual';
|
|
3
|
-
import PropTypes from 'prop-types';
|
|
4
1
|
import React, { Component } from 'react';
|
|
2
|
+
import PropTypes from 'prop-types';
|
|
5
3
|
|
|
6
|
-
import
|
|
4
|
+
import isEqual from 'lodash/isEqual';
|
|
7
5
|
|
|
8
6
|
/**
|
|
9
7
|
* Generic component for rendering an option in a select. Contains functionality for handling clicking and focusing.
|
|
@@ -13,13 +11,12 @@ export default class SelectOption extends Component {
|
|
|
13
11
|
super();
|
|
14
12
|
this.onClick = this.onClick.bind(this);
|
|
15
13
|
this.onMouseEnter = this.onMouseEnter.bind(this);
|
|
16
|
-
this.onCollapseClick = this.onCollapseClick.bind(this);
|
|
17
14
|
}
|
|
18
15
|
|
|
19
16
|
shouldComponentUpdate(nextProps) {
|
|
20
17
|
// check only interesting props
|
|
21
18
|
const currentProps = this.props;
|
|
22
|
-
const propsToCheck = ['isSelected', 'option', 'disabled', 'isHighlighted'
|
|
19
|
+
const propsToCheck = ['isSelected', 'option', 'disabled', 'isHighlighted'];
|
|
23
20
|
|
|
24
21
|
return propsToCheck
|
|
25
22
|
.map((val) => isEqual( currentProps[val], nextProps[val]) )
|
|
@@ -45,32 +42,19 @@ export default class SelectOption extends Component {
|
|
|
45
42
|
}
|
|
46
43
|
}
|
|
47
44
|
|
|
48
|
-
onCollapseClick(e){
|
|
49
|
-
e.stopPropagation();
|
|
50
|
-
e.nativeEvent.stopImmediatePropagation();
|
|
51
|
-
const { toggleCollapsedValue, option } = this.props;
|
|
52
|
-
toggleCollapsedValue(option.value);
|
|
53
|
-
}
|
|
54
|
-
|
|
55
45
|
render() {
|
|
56
|
-
const { isSelected, option, id, className, collapsibleState, renderOptionLabel } = this.props;
|
|
57
|
-
|
|
58
46
|
return (
|
|
59
47
|
<li
|
|
60
|
-
aria-selected={isSelected}
|
|
61
|
-
aria-disabled={option.disabled}
|
|
62
|
-
aria-label={renderOptionLabel(this.props.option)}
|
|
63
|
-
className={
|
|
64
|
-
id={id}
|
|
48
|
+
aria-selected={this.props.isSelected}
|
|
49
|
+
aria-disabled={this.props.option.disabled}
|
|
50
|
+
aria-label={this.props.renderOptionLabel(this.props.option)}
|
|
51
|
+
className={this.props.className}
|
|
52
|
+
id={this.props.id}
|
|
65
53
|
onClick={this.onClick}
|
|
66
54
|
onMouseEnter={this.onMouseEnter}
|
|
67
55
|
role="option"
|
|
68
56
|
tabIndex="-1"
|
|
69
57
|
>
|
|
70
|
-
{
|
|
71
|
-
collapsibleState &&
|
|
72
|
-
<Collapse collapsibleState={collapsibleState} onClick={this.onCollapseClick} />
|
|
73
|
-
}
|
|
74
58
|
{ this.props.children }
|
|
75
59
|
</li>
|
|
76
60
|
);
|
|
@@ -89,6 +73,4 @@ SelectOption.propTypes = {
|
|
|
89
73
|
toggleValue: PropTypes.func.isRequired,
|
|
90
74
|
unselectOnClick: PropTypes.bool,
|
|
91
75
|
id: PropTypes.string,
|
|
92
|
-
toggleCollapsedValue: PropTypes.func.isRequired,
|
|
93
|
-
collapsibleState: PropTypes.string
|
|
94
76
|
};
|
|
@@ -40,7 +40,6 @@ export default function SingleSelect (props){
|
|
|
40
40
|
onClose={props.onClose}
|
|
41
41
|
options={props.options}
|
|
42
42
|
optionSets={props.optionSets}
|
|
43
|
-
onChangeText={props.onChangeText}
|
|
44
43
|
placeholder={props.placeholder}
|
|
45
44
|
renderValueLabel={props.renderValueLabel}
|
|
46
45
|
renderOptionLabel={props.renderOptionLabel}
|
|
@@ -64,7 +63,6 @@ SingleSelect.propTypes = {
|
|
|
64
63
|
onChange: PropTypes.func,
|
|
65
64
|
onClose: PropTypes.func,
|
|
66
65
|
onOpen: PropTypes.func,
|
|
67
|
-
onChangeText: PropTypes.func,
|
|
68
66
|
OptionComponent: PropTypes.func,
|
|
69
67
|
renderOptionLabel: PropTypes.func,
|
|
70
68
|
renderValueLabel: PropTypes.func,
|
|
@@ -22,7 +22,6 @@ export default function TagBoxMenuSelect (props) {
|
|
|
22
22
|
closeOnSelect={false}
|
|
23
23
|
|
|
24
24
|
ariaLabel={props.ariaLabel}
|
|
25
|
-
collapsibleOptions={props.collapsibleOptions}
|
|
26
25
|
filterable={props.filterable}
|
|
27
26
|
disabled={props.disabled}
|
|
28
27
|
onChange={props.onChange}
|
|
@@ -40,7 +39,6 @@ export default function TagBoxMenuSelect (props) {
|
|
|
40
39
|
|
|
41
40
|
TagBoxMenuSelect.propTypes = {
|
|
42
41
|
ariaLabel: PropTypes.string,
|
|
43
|
-
collapsibleOptions: PropTypes.array,
|
|
44
42
|
filterable: PropTypes.bool,
|
|
45
43
|
disabled: PropTypes.bool,
|
|
46
44
|
options: PropTypes.array.isRequired,
|
|
@@ -14,6 +14,7 @@ const defaultProps = {
|
|
|
14
14
|
onOpen: () => {},
|
|
15
15
|
onClose: () => {},
|
|
16
16
|
options: [],
|
|
17
|
+
optionSets: [],
|
|
17
18
|
renderOptionLabel: () => {},
|
|
18
19
|
renderValueLabel: () => {}
|
|
19
20
|
};
|
|
@@ -30,6 +31,7 @@ test('it passes on correct props', () => {
|
|
|
30
31
|
expect(selectCore.prop('onOpen')).toEqual(props.onOpen);
|
|
31
32
|
expect(selectCore.prop('onClose')).toEqual(props.onClose);
|
|
32
33
|
expect(selectCore.prop('options')).toEqual(props.options);
|
|
34
|
+
expect(selectCore.prop('optionSets')).toEqual(props.optionSets);
|
|
33
35
|
expect(selectCore.prop('renderOptionLabel')).toEqual(props.renderOptionLabel);
|
|
34
36
|
expect(selectCore.prop('renderValueLabel')).toEqual(props.renderValueLabel);
|
|
35
37
|
expect(selectCore.prop('ValueComponent')).toEqual(props.ValueComponent);
|
|
@@ -16,10 +16,7 @@ const getDefaultProps = () => ({
|
|
|
16
16
|
toggleValue: sinon.spy(),
|
|
17
17
|
option: {value: 1, label: 'one'},
|
|
18
18
|
index: 0,
|
|
19
|
-
setIndex: sinon.spy()
|
|
20
|
-
toggleCollapsedValue: jest.fn(),
|
|
21
|
-
collapsibleOptions: null,
|
|
22
|
-
currentText: ''
|
|
19
|
+
setIndex: sinon.spy()
|
|
23
20
|
});
|
|
24
21
|
|
|
25
22
|
test('it renders checkbox based on isSelected', () => {
|
|
@@ -48,7 +45,7 @@ test('it renders custom label if passed in', () => {
|
|
|
48
45
|
expect(wrapper.findWhere(whereClassName(styles.label)).text()).toEqual(label);
|
|
49
46
|
});
|
|
50
47
|
|
|
51
|
-
test('it
|
|
48
|
+
test('it pases classes to SelectOption based on props', () => {
|
|
52
49
|
const props = getDefaultProps();
|
|
53
50
|
const wrapper = shallow(<MultiSelectOption {...props} />);
|
|
54
51
|
expect(wrapper.find(SelectOption).prop('className')).toEqual(styles['option']);
|
|
@@ -61,34 +58,3 @@ test('it passes classes to SelectOption based on props', () => {
|
|
|
61
58
|
classnames(styles.option, styles.disabled, styles.highlighted)
|
|
62
59
|
);
|
|
63
60
|
});
|
|
64
|
-
|
|
65
|
-
describe('collapsibleOption classname', function(){
|
|
66
|
-
it('renders indented class when option has collapsedBy is a part of collapsibleOption', function(){
|
|
67
|
-
const props = getDefaultProps();
|
|
68
|
-
const wrapper = shallow(<MultiSelectOption {...props} />);
|
|
69
|
-
|
|
70
|
-
// no collapsedOptions and no collapsible -> no class
|
|
71
|
-
expect(wrapper.find(SelectOption).prop('className').includes(styles['option__indented'])).toBe(false);
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
// collapsedOptions set but no collapsible -> no class
|
|
75
|
-
wrapper.setProps({collapsibleOptions: [3, 4]});
|
|
76
|
-
expect(wrapper.find(SelectOption).prop('className').includes(styles['option__indented'])).toBe(false);
|
|
77
|
-
|
|
78
|
-
// collapsedOptions set and collapsedBy -> has class
|
|
79
|
-
wrapper.setProps({
|
|
80
|
-
option: { value: 1, label: 'One', collapsedBy: 3}
|
|
81
|
-
});
|
|
82
|
-
expect(wrapper.find(SelectOption).prop('className').includes(styles['option__indented'])).toBe(true);
|
|
83
|
-
|
|
84
|
-
// collapsedOptions set but doesnt match collapsedBy -> no class
|
|
85
|
-
wrapper.setProps({
|
|
86
|
-
option: { value: 1, label: 'One', collapsedBy: 6}
|
|
87
|
-
});
|
|
88
|
-
expect(wrapper.find(SelectOption).prop('className').includes(styles['option__indented'])).toBe(false);
|
|
89
|
-
|
|
90
|
-
// collapsedOptions empty -> no class
|
|
91
|
-
wrapper.setProps({collapsibleOptions: []});
|
|
92
|
-
expect(wrapper.find(SelectOption).prop('className').includes(styles['option__indented'])).toBe(false);
|
|
93
|
-
});
|
|
94
|
-
});
|
|
@@ -7,7 +7,6 @@ import SingleSelectOption from '../SingleSelectOption';
|
|
|
7
7
|
import BasicMinLengthComponent from '../BasicMinLengthComponent';
|
|
8
8
|
import BasicEmptyOptionComponent from '../BasicEmptyOptionComponent';
|
|
9
9
|
import KEYS from '../../utils/keys';
|
|
10
|
-
import { OPTION_COLLAPSED, OPTION_NOT_COLLAPSED } from '../../constants';
|
|
11
10
|
|
|
12
11
|
let defaultProps;
|
|
13
12
|
|
|
@@ -25,9 +24,7 @@ beforeEach(function(){
|
|
|
25
24
|
toggleValue: jest.fn(),
|
|
26
25
|
setIndex: jest.fn(),
|
|
27
26
|
reference: React.createRef(),
|
|
28
|
-
menuId: 'menu-1'
|
|
29
|
-
getCollapsibleState: () => null,
|
|
30
|
-
toggleCollapsedValue: jest.fn()
|
|
27
|
+
menuId: 'menu-1'
|
|
31
28
|
};
|
|
32
29
|
});
|
|
33
30
|
|
|
@@ -193,23 +190,3 @@ describe('move scrollbar position', function() {
|
|
|
193
190
|
|
|
194
191
|
});
|
|
195
192
|
|
|
196
|
-
|
|
197
|
-
describe('collapsibleState', function(){
|
|
198
|
-
it('calls getCollapsibleState with the options and passes the result to the components', function(){
|
|
199
|
-
const getCollapsibleState = jest.fn().mockImplementation((value) => {
|
|
200
|
-
return value % 2 == 0 ? OPTION_COLLAPSED : OPTION_NOT_COLLAPSED;
|
|
201
|
-
});
|
|
202
|
-
|
|
203
|
-
const wrapper = mount(<OptionListSet {...defaultProps} getCollapsibleState={getCollapsibleState}/>);
|
|
204
|
-
expect(getCollapsibleState).toHaveBeenCalledTimes(2);
|
|
205
|
-
expect(getCollapsibleState).toHaveBeenCalledWith(basicOptions[0].value);
|
|
206
|
-
expect(getCollapsibleState).toHaveBeenCalledWith(basicOptions[1].value);
|
|
207
|
-
|
|
208
|
-
expect(
|
|
209
|
-
wrapper.find(SingleSelectOption).at(0).prop('collapsibleState')
|
|
210
|
-
).toEqual(OPTION_NOT_COLLAPSED);
|
|
211
|
-
expect(
|
|
212
|
-
wrapper.find(SingleSelectOption).at(1).prop('collapsibleState')
|
|
213
|
-
).toEqual(OPTION_COLLAPSED);
|
|
214
|
-
});
|
|
215
|
-
});
|
|
@@ -3,8 +3,6 @@ import { shallow, mount } from 'enzyme';
|
|
|
3
3
|
import SelectCore, { PureSelectCore } from '../SelectCore';
|
|
4
4
|
import SingleSelectValueAdapter from '../../adapters/SingleSelectValueAdapter';
|
|
5
5
|
import MultiSelectValueAdapter from '../../adapters/MultiSelectValueAdapter';
|
|
6
|
-
import { OPTION_NOT_COLLAPSED, OPTION_COLLAPSED } from '../../constants';
|
|
7
|
-
|
|
8
6
|
import { createFakeEvent } from 'test/utils/enzyme-utils';
|
|
9
7
|
|
|
10
8
|
const MenuComponent = () => <ul></ul>;
|
|
@@ -492,107 +490,6 @@ describe('filtering options', function(){
|
|
|
492
490
|
wrapper.instance()._getFilteredOptions();
|
|
493
491
|
expect(mockFilterOption).toHaveBeenCalledTimes(4);
|
|
494
492
|
});
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
it('calls onOptionsFiltered with filtered options', function(){
|
|
498
|
-
const onOptionsFiltered = jest.fn();
|
|
499
|
-
const wrapper = mount(<PureSelectCore {...defaultProps} filterOption={filterOption} onOptionsFiltered={onOptionsFiltered} />, {lifecycleExperimental: true});
|
|
500
|
-
wrapper.instance().changeText('Tw');
|
|
501
|
-
expect(onOptionsFiltered).toHaveBeenCalledTimes(1);
|
|
502
|
-
expect(onOptionsFiltered).toHaveBeenCalledWith([defaultProps.options[1]]);
|
|
503
|
-
wrapper.instance().changeText('');
|
|
504
|
-
expect(onOptionsFiltered).toHaveBeenCalledTimes(2);
|
|
505
|
-
expect(onOptionsFiltered).toHaveBeenCalledWith(defaultProps.options);
|
|
506
|
-
});
|
|
507
|
-
|
|
508
|
-
it('calls onChangeText with updated text', function(){
|
|
509
|
-
const onChangeText = jest.fn();
|
|
510
|
-
const wrapper = mount(<PureSelectCore {...defaultProps} filterOption={filterOption} onChangeText={onChangeText} />, {lifecycleExperimental: true});
|
|
511
|
-
wrapper.instance().changeText('Tw');
|
|
512
|
-
expect(onChangeText).toHaveBeenCalledTimes(1);
|
|
513
|
-
expect(onChangeText).toHaveBeenCalledWith('Tw');
|
|
514
|
-
wrapper.instance().changeText('');
|
|
515
|
-
expect(onChangeText).toHaveBeenCalledTimes(2);
|
|
516
|
-
expect(onChangeText).toHaveBeenCalledWith('');
|
|
517
|
-
});
|
|
518
|
-
});
|
|
519
|
-
|
|
520
|
-
describe('collapse behavior', function () {
|
|
521
|
-
const optionsWithCollapse = [{value: 1, label: 'One'}, {value: 2, label: 'Two', collapsedBy: 1}, {value: 3, label: 'Three', collapsedBy: 1}, {value: 4, label: 'Four'}, {value: 5, label: 'Five', collapsedBy: 4}]
|
|
522
|
-
|
|
523
|
-
describe('when there are no collapsibleOptions', function ( ) {
|
|
524
|
-
it('does not return collapsible state and does not filter options', function(){
|
|
525
|
-
const wrapper = shallow(<PureSelectCore {...defaultProps} options={optionsWithCollapse} />);
|
|
526
|
-
expect(wrapper.instance().getCollapsibleState(1)).toEqual(null)
|
|
527
|
-
expect(wrapper.instance().getCollapsibleState(2)).toEqual(null)
|
|
528
|
-
expect(wrapper.instance().getCollapsibleState(3)).toEqual(null)
|
|
529
|
-
expect(wrapper.instance().getCollapsibleState(4)).toEqual(null)
|
|
530
|
-
expect(wrapper.instance().getCollapsibleState(5)).toEqual(null)
|
|
531
|
-
expect(wrapper.instance()._getFilteredOptions()).toEqual(optionsWithCollapse);
|
|
532
|
-
wrapper.instance().toggleCollapsedValue(1);
|
|
533
|
-
expect(wrapper.instance().getCollapsibleState(1)).toEqual(null)
|
|
534
|
-
expect(wrapper.instance().getCollapsibleState(2)).toEqual(null)
|
|
535
|
-
expect(wrapper.instance().getCollapsibleState(3)).toEqual(null)
|
|
536
|
-
expect(wrapper.instance().getCollapsibleState(4)).toEqual(null)
|
|
537
|
-
expect(wrapper.instance().getCollapsibleState(5)).toEqual(null)
|
|
538
|
-
expect(wrapper.instance()._getFilteredOptions()).toEqual(optionsWithCollapse);
|
|
539
|
-
});
|
|
540
|
-
});
|
|
541
|
-
|
|
542
|
-
describe('when collapsibleOptions are provided but select is filtered', function () {
|
|
543
|
-
it('does not return collapsible state and does not filter options', function(){
|
|
544
|
-
const wrapper = shallow(<PureSelectCore {...defaultProps} options={optionsWithCollapse} collapsibleOptions={[1, 4]} />);
|
|
545
|
-
wrapper.instance().toggleCollapsedValue(1);
|
|
546
|
-
wrapper.instance().changeText('Tw');
|
|
547
|
-
expect(wrapper.instance().getCollapsibleState(1)).toEqual(null)
|
|
548
|
-
expect(wrapper.instance().getCollapsibleState(2)).toEqual(null)
|
|
549
|
-
expect(wrapper.instance().getCollapsibleState(3)).toEqual(null)
|
|
550
|
-
expect(wrapper.instance().getCollapsibleState(4)).toEqual(null)
|
|
551
|
-
expect(wrapper.instance().getCollapsibleState(5)).toEqual(null)
|
|
552
|
-
// becaused filtered, we are returning it even though its referenced by collapsedBy
|
|
553
|
-
expect(wrapper.instance()._getFilteredOptions()).toEqual([optionsWithCollapse[1]]);
|
|
554
|
-
});
|
|
555
|
-
});
|
|
556
|
-
|
|
557
|
-
describe('when collapsedValue is not one of the collapsibleOptions', function(){
|
|
558
|
-
it('returns null and not collapsed for others', function(){
|
|
559
|
-
const wrapper = shallow(<PureSelectCore {...defaultProps} options={optionsWithCollapse} collapsibleOptions={[1, 4]} />);
|
|
560
|
-
wrapper.instance().toggleCollapsedValue(2);
|
|
561
|
-
expect(wrapper.instance().getCollapsibleState(1)).toEqual(OPTION_NOT_COLLAPSED)
|
|
562
|
-
expect(wrapper.instance().getCollapsibleState(2)).toEqual(null)
|
|
563
|
-
expect(wrapper.instance().getCollapsibleState(3)).toEqual(null)
|
|
564
|
-
expect(wrapper.instance().getCollapsibleState(4)).toEqual(OPTION_NOT_COLLAPSED)
|
|
565
|
-
expect(wrapper.instance().getCollapsibleState(5)).toEqual(null)
|
|
566
|
-
expect(wrapper.instance()._getFilteredOptions()).toEqual(optionsWithCollapse);
|
|
567
|
-
});
|
|
568
|
-
})
|
|
569
|
-
|
|
570
|
-
describe('when value is collapsed', function() {
|
|
571
|
-
it('returns OPTION_COLLAPSED and filters out options with collapsedBy attribute', function () {
|
|
572
|
-
const wrapper = shallow(<PureSelectCore {...defaultProps} options={optionsWithCollapse} collapsibleOptions={[1, 4]} />);
|
|
573
|
-
wrapper.instance().toggleCollapsedValue(1);
|
|
574
|
-
expect(wrapper.instance().getCollapsibleState(1)).toEqual(OPTION_COLLAPSED)
|
|
575
|
-
expect(wrapper.instance().getCollapsibleState(2)).toEqual(null)
|
|
576
|
-
expect(wrapper.instance().getCollapsibleState(3)).toEqual(null)
|
|
577
|
-
expect(wrapper.instance().getCollapsibleState(4)).toEqual(OPTION_NOT_COLLAPSED)
|
|
578
|
-
expect(wrapper.instance().getCollapsibleState(5)).toEqual(null)
|
|
579
|
-
expect(wrapper.instance()._getFilteredOptions()).toEqual([optionsWithCollapse[0], optionsWithCollapse[3], optionsWithCollapse[4]]);
|
|
580
|
-
});
|
|
581
|
-
});
|
|
582
|
-
|
|
583
|
-
describe('when value is toggled', function() {
|
|
584
|
-
it('returns OPTION_NOT_COLLAPSED and does not filter out options with collapsedBy attribute', function(){
|
|
585
|
-
const wrapper = shallow(<PureSelectCore {...defaultProps} options={optionsWithCollapse} collapsibleOptions={[1, 4]} />);
|
|
586
|
-
wrapper.instance().toggleCollapsedValue(1);
|
|
587
|
-
wrapper.instance().toggleCollapsedValue(1);
|
|
588
|
-
expect(wrapper.instance().getCollapsibleState(1)).toEqual(OPTION_NOT_COLLAPSED)
|
|
589
|
-
expect(wrapper.instance().getCollapsibleState(2)).toEqual(null)
|
|
590
|
-
expect(wrapper.instance().getCollapsibleState(3)).toEqual(null)
|
|
591
|
-
expect(wrapper.instance().getCollapsibleState(4)).toEqual(OPTION_NOT_COLLAPSED)
|
|
592
|
-
expect(wrapper.instance().getCollapsibleState(5)).toEqual(null)
|
|
593
|
-
expect(wrapper.instance()._getFilteredOptions()).toEqual(optionsWithCollapse);
|
|
594
|
-
});
|
|
595
|
-
});
|
|
596
493
|
});
|
|
597
494
|
|
|
598
495
|
describe('render components', function(){
|
|
@@ -3,8 +3,7 @@ import { shallow } from 'enzyme';
|
|
|
3
3
|
|
|
4
4
|
import { createFakeEvent } from 'test/utils/enzyme-utils';
|
|
5
5
|
import SelectOption from '../SelectOption';
|
|
6
|
-
|
|
7
|
-
import { OPTION_NOT_COLLAPSED, OPTION_COLLAPSED } from '../../constants';
|
|
6
|
+
|
|
8
7
|
|
|
9
8
|
let defaultProps;
|
|
10
9
|
|
|
@@ -18,9 +17,7 @@ beforeEach(function(){
|
|
|
18
17
|
option: {value: 1, label: 'one'},
|
|
19
18
|
unselectOnClick: true,
|
|
20
19
|
renderOptionLabel: jest.fn(),
|
|
21
|
-
index: 0
|
|
22
|
-
toggleCollapsedValue: jest.fn(),
|
|
23
|
-
collapsibleState: null
|
|
20
|
+
index: 0
|
|
24
21
|
};
|
|
25
22
|
})
|
|
26
23
|
|
|
@@ -66,31 +63,3 @@ test('it triggers setIndex on mouse enter', () => {
|
|
|
66
63
|
wrapper.find('li').simulate('mouseenter');
|
|
67
64
|
expect(defaultProps.setIndex).toHaveBeenCalledTimes(1);
|
|
68
65
|
});
|
|
69
|
-
|
|
70
|
-
test('it renders Collapse if collapsibleState is not null', function(){
|
|
71
|
-
const wrapper = shallow(<SelectOption {...defaultProps}><span /></SelectOption>);
|
|
72
|
-
expect(wrapper.find(Collapse).length).toEqual(0);
|
|
73
|
-
wrapper.setProps({collapsibleState: OPTION_COLLAPSED});
|
|
74
|
-
expect(wrapper.find(Collapse).length).toEqual(1);
|
|
75
|
-
expect(wrapper.find(Collapse).at(0).prop('collapsibleState')).toEqual(OPTION_COLLAPSED);
|
|
76
|
-
|
|
77
|
-
wrapper.setProps({collapsibleState: OPTION_NOT_COLLAPSED});
|
|
78
|
-
expect(wrapper.find(Collapse).length).toEqual(1);
|
|
79
|
-
expect(wrapper.find(Collapse).at(0).prop('collapsibleState')).toEqual(OPTION_NOT_COLLAPSED);
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
test('clicking on Collapse calls toggleCollapsedValue', function(){
|
|
83
|
-
const wrapper = shallow(<SelectOption {...defaultProps} collapsibleState={OPTION_COLLAPSED}><span /></SelectOption>);
|
|
84
|
-
expect(defaultProps.toggleCollapsedValue).not.toHaveBeenCalled();
|
|
85
|
-
const e = {stopPropagation: jest.fn(), nativeEvent: { stopImmediatePropagation: jest.fn()}};
|
|
86
|
-
wrapper.find(Collapse).at(0).simulate('click', e);
|
|
87
|
-
expect(defaultProps.toggleCollapsedValue).toHaveBeenCalledWith(defaultProps.option.value);
|
|
88
|
-
expect(e.stopPropagation).toHaveBeenCalled();
|
|
89
|
-
expect(e.nativeEvent.stopImmediatePropagation).toHaveBeenCalled();
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
test('adds classname if option.optionClassName', function(){
|
|
93
|
-
const option = {label: 'One', value: 1, optionClassName: 'some-class'};
|
|
94
|
-
const wrapper = shallow(<SelectOption {...defaultProps} option={option}><span /></SelectOption>);
|
|
95
|
-
expect(wrapper.find('li').hasClass('some-class')).toBe(true);
|
|
96
|
-
});
|
|
@@ -15,8 +15,7 @@ const getDefaultProps = () => ({
|
|
|
15
15
|
option: {value: 1, label: 'one'},
|
|
16
16
|
isHighlighted: false,
|
|
17
17
|
index: 0,
|
|
18
|
-
setIndex: sinon.spy()
|
|
19
|
-
toggleCollapsedValue: jest.fn()
|
|
18
|
+
setIndex: sinon.spy()
|
|
20
19
|
});
|
|
21
20
|
|
|
22
21
|
test('it passes the correct classnames based on props', () => {
|