@dhis2-ui/select 10.10.0-alpha.2 → 10.10.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/simple-single-select/__stories__/WithMultipleSelectsAndScrollableParent.js +44 -0
- package/build/cjs/simple-single-select/selected-value/clear-button.js +10 -26
- package/build/cjs/simple-single-select/simple-single-select.js +3 -0
- package/build/cjs/simple-single-select/simple-single-select.prod.stories.js +7 -7
- package/build/es/simple-single-select/__stories__/WithMultipleSelectsAndScrollableParent.js +36 -0
- package/build/es/simple-single-select/selected-value/clear-button.js +10 -26
- package/build/es/simple-single-select/simple-single-select.js +3 -0
- package/build/es/simple-single-select/simple-single-select.prod.stories.js +1 -1
- package/package.json +15 -15
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.WithMultipleSelectsAndScrollableParent = void 0;
|
|
7
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
8
|
+
var _simpleSingleSelect = require("../simple-single-select.js");
|
|
9
|
+
var _options = require("./options.js");
|
|
10
|
+
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); }
|
|
11
|
+
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; }
|
|
12
|
+
// simulating when the first option value is not empty string
|
|
13
|
+
const fiveOptions = [{
|
|
14
|
+
label: 'None',
|
|
15
|
+
value: 'unknown'
|
|
16
|
+
}, ..._options.fiveOptions.slice(1)];
|
|
17
|
+
const WithMultipleSelectsAndScrollableParent = () => {
|
|
18
|
+
const [selected, setSelected] = (0, _react.useState)(null);
|
|
19
|
+
const [selected2, setSelected2] = (0, _react.useState)(null);
|
|
20
|
+
return /*#__PURE__*/_react.default.createElement("div", {
|
|
21
|
+
style: {
|
|
22
|
+
overflow: 'scroll',
|
|
23
|
+
height: '250px'
|
|
24
|
+
}
|
|
25
|
+
}, "Selected value from first select: ", JSON.stringify(selected), /*#__PURE__*/_react.default.createElement(_simpleSingleSelect.SimpleSingleSelect, {
|
|
26
|
+
inputMaxHeight: "50px",
|
|
27
|
+
name: "simple",
|
|
28
|
+
selected: selected,
|
|
29
|
+
onChange: setSelected,
|
|
30
|
+
options: fiveOptions
|
|
31
|
+
}), /*#__PURE__*/_react.default.createElement("br", null), "Selected value from second select: ", JSON.stringify(selected2), /*#__PURE__*/_react.default.createElement(_simpleSingleSelect.SimpleSingleSelect, {
|
|
32
|
+
inputMaxHeight: "50px",
|
|
33
|
+
name: "simple",
|
|
34
|
+
selected: selected2,
|
|
35
|
+
onChange: setSelected2,
|
|
36
|
+
options: fiveOptions,
|
|
37
|
+
clearable: true,
|
|
38
|
+
onClear: () => setSelected2(null)
|
|
39
|
+
}), /*#__PURE__*/_react.default.createElement("br", null), /*#__PURE__*/_react.default.createElement("input", {
|
|
40
|
+
type: "text",
|
|
41
|
+
placeholder: "just another field"
|
|
42
|
+
}), /*#__PURE__*/_react.default.createElement("br", null), /*#__PURE__*/_react.default.createElement("br", null), /*#__PURE__*/_react.default.createElement("div", null, "Some text to force a window with scrolling (to validate the KeyDown on the combo box does not scroll the whole window)", /*#__PURE__*/_react.default.createElement("br", null), /*#__PURE__*/_react.default.createElement("br", null), "Some more text..", /*#__PURE__*/_react.default.createElement("br", null), /*#__PURE__*/_react.default.createElement("br", null), /*#__PURE__*/_react.default.createElement("br", null), /*#__PURE__*/_react.default.createElement("br", null), /*#__PURE__*/_react.default.createElement("br", null), /*#__PURE__*/_react.default.createElement("br", null), /*#__PURE__*/_react.default.createElement("br", null), /*#__PURE__*/_react.default.createElement("br", null), "Some text to force scrolling", /*#__PURE__*/_react.default.createElement("br", null), /*#__PURE__*/_react.default.createElement("br", null), /*#__PURE__*/_react.default.createElement("br", null), /*#__PURE__*/_react.default.createElement("br", null), /*#__PURE__*/_react.default.createElement("br", null), /*#__PURE__*/_react.default.createElement("br", null), "Some text to force scrolling"));
|
|
43
|
+
};
|
|
44
|
+
exports.WithMultipleSelectsAndScrollableParent = WithMultipleSelectsAndScrollableParent;
|
|
@@ -3,10 +3,9 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.ClearButton =
|
|
6
|
+
exports.ClearButton = ClearButton;
|
|
7
7
|
var _style = _interopRequireDefault(require("styled-jsx/style"));
|
|
8
8
|
var _uiConstants = require("@dhis2/ui-constants");
|
|
9
|
-
var _tooltip = require("@dhis2-ui/tooltip");
|
|
10
9
|
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
11
10
|
var _react = _interopRequireDefault(require("react"));
|
|
12
11
|
var _index = _interopRequireDefault(require("../../locales/index.js"));
|
|
@@ -21,7 +20,16 @@ function ClearButton(_ref) {
|
|
|
21
20
|
"aria-label": _index.default.t('{{clearText}}', {
|
|
22
21
|
clearText
|
|
23
22
|
}),
|
|
23
|
+
title: _index.default.t('{{clearText}}', {
|
|
24
|
+
clearText
|
|
25
|
+
}),
|
|
24
26
|
"data-test": dataTest,
|
|
27
|
+
onKeyDown: e => {
|
|
28
|
+
if (e.key === 'Enter' || e.key === 'space') {
|
|
29
|
+
// otherwise, Enter propagates to parent menu and opens the combo
|
|
30
|
+
e.stopPropagation();
|
|
31
|
+
}
|
|
32
|
+
},
|
|
25
33
|
onClick: e => {
|
|
26
34
|
e.stopPropagation();
|
|
27
35
|
onClear();
|
|
@@ -47,28 +55,4 @@ ClearButton.propTypes = {
|
|
|
47
55
|
clearText: _propTypes.default.string.isRequired,
|
|
48
56
|
onClear: _propTypes.default.func.isRequired,
|
|
49
57
|
dataTest: _propTypes.default.string
|
|
50
|
-
};
|
|
51
|
-
function ClearButtonWithTooltip(_ref2) {
|
|
52
|
-
let {
|
|
53
|
-
onClear,
|
|
54
|
-
clearText,
|
|
55
|
-
dataTest
|
|
56
|
-
} = _ref2;
|
|
57
|
-
const clearButton = /*#__PURE__*/_react.default.createElement(ClearButton, {
|
|
58
|
-
onClear: onClear,
|
|
59
|
-
dataTest: dataTest,
|
|
60
|
-
clearText: clearText
|
|
61
|
-
});
|
|
62
|
-
if (!clearText) {
|
|
63
|
-
return clearButton;
|
|
64
|
-
}
|
|
65
|
-
return /*#__PURE__*/_react.default.createElement(_tooltip.Tooltip, {
|
|
66
|
-
openDelay: 500,
|
|
67
|
-
content: clearText
|
|
68
|
-
}, clearButton);
|
|
69
|
-
}
|
|
70
|
-
ClearButtonWithTooltip.propTypes = {
|
|
71
|
-
clearText: _propTypes.default.string.isRequired,
|
|
72
|
-
onClear: _propTypes.default.func.isRequired,
|
|
73
|
-
dataTest: _propTypes.default.string
|
|
74
58
|
};
|
|
@@ -119,6 +119,9 @@ function SimpleSingleSelect(_ref2) {
|
|
|
119
119
|
if (selectedOptionIndex !== focussedOptionIndex) {
|
|
120
120
|
setFocussedOptionIndex(selectedOptionIndex);
|
|
121
121
|
}
|
|
122
|
+
if (selectedOptionIndex === -1) {
|
|
123
|
+
setFocussedOptionIndex(0);
|
|
124
|
+
}
|
|
122
125
|
setExpanded(true);
|
|
123
126
|
}, [options, selectedValue, focussedOptionIndex, setFocussedOptionIndex]);
|
|
124
127
|
const toggleMenu = (0, _react.useCallback)(() => {
|
|
@@ -99,6 +99,12 @@ Object.defineProperty(exports, "WithManyOptions", {
|
|
|
99
99
|
return _WithManyOptions.WithManyOptions;
|
|
100
100
|
}
|
|
101
101
|
});
|
|
102
|
+
Object.defineProperty(exports, "WithMultipleSelectsAndScrollableParent", {
|
|
103
|
+
enumerable: true,
|
|
104
|
+
get: function () {
|
|
105
|
+
return _WithMultipleSelectsAndScrollableParent.WithMultipleSelectsAndScrollableParent;
|
|
106
|
+
}
|
|
107
|
+
});
|
|
102
108
|
Object.defineProperty(exports, "WithNoMatchText", {
|
|
103
109
|
enumerable: true,
|
|
104
110
|
get: function () {
|
|
@@ -165,12 +171,6 @@ Object.defineProperty(exports, "WithRTL", {
|
|
|
165
171
|
return _WithRTL.WithRTL;
|
|
166
172
|
}
|
|
167
173
|
});
|
|
168
|
-
Object.defineProperty(exports, "WithScrollingParent", {
|
|
169
|
-
enumerable: true,
|
|
170
|
-
get: function () {
|
|
171
|
-
return _WithScrollingParent.WithScrollingParent;
|
|
172
|
-
}
|
|
173
|
-
});
|
|
174
174
|
Object.defineProperty(exports, "WithSelection", {
|
|
175
175
|
enumerable: true,
|
|
176
176
|
get: function () {
|
|
@@ -228,7 +228,7 @@ var _WithNoMatchText = require("./__stories__/WithNoMatchText.js");
|
|
|
228
228
|
var _DefaultPosition = require("./__stories__/DefaultPosition.js");
|
|
229
229
|
var _FlippedPosition = require("./__stories__/FlippedPosition.js");
|
|
230
230
|
var _ShiftedIntoView = require("./__stories__/ShiftedIntoView.js");
|
|
231
|
-
var
|
|
231
|
+
var _WithMultipleSelectsAndScrollableParent = require("./__stories__/WithMultipleSelectsAndScrollableParent.js");
|
|
232
232
|
var _default = exports.default = {
|
|
233
233
|
title: 'Simple Single Select',
|
|
234
234
|
component: _simpleSingleSelect.SimpleSingleSelect
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import React, { useState } from 'react';
|
|
2
|
+
import { SimpleSingleSelect } from '../simple-single-select.js';
|
|
3
|
+
import { fiveOptions as originalOptions } from './options.js';
|
|
4
|
+
|
|
5
|
+
// simulating when the first option value is not empty string
|
|
6
|
+
const fiveOptions = [{
|
|
7
|
+
label: 'None',
|
|
8
|
+
value: 'unknown'
|
|
9
|
+
}, ...originalOptions.slice(1)];
|
|
10
|
+
export const WithMultipleSelectsAndScrollableParent = () => {
|
|
11
|
+
const [selected, setSelected] = useState(null);
|
|
12
|
+
const [selected2, setSelected2] = useState(null);
|
|
13
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
14
|
+
style: {
|
|
15
|
+
overflow: 'scroll',
|
|
16
|
+
height: '250px'
|
|
17
|
+
}
|
|
18
|
+
}, "Selected value from first select: ", JSON.stringify(selected), /*#__PURE__*/React.createElement(SimpleSingleSelect, {
|
|
19
|
+
inputMaxHeight: "50px",
|
|
20
|
+
name: "simple",
|
|
21
|
+
selected: selected,
|
|
22
|
+
onChange: setSelected,
|
|
23
|
+
options: fiveOptions
|
|
24
|
+
}), /*#__PURE__*/React.createElement("br", null), "Selected value from second select: ", JSON.stringify(selected2), /*#__PURE__*/React.createElement(SimpleSingleSelect, {
|
|
25
|
+
inputMaxHeight: "50px",
|
|
26
|
+
name: "simple",
|
|
27
|
+
selected: selected2,
|
|
28
|
+
onChange: setSelected2,
|
|
29
|
+
options: fiveOptions,
|
|
30
|
+
clearable: true,
|
|
31
|
+
onClear: () => setSelected2(null)
|
|
32
|
+
}), /*#__PURE__*/React.createElement("br", null), /*#__PURE__*/React.createElement("input", {
|
|
33
|
+
type: "text",
|
|
34
|
+
placeholder: "just another field"
|
|
35
|
+
}), /*#__PURE__*/React.createElement("br", null), /*#__PURE__*/React.createElement("br", null), /*#__PURE__*/React.createElement("div", null, "Some text to force a window with scrolling (to validate the KeyDown on the combo box does not scroll the whole window)", /*#__PURE__*/React.createElement("br", null), /*#__PURE__*/React.createElement("br", null), "Some more text..", /*#__PURE__*/React.createElement("br", null), /*#__PURE__*/React.createElement("br", null), /*#__PURE__*/React.createElement("br", null), /*#__PURE__*/React.createElement("br", null), /*#__PURE__*/React.createElement("br", null), /*#__PURE__*/React.createElement("br", null), /*#__PURE__*/React.createElement("br", null), /*#__PURE__*/React.createElement("br", null), "Some text to force scrolling", /*#__PURE__*/React.createElement("br", null), /*#__PURE__*/React.createElement("br", null), /*#__PURE__*/React.createElement("br", null), /*#__PURE__*/React.createElement("br", null), /*#__PURE__*/React.createElement("br", null), /*#__PURE__*/React.createElement("br", null), "Some text to force scrolling"));
|
|
36
|
+
};
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import _JSXStyle from "styled-jsx/style";
|
|
2
2
|
import { colors, theme } from '@dhis2/ui-constants';
|
|
3
|
-
import { Tooltip } from '@dhis2-ui/tooltip';
|
|
4
3
|
import PropTypes from 'prop-types';
|
|
5
4
|
import React from 'react';
|
|
6
5
|
import i18n from '../../locales/index.js';
|
|
@@ -14,7 +13,16 @@ function ClearButton(_ref) {
|
|
|
14
13
|
"aria-label": i18n.t('{{clearText}}', {
|
|
15
14
|
clearText
|
|
16
15
|
}),
|
|
16
|
+
title: i18n.t('{{clearText}}', {
|
|
17
|
+
clearText
|
|
18
|
+
}),
|
|
17
19
|
"data-test": dataTest,
|
|
20
|
+
onKeyDown: e => {
|
|
21
|
+
if (e.key === 'Enter' || e.key === 'space') {
|
|
22
|
+
// otherwise, Enter propagates to parent menu and opens the combo
|
|
23
|
+
e.stopPropagation();
|
|
24
|
+
}
|
|
25
|
+
},
|
|
18
26
|
onClick: e => {
|
|
19
27
|
e.stopPropagation();
|
|
20
28
|
onClear();
|
|
@@ -41,28 +49,4 @@ ClearButton.propTypes = {
|
|
|
41
49
|
onClear: PropTypes.func.isRequired,
|
|
42
50
|
dataTest: PropTypes.string
|
|
43
51
|
};
|
|
44
|
-
|
|
45
|
-
let {
|
|
46
|
-
onClear,
|
|
47
|
-
clearText,
|
|
48
|
-
dataTest
|
|
49
|
-
} = _ref2;
|
|
50
|
-
const clearButton = /*#__PURE__*/React.createElement(ClearButton, {
|
|
51
|
-
onClear: onClear,
|
|
52
|
-
dataTest: dataTest,
|
|
53
|
-
clearText: clearText
|
|
54
|
-
});
|
|
55
|
-
if (!clearText) {
|
|
56
|
-
return clearButton;
|
|
57
|
-
}
|
|
58
|
-
return /*#__PURE__*/React.createElement(Tooltip, {
|
|
59
|
-
openDelay: 500,
|
|
60
|
-
content: clearText
|
|
61
|
-
}, clearButton);
|
|
62
|
-
}
|
|
63
|
-
ClearButtonWithTooltip.propTypes = {
|
|
64
|
-
clearText: PropTypes.string.isRequired,
|
|
65
|
-
onClear: PropTypes.func.isRequired,
|
|
66
|
-
dataTest: PropTypes.string
|
|
67
|
-
};
|
|
68
|
-
export { ClearButtonWithTooltip as ClearButton };
|
|
52
|
+
export { ClearButton };
|
|
@@ -110,6 +110,9 @@ export function SimpleSingleSelect(_ref2) {
|
|
|
110
110
|
if (selectedOptionIndex !== focussedOptionIndex) {
|
|
111
111
|
setFocussedOptionIndex(selectedOptionIndex);
|
|
112
112
|
}
|
|
113
|
+
if (selectedOptionIndex === -1) {
|
|
114
|
+
setFocussedOptionIndex(0);
|
|
115
|
+
}
|
|
113
116
|
setExpanded(true);
|
|
114
117
|
}, [options, selectedValue, focussedOptionIndex, setFocussedOptionIndex]);
|
|
115
118
|
const toggleMenu = useCallback(() => {
|
|
@@ -34,4 +34,4 @@ export { WithNoMatchText } from './__stories__/WithNoMatchText.js';
|
|
|
34
34
|
export { DefaultPosition } from './__stories__/DefaultPosition.js';
|
|
35
35
|
export { FlippedPosition } from './__stories__/FlippedPosition.js';
|
|
36
36
|
export { ShiftedIntoView } from './__stories__/ShiftedIntoView.js';
|
|
37
|
-
export {
|
|
37
|
+
export { WithMultipleSelectsAndScrollableParent } from './__stories__/WithMultipleSelectsAndScrollableParent.js';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dhis2-ui/select",
|
|
3
|
-
"version": "10.10.0
|
|
3
|
+
"version": "10.10.0",
|
|
4
4
|
"description": "UI Select",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -33,21 +33,21 @@
|
|
|
33
33
|
"styled-jsx": "^4"
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@dhis2-ui/box": "10.10.0
|
|
37
|
-
"@dhis2-ui/button": "10.10.0
|
|
38
|
-
"@dhis2-ui/card": "10.10.0
|
|
39
|
-
"@dhis2-ui/checkbox": "10.10.0
|
|
40
|
-
"@dhis2-ui/chip": "10.10.0
|
|
41
|
-
"@dhis2-ui/field": "10.10.0
|
|
42
|
-
"@dhis2-ui/input": "10.10.0
|
|
43
|
-
"@dhis2-ui/layer": "10.10.0
|
|
44
|
-
"@dhis2-ui/loader": "10.10.0
|
|
45
|
-
"@dhis2-ui/popper": "10.10.0
|
|
46
|
-
"@dhis2-ui/status-icon": "10.10.0
|
|
47
|
-
"@dhis2-ui/tooltip": "10.10.0
|
|
36
|
+
"@dhis2-ui/box": "10.10.0",
|
|
37
|
+
"@dhis2-ui/button": "10.10.0",
|
|
38
|
+
"@dhis2-ui/card": "10.10.0",
|
|
39
|
+
"@dhis2-ui/checkbox": "10.10.0",
|
|
40
|
+
"@dhis2-ui/chip": "10.10.0",
|
|
41
|
+
"@dhis2-ui/field": "10.10.0",
|
|
42
|
+
"@dhis2-ui/input": "10.10.0",
|
|
43
|
+
"@dhis2-ui/layer": "10.10.0",
|
|
44
|
+
"@dhis2-ui/loader": "10.10.0",
|
|
45
|
+
"@dhis2-ui/popper": "10.10.0",
|
|
46
|
+
"@dhis2-ui/status-icon": "10.10.0",
|
|
47
|
+
"@dhis2-ui/tooltip": "10.10.0",
|
|
48
48
|
"@dhis2/prop-types": "^3.1.2",
|
|
49
|
-
"@dhis2/ui-constants": "10.10.0
|
|
50
|
-
"@dhis2/ui-icons": "10.10.0
|
|
49
|
+
"@dhis2/ui-constants": "10.10.0",
|
|
50
|
+
"@dhis2/ui-icons": "10.10.0",
|
|
51
51
|
"classnames": "^2.3.1",
|
|
52
52
|
"prop-types": "^15.7.2"
|
|
53
53
|
},
|