@dhis2-ui/select 10.13.0-alpha.1 → 10.13.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/build/cjs/locales/en/translations.json +2 -0
- package/build/cjs/multi-select/input.js +20 -11
- package/build/cjs/multi-select/multi-select.js +5 -1
- package/build/cjs/multi-select/multi-select.prod.stories.js +42 -1
- package/build/cjs/simple-single-select/menu/filter.js +23 -36
- package/build/cjs/simple-single-select/menu/menu.js +4 -36
- package/build/cjs/simple-single-select/menu/options-list.js +5 -13
- package/build/cjs/simple-single-select/selected-value/selected-value.js +26 -1
- package/build/cjs/simple-single-select/simple-single-select.js +20 -16
- package/build/cjs/simple-single-select/use-handle-key-press/use-handle-key-press-on-combobox.js +24 -15
- package/build/cjs/simple-single-select/use-handle-key-press/use-handle-key-press-on-filter-input.js +1 -3
- package/build/cjs/simple-single-select-field/simple-single-select-field.js +23 -3
- package/build/cjs/simple-single-select-field/simple-single-select-field.test.js +5 -2
- package/build/es/locales/en/translations.json +2 -0
- package/build/es/multi-select/input.js +16 -7
- package/build/es/multi-select/multi-select.js +5 -1
- package/build/es/multi-select/multi-select.prod.stories.js +40 -0
- package/build/es/simple-single-select/menu/filter.js +22 -33
- package/build/es/simple-single-select/menu/menu.js +4 -36
- package/build/es/simple-single-select/menu/options-list.js +5 -13
- package/build/es/simple-single-select/selected-value/selected-value.js +26 -1
- package/build/es/simple-single-select/simple-single-select.js +20 -16
- package/build/es/simple-single-select/use-handle-key-press/use-handle-key-press-on-combobox.js +24 -15
- package/build/es/simple-single-select/use-handle-key-press/use-handle-key-press-on-filter-input.js +1 -3
- package/build/es/simple-single-select-field/simple-single-select-field.js +23 -3
- package/build/es/simple-single-select-field/simple-single-select-field.test.js +5 -2
- package/package.json +15 -15
- package/types/index.d.ts +4 -0
|
@@ -10,7 +10,8 @@ var _uiConstants = require("@dhis2/ui-constants");
|
|
|
10
10
|
var _classnames = _interopRequireDefault(require("classnames"));
|
|
11
11
|
var _propTypes2 = _interopRequireDefault(require("prop-types"));
|
|
12
12
|
var _react = _interopRequireDefault(require("react"));
|
|
13
|
-
var _index = require("../
|
|
13
|
+
var _index = _interopRequireDefault(require("../locales/index.js"));
|
|
14
|
+
var _index2 = require("../select/index.js");
|
|
14
15
|
var _selectionList = require("./selection-list.js");
|
|
15
16
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
16
17
|
const Input = _ref => {
|
|
@@ -25,9 +26,11 @@ const Input = _ref => {
|
|
|
25
26
|
options,
|
|
26
27
|
className,
|
|
27
28
|
disabled,
|
|
28
|
-
inputMaxHeight = '100px'
|
|
29
|
+
inputMaxHeight = '100px',
|
|
30
|
+
collapseSelectionAfter
|
|
29
31
|
} = _ref;
|
|
30
32
|
const hasSelection = selected.length > 0;
|
|
33
|
+
const shouldCollapse = hasSelection && typeof collapseSelectionAfter === 'number' && selected.length > collapseSelectionAfter;
|
|
31
34
|
const onClear = e => {
|
|
32
35
|
const data = {
|
|
33
36
|
selected: []
|
|
@@ -36,30 +39,35 @@ const Input = _ref => {
|
|
|
36
39
|
onChange(data, e);
|
|
37
40
|
};
|
|
38
41
|
return /*#__PURE__*/_react.default.createElement("div", {
|
|
39
|
-
className: _style.default.dynamic([["
|
|
40
|
-
}, /*#__PURE__*/_react.default.createElement(
|
|
42
|
+
className: _style.default.dynamic([["3188585639", [_uiConstants.colors.grey900]], ["1331770409", [inputMaxHeight]]]) + " " + ((0, _classnames.default)('root', className) || "")
|
|
43
|
+
}, /*#__PURE__*/_react.default.createElement(_index2.InputPrefix, {
|
|
41
44
|
prefix: prefix,
|
|
42
45
|
dataTest: `${dataTest}-prefix`
|
|
43
|
-
}), !hasSelection && !prefix && /*#__PURE__*/_react.default.createElement(
|
|
46
|
+
}), !hasSelection && !prefix && /*#__PURE__*/_react.default.createElement(_index2.InputPlaceholder, {
|
|
44
47
|
placeholder: placeholder,
|
|
45
48
|
dataTest: `${dataTest}-placeholder`
|
|
46
|
-
}), hasSelection && /*#__PURE__*/_react.default.createElement("
|
|
47
|
-
|
|
49
|
+
}), hasSelection && shouldCollapse && /*#__PURE__*/_react.default.createElement("span", {
|
|
50
|
+
"data-test": `${dataTest}-selection-count`,
|
|
51
|
+
className: _style.default.dynamic([["3188585639", [_uiConstants.colors.grey900]], ["1331770409", [inputMaxHeight]]]) + " " + "collapsed-selection-text"
|
|
52
|
+
}, _index.default.t('{{count}} selected', {
|
|
53
|
+
count: selected.length
|
|
54
|
+
})), hasSelection && !shouldCollapse && /*#__PURE__*/_react.default.createElement("div", {
|
|
55
|
+
className: _style.default.dynamic([["3188585639", [_uiConstants.colors.grey900]], ["1331770409", [inputMaxHeight]]]) + " " + "root-input"
|
|
48
56
|
}, /*#__PURE__*/_react.default.createElement(_selectionList.SelectionList, {
|
|
49
57
|
selected: selected,
|
|
50
58
|
onChange: onChange,
|
|
51
59
|
options: options,
|
|
52
60
|
disabled: disabled
|
|
53
61
|
})), hasSelection && clearable && !disabled && /*#__PURE__*/_react.default.createElement("div", {
|
|
54
|
-
className: _style.default.dynamic([["
|
|
55
|
-
}, /*#__PURE__*/_react.default.createElement(
|
|
62
|
+
className: _style.default.dynamic([["3188585639", [_uiConstants.colors.grey900]], ["1331770409", [inputMaxHeight]]]) + " " + "root-right"
|
|
63
|
+
}, /*#__PURE__*/_react.default.createElement(_index2.InputClearButton, {
|
|
56
64
|
onClear: onClear,
|
|
57
65
|
clearText: clearText,
|
|
58
66
|
dataTest: `${dataTest}-clear`
|
|
59
67
|
})), /*#__PURE__*/_react.default.createElement(_style.default, {
|
|
60
|
-
id: "
|
|
68
|
+
id: "3188585639",
|
|
61
69
|
dynamic: [_uiConstants.colors.grey900]
|
|
62
|
-
}, [`.root.__jsx-style-dynamic-selector{display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;-webkit-align-items:center;-webkit-box-align:center;-ms-flex-align:center;align-items:center;color:${_uiConstants.colors.grey900};font-size:14px;line-height:16px;}`, ".root-input.__jsx-style-dynamic-selector{overflow-y:auto;-webkit-flex:1;-ms-flex:1;flex:1;display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;-webkit-flex-flow:wrap;-ms-flex-flow:wrap;flex-flow:wrap;gap:4px;}", ".root-right.__jsx-style-dynamic-selector{margin-inline-start:auto;}"]), /*#__PURE__*/_react.default.createElement(_style.default, {
|
|
70
|
+
}, [`.root.__jsx-style-dynamic-selector{display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;-webkit-align-items:center;-webkit-box-align:center;-ms-flex-align:center;align-items:center;color:${_uiConstants.colors.grey900};font-size:14px;line-height:16px;}`, ".root-input.__jsx-style-dynamic-selector{overflow-y:auto;-webkit-flex:1;-ms-flex:1;flex:1;display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;-webkit-flex-flow:wrap;-ms-flex-flow:wrap;flex-flow:wrap;gap:4px;}", ".root-right.__jsx-style-dynamic-selector{margin-inline-start:auto;}", ".collapsed-selection-text.__jsx-style-dynamic-selector{-webkit-flex:1;-ms-flex:1;flex:1;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;}"]), /*#__PURE__*/_react.default.createElement(_style.default, {
|
|
63
71
|
id: "1331770409",
|
|
64
72
|
dynamic: [inputMaxHeight]
|
|
65
73
|
}, [`.root-input.__jsx-style-dynamic-selector{max-height:${inputMaxHeight};}`]));
|
|
@@ -70,6 +78,7 @@ Input.propTypes = {
|
|
|
70
78
|
className: _propTypes2.default.string,
|
|
71
79
|
clearText: (0, _propTypes.requiredIf)(props => props.clearable, _propTypes2.default.string),
|
|
72
80
|
clearable: _propTypes2.default.bool,
|
|
81
|
+
collapseSelectionAfter: _propTypes2.default.number,
|
|
73
82
|
disabled: _propTypes2.default.bool,
|
|
74
83
|
inputMaxHeight: _propTypes2.default.string,
|
|
75
84
|
options: _propTypes2.default.node,
|
|
@@ -45,6 +45,7 @@ const MultiSelect = _ref => {
|
|
|
45
45
|
noMatchText,
|
|
46
46
|
initialFocus,
|
|
47
47
|
dense,
|
|
48
|
+
collapseSelectionAfter,
|
|
48
49
|
dataTest = 'dhis2-uicore-multiselect'
|
|
49
50
|
} = _ref;
|
|
50
51
|
// If the select is filterable, use a filterable menu
|
|
@@ -71,7 +72,8 @@ const MultiSelect = _ref => {
|
|
|
71
72
|
dataTest: dataTest,
|
|
72
73
|
placeholder: placeholder,
|
|
73
74
|
prefix: prefix,
|
|
74
|
-
inputMaxHeight: inputMaxHeight
|
|
75
|
+
inputMaxHeight: inputMaxHeight,
|
|
76
|
+
collapseSelectionAfter: collapseSelectionAfter
|
|
75
77
|
}),
|
|
76
78
|
menu: menu,
|
|
77
79
|
tabIndex: tabIndex,
|
|
@@ -106,6 +108,8 @@ MultiSelect.propTypes = {
|
|
|
106
108
|
clearText: (0, _propTypes.requiredIf)(props => props.clearable, _propTypes2.default.string),
|
|
107
109
|
/** Adds a 'clear' option to the menu */
|
|
108
110
|
clearable: _propTypes2.default.bool,
|
|
111
|
+
/** When the number of selected items exceeds this threshold, chips are replaced with "X selected" text */
|
|
112
|
+
collapseSelectionAfter: _propTypes2.default.number,
|
|
109
113
|
dataTest: _propTypes2.default.string,
|
|
110
114
|
dense: _propTypes2.default.bool,
|
|
111
115
|
disabled: _propTypes2.default.bool,
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.default = exports.WithPrefixAndSelection = exports.WithPrefix = exports.WithPlaceholderAndSelection = exports.WithPlaceholder = exports.WithOptionsLoadingAndLoadingText = exports.WithOptionsAndOnChange = exports.WithOptionsAndMultipleSelections = exports.WithOptionsAndLoading = exports.WithOptionsAndDisabled = exports.WithOptionsAndASelection = exports.WithOptionsASelectionAndDisabled = exports.WithOnFocus = exports.WithOnBlur = exports.WithMultipleSelectionsWrapped = exports.WithMoreThanThreeOptionsAndA100PxMaxHeight = exports.WithMoreThanTenOptions = exports.WithInvalidOptions = exports.WithInvalidFilterableOptions = exports.WithInitialFocus = exports.WithFilterField = exports.WithDisabledOptionAndOnChange = exports.WithCustomOptionsAndOnChange = exports.WithClearButtonSelectionAndOnChange = exports.ShiftedIntoView = exports.RTL = exports.FlippedPosition = exports.EmptyWithEmptyText = exports.EmptyWithEmptyComponent = exports.Empty = exports.DenseWithSelections = exports.Dense = exports.DefaultPosition = void 0;
|
|
6
|
+
exports.default = exports.WithPrefixAndSelection = exports.WithPrefix = exports.WithPlaceholderAndSelection = exports.WithPlaceholder = exports.WithOptionsLoadingAndLoadingText = exports.WithOptionsAndOnChange = exports.WithOptionsAndMultipleSelections = exports.WithOptionsAndLoading = exports.WithOptionsAndDisabled = exports.WithOptionsAndASelection = exports.WithOptionsASelectionAndDisabled = exports.WithOnFocus = exports.WithOnBlur = exports.WithMultipleSelectionsWrapped = exports.WithMoreThanThreeOptionsAndA100PxMaxHeight = exports.WithMoreThanTenOptions = exports.WithInvalidOptions = exports.WithInvalidFilterableOptions = exports.WithInitialFocus = exports.WithFilterField = exports.WithDisabledOptionAndOnChange = exports.WithCustomOptionsAndOnChange = exports.WithClearButtonSelectionAndOnChange = exports.ShiftedIntoView = exports.RTL = exports.FlippedPosition = exports.EmptyWithEmptyText = exports.EmptyWithEmptyComponent = exports.Empty = exports.DenseWithSelections = exports.Dense = exports.DefaultPosition = exports.CollapseSelectionAfterThreshold = void 0;
|
|
7
7
|
var _style = _interopRequireDefault(require("styled-jsx/style"));
|
|
8
8
|
var _uiConstants = require("@dhis2/ui-constants");
|
|
9
9
|
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
@@ -513,6 +513,47 @@ const ShiftedIntoView = args => /*#__PURE__*/_react.default.createElement(_react
|
|
|
513
513
|
id: "1828862170"
|
|
514
514
|
}, ["html,body,#root{position:relative;height:300px !important;max-height:300px;}", "#root{padding-top:130px !important;}"]));
|
|
515
515
|
exports.ShiftedIntoView = ShiftedIntoView;
|
|
516
|
+
const CollapseSelectionAfterThreshold = () => {
|
|
517
|
+
const [selected, setSelected] = _react.default.useState(['1', '3', '5']);
|
|
518
|
+
return /*#__PURE__*/_react.default.createElement("div", {
|
|
519
|
+
style: {
|
|
520
|
+
maxWidth: 400
|
|
521
|
+
}
|
|
522
|
+
}, /*#__PURE__*/_react.default.createElement(_index2.MultiSelect, {
|
|
523
|
+
className: "select",
|
|
524
|
+
selected: selected,
|
|
525
|
+
onChange: _ref3 => {
|
|
526
|
+
let {
|
|
527
|
+
selected
|
|
528
|
+
} = _ref3;
|
|
529
|
+
return setSelected(selected);
|
|
530
|
+
},
|
|
531
|
+
collapseSelectionAfter: 2,
|
|
532
|
+
prefix: "Prefix text",
|
|
533
|
+
clearable: true,
|
|
534
|
+
clearText: "Clear all"
|
|
535
|
+
}, /*#__PURE__*/_react.default.createElement(_index.MultiSelectOption, {
|
|
536
|
+
value: "1",
|
|
537
|
+
label: "option one"
|
|
538
|
+
}), /*#__PURE__*/_react.default.createElement(_index.MultiSelectOption, {
|
|
539
|
+
value: "2",
|
|
540
|
+
label: "option two"
|
|
541
|
+
}), /*#__PURE__*/_react.default.createElement(_index.MultiSelectOption, {
|
|
542
|
+
value: "3",
|
|
543
|
+
label: "option three"
|
|
544
|
+
}), /*#__PURE__*/_react.default.createElement(_index.MultiSelectOption, {
|
|
545
|
+
value: "4",
|
|
546
|
+
label: "option four"
|
|
547
|
+
}), /*#__PURE__*/_react.default.createElement(_index.MultiSelectOption, {
|
|
548
|
+
value: "5",
|
|
549
|
+
label: "option five"
|
|
550
|
+
}), /*#__PURE__*/_react.default.createElement(_index.MultiSelectOption, {
|
|
551
|
+
value: "6",
|
|
552
|
+
label: "option six"
|
|
553
|
+
})));
|
|
554
|
+
};
|
|
555
|
+
exports.CollapseSelectionAfterThreshold = CollapseSelectionAfterThreshold;
|
|
556
|
+
CollapseSelectionAfterThreshold.storyName = 'Collapse selection after threshold';
|
|
516
557
|
const RTL = args => {
|
|
517
558
|
(0, _react.useEffect)(() => {
|
|
518
559
|
document.body.dir = 'rtl';
|
|
@@ -3,64 +3,51 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.Filter =
|
|
6
|
+
exports.Filter = Filter;
|
|
7
7
|
var _style = _interopRequireDefault(require("styled-jsx/style"));
|
|
8
|
-
var _uiConstants = require("@dhis2/ui-constants");
|
|
9
|
-
var _input = require("@dhis2-ui/input");
|
|
10
8
|
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
11
|
-
var _react =
|
|
9
|
+
var _react = _interopRequireDefault(require("react"));
|
|
12
10
|
var _index = _interopRequireDefault(require("../../locales/index.js"));
|
|
13
|
-
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
14
|
-
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
15
11
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
16
|
-
|
|
12
|
+
function Filter(_ref) {
|
|
17
13
|
let {
|
|
18
14
|
ariaControls,
|
|
19
15
|
dataTest,
|
|
16
|
+
inputRef,
|
|
20
17
|
label,
|
|
21
18
|
placeholder,
|
|
22
|
-
tabIndex,
|
|
23
19
|
value,
|
|
24
20
|
onChange,
|
|
25
|
-
onKeyDown
|
|
26
|
-
onFocus
|
|
21
|
+
onKeyDown
|
|
27
22
|
} = _ref;
|
|
28
|
-
return /*#__PURE__*/_react.default.createElement("
|
|
29
|
-
|
|
30
|
-
className: _style.default.dynamic([["3850436710", [_uiConstants.colors.white, _uiConstants.spacers.dp8, _uiConstants.spacers.dp8, _uiConstants.spacers.dp4, _uiConstants.spacers.dp8]]])
|
|
31
|
-
}, /*#__PURE__*/_react.default.createElement(_input.Input, {
|
|
32
|
-
dense: true,
|
|
33
|
-
ref: ref,
|
|
34
|
-
tabIndex: tabIndex,
|
|
35
|
-
ariaControls: ariaControls,
|
|
36
|
-
ariaHaspopup: "listbox",
|
|
37
|
-
ariaLabel: label || _index.default.t('Search options'),
|
|
38
|
-
dataTest: `${dataTest}-input`,
|
|
39
|
-
value: value,
|
|
40
|
-
onChange: _ref2 => {
|
|
41
|
-
let {
|
|
42
|
-
value
|
|
43
|
-
} = _ref2;
|
|
44
|
-
return onChange(value);
|
|
45
|
-
},
|
|
23
|
+
return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement("input", {
|
|
24
|
+
ref: inputRef,
|
|
46
25
|
type: "text",
|
|
47
26
|
name: "filter",
|
|
27
|
+
value: value,
|
|
48
28
|
placeholder: placeholder,
|
|
49
|
-
|
|
50
|
-
|
|
29
|
+
"aria-label": label || _index.default.t('Search options'),
|
|
30
|
+
"aria-controls": ariaControls,
|
|
31
|
+
"aria-haspopup": "listbox",
|
|
32
|
+
"data-test": dataTest,
|
|
33
|
+
onChange: e => onChange(e.target.value),
|
|
34
|
+
onClick: e => e.stopPropagation(),
|
|
35
|
+
onKeyDown: e => {
|
|
36
|
+
e.stopPropagation();
|
|
37
|
+
onKeyDown === null || onKeyDown === void 0 ? void 0 : onKeyDown(e);
|
|
38
|
+
},
|
|
39
|
+
className: "jsx-1122123784" + " " + "filter-input"
|
|
51
40
|
}), /*#__PURE__*/_react.default.createElement(_style.default, {
|
|
52
|
-
id: "
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
});
|
|
41
|
+
id: "1122123784"
|
|
42
|
+
}, [".filter-input.jsx-1122123784{-webkit-flex:1;-ms-flex:1;flex:1;border:none;outline:none;background:transparent;font-size:14px;line-height:16px;color:inherit;padding:0;min-width:0;}"]));
|
|
43
|
+
}
|
|
56
44
|
Filter.propTypes = {
|
|
57
45
|
ariaControls: _propTypes.default.string.isRequired,
|
|
46
|
+
inputRef: _propTypes.default.object.isRequired,
|
|
58
47
|
value: _propTypes.default.string.isRequired,
|
|
59
48
|
onChange: _propTypes.default.func.isRequired,
|
|
60
49
|
dataTest: _propTypes.default.string,
|
|
61
50
|
label: _propTypes.default.string,
|
|
62
51
|
placeholder: _propTypes.default.string,
|
|
63
|
-
tabIndex: _propTypes.default.string,
|
|
64
|
-
onFocus: _propTypes.default.func,
|
|
65
52
|
onKeyDown: _propTypes.default.func
|
|
66
53
|
};
|
|
@@ -12,7 +12,6 @@ var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
|
12
12
|
var _react = _interopRequireWildcard(require("react"));
|
|
13
13
|
var _sharedPropTypes = require("../shared-prop-types.js");
|
|
14
14
|
var _empty = require("./empty.js");
|
|
15
|
-
var _filter = require("./filter.js");
|
|
16
15
|
var _loading = require("./loading.js");
|
|
17
16
|
var _noMatch = require("./no-match.js");
|
|
18
17
|
var _optionsList = require("./options-list.js");
|
|
@@ -30,10 +29,7 @@ function Menu(_ref) {
|
|
|
30
29
|
dataTest,
|
|
31
30
|
disabled,
|
|
32
31
|
empty,
|
|
33
|
-
filterLabel,
|
|
34
|
-
filterPlaceholder,
|
|
35
32
|
filterValue,
|
|
36
|
-
filterable,
|
|
37
33
|
hidden,
|
|
38
34
|
labelledBy,
|
|
39
35
|
listBoxRef,
|
|
@@ -44,14 +40,9 @@ function Menu(_ref) {
|
|
|
44
40
|
optionUpdateStrategy,
|
|
45
41
|
selectRef,
|
|
46
42
|
selectedValue,
|
|
47
|
-
tabIndex,
|
|
48
43
|
onBlur,
|
|
49
44
|
onClose,
|
|
50
|
-
onEndReached
|
|
51
|
-
onFilterChange,
|
|
52
|
-
onFilterInputKeyDown,
|
|
53
|
-
filterRef,
|
|
54
|
-
onOptionsKeyDown
|
|
45
|
+
onEndReached
|
|
55
46
|
} = _ref;
|
|
56
47
|
const [menuWidth, setWidth] = (0, _react.useState)('auto');
|
|
57
48
|
const dataTestPrefix = `${dataTest}-menu`;
|
|
@@ -85,25 +76,12 @@ function Menu(_ref) {
|
|
|
85
76
|
maxHeight
|
|
86
77
|
},
|
|
87
78
|
className: _style.default.dynamic([["2949029222", [_uiConstants.colors.white, _uiConstants.colors.grey200, _uiConstants.elevations.e300]]]) + " " + "menu"
|
|
88
|
-
},
|
|
89
|
-
className: _style.default.dynamic([["2949029222", [_uiConstants.colors.white, _uiConstants.colors.grey200, _uiConstants.elevations.e300]]]) + " " + "filter-container"
|
|
90
|
-
}, /*#__PURE__*/_react.default.createElement(_filter.Filter, {
|
|
91
|
-
ref: filterRef,
|
|
92
|
-
dataTest: `${dataTestPrefix}-filter`,
|
|
93
|
-
value: filterValue,
|
|
94
|
-
label: filterLabel,
|
|
95
|
-
ariaControls: `${name}-listbox`,
|
|
96
|
-
placeholder: filterPlaceholder,
|
|
97
|
-
tabIndex: tabIndex,
|
|
98
|
-
onChange: onFilterChange,
|
|
99
|
-
onKeyDown: onFilterInputKeyDown
|
|
100
|
-
})), isEmpty && /*#__PURE__*/_react.default.createElement(_empty.Empty, null, empty), hasNoFilterMatch && /*#__PURE__*/_react.default.createElement(_noMatch.NoMatch, null, noMatchText), /*#__PURE__*/_react.default.createElement("div", {
|
|
79
|
+
}, isEmpty && /*#__PURE__*/_react.default.createElement(_empty.Empty, null, empty), hasNoFilterMatch && /*#__PURE__*/_react.default.createElement(_noMatch.NoMatch, null, noMatchText), /*#__PURE__*/_react.default.createElement("div", {
|
|
101
80
|
className: _style.default.dynamic([["2949029222", [_uiConstants.colors.white, _uiConstants.colors.grey200, _uiConstants.elevations.e300]]]) + " " + "listbox-container"
|
|
102
81
|
}, /*#__PURE__*/_react.default.createElement("div", {
|
|
103
82
|
className: _style.default.dynamic([["2949029222", [_uiConstants.colors.white, _uiConstants.colors.grey200, _uiConstants.elevations.e300]]]) + " " + "listbox-wrapper"
|
|
104
83
|
}, /*#__PURE__*/_react.default.createElement(_optionsList.OptionsList, {
|
|
105
84
|
ref: listBoxRef,
|
|
106
|
-
onKeyDown: onOptionsKeyDown,
|
|
107
85
|
comboBoxId: comboBoxId,
|
|
108
86
|
optionComponent: optionComponent,
|
|
109
87
|
dataTest: `${dataTestPrefix}-list`,
|
|
@@ -135,16 +113,11 @@ Menu.propTypes = {
|
|
|
135
113
|
}).isRequired,
|
|
136
114
|
name: _propTypes.default.string.isRequired,
|
|
137
115
|
options: _propTypes.default.arrayOf(_sharedPropTypes.optionProp).isRequired,
|
|
116
|
+
onChange: _propTypes.default.func.isRequired,
|
|
138
117
|
dataTest: _propTypes.default.string,
|
|
139
118
|
disabled: _propTypes.default.bool,
|
|
140
119
|
empty: _propTypes.default.node,
|
|
141
|
-
filterLabel: _propTypes.default.string,
|
|
142
|
-
filterPlaceholder: _propTypes.default.string,
|
|
143
|
-
filterRef: _propTypes.default.shape({
|
|
144
|
-
current: _propTypes.default.instanceOf(HTMLElement)
|
|
145
|
-
}),
|
|
146
120
|
filterValue: _propTypes.default.string,
|
|
147
|
-
filterable: _propTypes.default.bool,
|
|
148
121
|
hidden: _propTypes.default.bool,
|
|
149
122
|
labelledBy: _propTypes.default.string,
|
|
150
123
|
loading: _propTypes.default.bool,
|
|
@@ -155,12 +128,7 @@ Menu.propTypes = {
|
|
|
155
128
|
optionUpdateStrategy: _propTypes.default.oneOf(['off', 'polite', 'assertive']),
|
|
156
129
|
selectRef: _propTypes.default.instanceOf(HTMLElement),
|
|
157
130
|
selectedValue: _propTypes.default.string,
|
|
158
|
-
tabIndex: _propTypes.default.string,
|
|
159
131
|
onBlur: _propTypes.default.func,
|
|
160
|
-
onChange: _propTypes.default.func,
|
|
161
132
|
onClose: _propTypes.default.func,
|
|
162
|
-
onEndReached: _propTypes.default.func
|
|
163
|
-
onFilterChange: _propTypes.default.func,
|
|
164
|
-
onFilterInputKeyDown: _propTypes.default.func,
|
|
165
|
-
onOptionsKeyDown: _propTypes.default.func
|
|
133
|
+
onEndReached: _propTypes.default.func
|
|
166
134
|
};
|
|
@@ -4,7 +4,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.OptionsList = void 0;
|
|
7
|
-
var _style = _interopRequireDefault(require("styled-jsx/style"));
|
|
8
7
|
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
9
8
|
var _react = _interopRequireWildcard(require("react"));
|
|
10
9
|
var _isOptionHidden = require("../is-option-hidden.js");
|
|
@@ -28,8 +27,7 @@ const OptionsList = exports.OptionsList = /*#__PURE__*/(0, _react.forwardRef)(fu
|
|
|
28
27
|
loading,
|
|
29
28
|
onChange,
|
|
30
29
|
onBlur,
|
|
31
|
-
onEndReached
|
|
32
|
-
onKeyDown
|
|
30
|
+
onEndReached
|
|
33
31
|
} = _ref;
|
|
34
32
|
// scrolls the highlighted option into view when:
|
|
35
33
|
// * the highlighted option changes
|
|
@@ -50,15 +48,12 @@ const OptionsList = exports.OptionsList = /*#__PURE__*/(0, _react.forwardRef)(fu
|
|
|
50
48
|
return /*#__PURE__*/_react.default.createElement("div", {
|
|
51
49
|
ref: ref,
|
|
52
50
|
role: "listbox",
|
|
53
|
-
tabIndex: "-1",
|
|
54
51
|
id: id,
|
|
55
52
|
"aria-labelledby": labelledBy,
|
|
56
53
|
"aria-live": optionUpdateStrategy,
|
|
57
54
|
"aria-busy": loading.toString(),
|
|
58
55
|
"data-test": dataTest,
|
|
59
|
-
onBlur: onBlur
|
|
60
|
-
onKeyDown: onKeyDown,
|
|
61
|
-
className: "jsx-233683301"
|
|
56
|
+
onBlur: onBlur
|
|
62
57
|
}, options.map((_ref2, index) => {
|
|
63
58
|
let {
|
|
64
59
|
value,
|
|
@@ -82,15 +77,14 @@ const OptionsList = exports.OptionsList = /*#__PURE__*/(0, _react.forwardRef)(fu
|
|
|
82
77
|
component: component || optionComponent,
|
|
83
78
|
onBecameVisible: isLast ? onEndReached : undefined
|
|
84
79
|
});
|
|
85
|
-
})
|
|
86
|
-
id: "233683301"
|
|
87
|
-
}, ["div.jsx-233683301{outline:none;}"]));
|
|
80
|
+
}));
|
|
88
81
|
});
|
|
89
82
|
OptionsList.propTypes = {
|
|
90
83
|
comboBoxId: _propTypes.default.string.isRequired,
|
|
91
84
|
focussedOptionIndex: _propTypes.default.number.isRequired,
|
|
92
85
|
id: _propTypes.default.string.isRequired,
|
|
93
86
|
options: _propTypes.default.arrayOf(_sharedPropTypes.optionProp).isRequired,
|
|
87
|
+
onChange: _propTypes.default.func.isRequired,
|
|
94
88
|
dataTest: _propTypes.default.string,
|
|
95
89
|
disabled: _propTypes.default.bool,
|
|
96
90
|
labelledBy: _propTypes.default.string,
|
|
@@ -99,7 +93,5 @@ OptionsList.propTypes = {
|
|
|
99
93
|
optionUpdateStrategy: _propTypes.default.oneOf(['off', 'polite', 'assertive']),
|
|
100
94
|
selectedValue: _propTypes.default.string,
|
|
101
95
|
onBlur: _propTypes.default.func,
|
|
102
|
-
|
|
103
|
-
onEndReached: _propTypes.default.func,
|
|
104
|
-
onKeyDown: _propTypes.default.func
|
|
96
|
+
onEndReached: _propTypes.default.func
|
|
105
97
|
};
|
|
@@ -8,6 +8,7 @@ var _style = _interopRequireDefault(require("styled-jsx/style"));
|
|
|
8
8
|
var _uiIcons = require("@dhis2/ui-icons");
|
|
9
9
|
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
10
10
|
var _react = _interopRequireDefault(require("react"));
|
|
11
|
+
var _filter = require("../menu/filter.js");
|
|
11
12
|
var _clearButton = require("./clear-button.js");
|
|
12
13
|
var _container = require("./container.js");
|
|
13
14
|
var _placeholder = require("./placeholder.js");
|
|
@@ -28,6 +29,11 @@ function SelectedValue(_ref) {
|
|
|
28
29
|
disabled,
|
|
29
30
|
error,
|
|
30
31
|
expanded,
|
|
32
|
+
filterLabel,
|
|
33
|
+
filterPlaceholder,
|
|
34
|
+
filterRef,
|
|
35
|
+
filterable,
|
|
36
|
+
filterValue,
|
|
31
37
|
hasSelection,
|
|
32
38
|
inputMaxHeight,
|
|
33
39
|
labelledBy,
|
|
@@ -39,9 +45,12 @@ function SelectedValue(_ref) {
|
|
|
39
45
|
onBlur,
|
|
40
46
|
onClear,
|
|
41
47
|
onClick,
|
|
48
|
+
onFilterChange,
|
|
49
|
+
onFilterInputKeyDown,
|
|
42
50
|
onFocus
|
|
43
51
|
} = _ref;
|
|
44
52
|
const dataTestPrefix = `${dataTest}-selectedvalue`;
|
|
53
|
+
const showFilter = filterable && expanded;
|
|
45
54
|
return /*#__PURE__*/_react.default.createElement(_container.Container, {
|
|
46
55
|
dataTest: `${dataTestPrefix}-container`,
|
|
47
56
|
ref: comboBoxRef,
|
|
@@ -64,7 +73,16 @@ function SelectedValue(_ref) {
|
|
|
64
73
|
}, prefix && /*#__PURE__*/_react.default.createElement(_prefix.Prefix, {
|
|
65
74
|
dataTest: `${dataTestPrefix}-prefix`,
|
|
66
75
|
prefix: prefix
|
|
67
|
-
}), /*#__PURE__*/_react.default.createElement(
|
|
76
|
+
}), showFilter ? /*#__PURE__*/_react.default.createElement(_filter.Filter, {
|
|
77
|
+
inputRef: filterRef,
|
|
78
|
+
ariaControls: `${name}-listbox`,
|
|
79
|
+
dataTest: `${dataTestPrefix}-filter`,
|
|
80
|
+
label: filterLabel,
|
|
81
|
+
placeholder: filterPlaceholder,
|
|
82
|
+
value: filterValue,
|
|
83
|
+
onChange: onFilterChange,
|
|
84
|
+
onKeyDown: onFilterInputKeyDown
|
|
85
|
+
}) : /*#__PURE__*/_react.default.createElement("div", {
|
|
68
86
|
tabIndex: "-1",
|
|
69
87
|
className: _style.default.dynamic([["3226769786", [inputMaxHeight]]]) + " " + "selected-option-label"
|
|
70
88
|
}, !selectedLabel && !prefix && placeholder && /*#__PURE__*/_react.default.createElement(_placeholder.Placeholder, {
|
|
@@ -91,6 +109,7 @@ function SelectedValue(_ref) {
|
|
|
91
109
|
SelectedValue.propTypes = {
|
|
92
110
|
clearText: _propTypes.default.string.isRequired,
|
|
93
111
|
comboBoxId: _propTypes.default.string.isRequired,
|
|
112
|
+
filterRef: _propTypes.default.object.isRequired,
|
|
94
113
|
name: _propTypes.default.string.isRequired,
|
|
95
114
|
selectedLabel: _propTypes.default.string.isRequired,
|
|
96
115
|
onKeyDown: _propTypes.default.func.isRequired,
|
|
@@ -104,6 +123,10 @@ SelectedValue.propTypes = {
|
|
|
104
123
|
disabled: _propTypes.default.bool,
|
|
105
124
|
error: _propTypes.default.bool,
|
|
106
125
|
expanded: _propTypes.default.bool,
|
|
126
|
+
filterLabel: _propTypes.default.string,
|
|
127
|
+
filterPlaceholder: _propTypes.default.string,
|
|
128
|
+
filterValue: _propTypes.default.string,
|
|
129
|
+
filterable: _propTypes.default.bool,
|
|
107
130
|
hasSelection: _propTypes.default.bool,
|
|
108
131
|
inputMaxHeight: _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.number]),
|
|
109
132
|
labelledBy: _propTypes.default.string,
|
|
@@ -115,5 +138,7 @@ SelectedValue.propTypes = {
|
|
|
115
138
|
onBlur: _propTypes.default.func,
|
|
116
139
|
onClear: _propTypes.default.func,
|
|
117
140
|
onClick: _propTypes.default.func,
|
|
141
|
+
onFilterChange: _propTypes.default.func,
|
|
142
|
+
onFilterInputKeyDown: _propTypes.default.func,
|
|
118
143
|
onFocus: _propTypes.default.func
|
|
119
144
|
};
|
|
@@ -67,7 +67,6 @@ function SimpleSingleSelect(_ref2) {
|
|
|
67
67
|
disabled = false,
|
|
68
68
|
empty: _empty = false,
|
|
69
69
|
error = false,
|
|
70
|
-
filterHelpText = '',
|
|
71
70
|
filterLabel = '',
|
|
72
71
|
filterPlaceholder: _filterPlaceholder = '',
|
|
73
72
|
filterValue = '',
|
|
@@ -104,7 +103,7 @@ function SimpleSingleSelect(_ref2) {
|
|
|
104
103
|
const comboBoxId = `${name}-combo`;
|
|
105
104
|
const comboBoxRef = (0, _react.useRef)();
|
|
106
105
|
const listBoxRef = (0, _react.useRef)();
|
|
107
|
-
const
|
|
106
|
+
const filterInputRef = (0, _react.useRef)();
|
|
108
107
|
const [focussedOptionIndex, setFocussedOptionIndex] = useFocussedOptionIndex({
|
|
109
108
|
filterable,
|
|
110
109
|
filterValue,
|
|
@@ -112,6 +111,14 @@ function SimpleSingleSelect(_ref2) {
|
|
|
112
111
|
});
|
|
113
112
|
const [selectRef, setSelectRef] = (0, _react.useState)();
|
|
114
113
|
const [expanded, setExpanded] = (0, _react.useState)(false);
|
|
114
|
+
(0, _react.useEffect)(() => {
|
|
115
|
+
if (expanded && filterable) {
|
|
116
|
+
requestAnimationFrame(() => {
|
|
117
|
+
var _filterInputRef$curre;
|
|
118
|
+
(_filterInputRef$curre = filterInputRef.current) === null || _filterInputRef$curre === void 0 ? void 0 : _filterInputRef$curre.focus();
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
}, [expanded, filterable]);
|
|
115
122
|
const closeMenu = (0, _react.useCallback)(() => setExpanded(false), []);
|
|
116
123
|
const selectedValue = (selected === null || selected === void 0 ? void 0 : selected.value) || '';
|
|
117
124
|
const selectedLabel = (selected === null || selected === void 0 ? void 0 : selected.label) || '';
|
|
@@ -155,9 +162,10 @@ function SimpleSingleSelect(_ref2) {
|
|
|
155
162
|
focussedOptionIndex,
|
|
156
163
|
setFocussedOptionIndex,
|
|
157
164
|
selectFocussedOption,
|
|
158
|
-
filterRef,
|
|
159
165
|
clearable,
|
|
160
|
-
onClear
|
|
166
|
+
onClear,
|
|
167
|
+
filterable,
|
|
168
|
+
onFilterChange
|
|
161
169
|
});
|
|
162
170
|
const handleKeyDownOnFilterInput = (0, _index4.useHandleKeyPressOnFilterInput)({
|
|
163
171
|
value: selectedValue,
|
|
@@ -197,6 +205,11 @@ function SimpleSingleSelect(_ref2) {
|
|
|
197
205
|
disabled: disabled,
|
|
198
206
|
error: error,
|
|
199
207
|
expanded: expanded,
|
|
208
|
+
filterLabel: filterLabel,
|
|
209
|
+
filterPlaceholder: filterPlaceholder,
|
|
210
|
+
filterRef: filterInputRef,
|
|
211
|
+
filterable: filterable,
|
|
212
|
+
filterValue: filterValue,
|
|
200
213
|
hasSelection: !!selectedValue,
|
|
201
214
|
inputMaxHeight: inputMaxHeight,
|
|
202
215
|
labelledBy: labelledBy,
|
|
@@ -210,6 +223,8 @@ function SimpleSingleSelect(_ref2) {
|
|
|
210
223
|
onBlur: onBlur,
|
|
211
224
|
onClear: onClear,
|
|
212
225
|
onClick: toggleMenu,
|
|
226
|
+
onFilterChange: onFilterChange,
|
|
227
|
+
onFilterInputKeyDown: handleKeyDownOnFilterInput,
|
|
213
228
|
onFocus: onFocus,
|
|
214
229
|
onKeyDown: handleKeyDown
|
|
215
230
|
}), /*#__PURE__*/_react.default.createElement(_index2.Menu, {
|
|
@@ -217,13 +232,8 @@ function SimpleSingleSelect(_ref2) {
|
|
|
217
232
|
optionComponent: optionComponent,
|
|
218
233
|
disabled: disabled,
|
|
219
234
|
empty: empty,
|
|
220
|
-
filterHelpText: filterHelpText,
|
|
221
|
-
filterLabel: filterLabel,
|
|
222
|
-
filterable: filterable,
|
|
223
235
|
filterValue: filterValue,
|
|
224
|
-
filterPlaceholder: filterPlaceholder,
|
|
225
236
|
focussedOptionIndex: focussedOptionIndex,
|
|
226
|
-
onFilterInputKeyDown: handleKeyDownOnFilterInput,
|
|
227
237
|
hidden: !expanded,
|
|
228
238
|
name: name,
|
|
229
239
|
labelledBy: labelledBy,
|
|
@@ -236,17 +246,13 @@ function SimpleSingleSelect(_ref2) {
|
|
|
236
246
|
options: options,
|
|
237
247
|
selectRef: selectRef,
|
|
238
248
|
selectedValue: selectedValue,
|
|
239
|
-
tabIndex: tabIndex.toString(),
|
|
240
249
|
onBlur: onBlur,
|
|
241
250
|
onChange: nextValue => {
|
|
242
251
|
onChange(nextValue);
|
|
243
252
|
closeMenu();
|
|
244
253
|
},
|
|
245
254
|
onClose: closeMenu,
|
|
246
|
-
onEndReached: onEndReached
|
|
247
|
-
onFilterChange: onFilterChange,
|
|
248
|
-
filterRef: filterRef,
|
|
249
|
-
onOptionsKeyDown: handleKeyDown
|
|
255
|
+
onEndReached: onEndReached
|
|
250
256
|
}));
|
|
251
257
|
}
|
|
252
258
|
SimpleSingleSelect.propTypes = {
|
|
@@ -274,8 +280,6 @@ SimpleSingleSelect.propTypes = {
|
|
|
274
280
|
empty: _propTypes2.default.node,
|
|
275
281
|
/** Applies 'error' appearance for validation feedback. Mutually exclusive with `warning` and `valid` props **/
|
|
276
282
|
error: _uiConstants.sharedPropTypes.statusPropType,
|
|
277
|
-
/** Help text that will be displayed below the input **/
|
|
278
|
-
filterHelpText: _propTypes2.default.string,
|
|
279
283
|
/** Value will be used as aria-label attribute on the filter input **/
|
|
280
284
|
filterLabel: _propTypes2.default.string,
|
|
281
285
|
/** Placeholder for the filter input **/
|