@dhis2-ui/select 10.10.0-alpha.1 → 10.10.0-alpha.3
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/__stories__/WithScrollingParent.js +36 -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 -0
- package/build/cjs/simple-single-select/use-handle-key-press/use-handle-key-press-on-combobox.js +9 -3
- package/build/es/simple-single-select/__stories__/WithMultipleSelectsAndScrollableParent.js +36 -0
- package/build/es/simple-single-select/__stories__/WithScrollingParent.js +27 -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 +2 -1
- package/build/es/simple-single-select/use-handle-key-press/use-handle-key-press-on-combobox.js +9 -3
- package/package.json +15 -15
- package/types/index.d.ts +1 -1
|
@@ -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;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.WithScrollingParent = 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
|
+
const WithScrollingParent = () => {
|
|
13
|
+
const [selected, setSelected] = (0, _react.useState)(null);
|
|
14
|
+
const [selected2, setSelected2] = (0, _react.useState)(null);
|
|
15
|
+
return /*#__PURE__*/_react.default.createElement("div", {
|
|
16
|
+
style: {
|
|
17
|
+
overflow: 'scroll',
|
|
18
|
+
height: '200px'
|
|
19
|
+
}
|
|
20
|
+
}, /*#__PURE__*/_react.default.createElement(_simpleSingleSelect.SimpleSingleSelect, {
|
|
21
|
+
tabIndex: "1",
|
|
22
|
+
inputMaxHeight: "50px",
|
|
23
|
+
name: "simple",
|
|
24
|
+
selected: selected,
|
|
25
|
+
onChange: setSelected,
|
|
26
|
+
options: _options.fiveOptions
|
|
27
|
+
}), /*#__PURE__*/_react.default.createElement(_simpleSingleSelect.SimpleSingleSelect, {
|
|
28
|
+
tabIndex: "2",
|
|
29
|
+
inputMaxHeight: "50px",
|
|
30
|
+
name: "simple2",
|
|
31
|
+
selected: selected2,
|
|
32
|
+
onChange: setSelected2,
|
|
33
|
+
options: _options.fiveOptions
|
|
34
|
+
}), /*#__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), /*#__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"));
|
|
35
|
+
};
|
|
36
|
+
exports.WithScrollingParent = WithScrollingParent;
|
|
@@ -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 () {
|
|
@@ -222,6 +228,7 @@ var _WithNoMatchText = require("./__stories__/WithNoMatchText.js");
|
|
|
222
228
|
var _DefaultPosition = require("./__stories__/DefaultPosition.js");
|
|
223
229
|
var _FlippedPosition = require("./__stories__/FlippedPosition.js");
|
|
224
230
|
var _ShiftedIntoView = require("./__stories__/ShiftedIntoView.js");
|
|
231
|
+
var _WithMultipleSelectsAndScrollableParent = require("./__stories__/WithMultipleSelectsAndScrollableParent.js");
|
|
225
232
|
var _default = exports.default = {
|
|
226
233
|
title: 'Simple Single Select',
|
|
227
234
|
component: _simpleSingleSelect.SimpleSingleSelect
|
package/build/cjs/simple-single-select/use-handle-key-press/use-handle-key-press-on-combobox.js
CHANGED
|
@@ -98,13 +98,13 @@ function useHandleKeyPressOnCombobox(_ref2) {
|
|
|
98
98
|
focussedOptionIndex,
|
|
99
99
|
setFocussedOptionIndex
|
|
100
100
|
});
|
|
101
|
-
const handleKeyPress = (0, _react.useCallback)(
|
|
102
|
-
|
|
101
|
+
const handleKeyPress = (0, _react.useCallback)(event => {
|
|
102
|
+
const {
|
|
103
103
|
key,
|
|
104
104
|
altKey,
|
|
105
105
|
ctrlKey,
|
|
106
106
|
metaKey
|
|
107
|
-
} =
|
|
107
|
+
} = event;
|
|
108
108
|
if (disabled || loading) {
|
|
109
109
|
return;
|
|
110
110
|
}
|
|
@@ -123,6 +123,12 @@ function useHandleKeyPressOnCombobox(_ref2) {
|
|
|
123
123
|
closeMenu();
|
|
124
124
|
return;
|
|
125
125
|
}
|
|
126
|
+
|
|
127
|
+
// ! This is necessary for cases where the parent window is scrollable
|
|
128
|
+
// ! otherwise the ArrowDown/Up would change the combo but also scroll the window
|
|
129
|
+
if (key === 'ArrowDown' || key === 'ArrowUp' || key === ' ') {
|
|
130
|
+
event.preventDefault();
|
|
131
|
+
}
|
|
126
132
|
if (expanded && (key === 'Escape' || key === 'Enter' || key === ' ' && !typing || key === 'ArrowUp' && altKey || key === 'ArrowDown' && altKey)) {
|
|
127
133
|
if (value !== options[focussedOptionIndex].value) {
|
|
128
134
|
selectFocussedOption();
|
|
@@ -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
|
+
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import React, { useState } from 'react';
|
|
2
|
+
import { SimpleSingleSelect } from '../simple-single-select.js';
|
|
3
|
+
import { fiveOptions } from './options.js';
|
|
4
|
+
export const WithScrollingParent = () => {
|
|
5
|
+
const [selected, setSelected] = useState(null);
|
|
6
|
+
const [selected2, setSelected2] = useState(null);
|
|
7
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
8
|
+
style: {
|
|
9
|
+
overflow: 'scroll',
|
|
10
|
+
height: '200px'
|
|
11
|
+
}
|
|
12
|
+
}, /*#__PURE__*/React.createElement(SimpleSingleSelect, {
|
|
13
|
+
tabIndex: "1",
|
|
14
|
+
inputMaxHeight: "50px",
|
|
15
|
+
name: "simple",
|
|
16
|
+
selected: selected,
|
|
17
|
+
onChange: setSelected,
|
|
18
|
+
options: fiveOptions
|
|
19
|
+
}), /*#__PURE__*/React.createElement(SimpleSingleSelect, {
|
|
20
|
+
tabIndex: "2",
|
|
21
|
+
inputMaxHeight: "50px",
|
|
22
|
+
name: "simple2",
|
|
23
|
+
selected: selected2,
|
|
24
|
+
onChange: setSelected2,
|
|
25
|
+
options: fiveOptions
|
|
26
|
+
}), /*#__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), /*#__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"));
|
|
27
|
+
};
|
|
@@ -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(() => {
|
|
@@ -33,4 +33,5 @@ export { WithFilterField } from './__stories__/WithFilterField.js';
|
|
|
33
33
|
export { WithNoMatchText } from './__stories__/WithNoMatchText.js';
|
|
34
34
|
export { DefaultPosition } from './__stories__/DefaultPosition.js';
|
|
35
35
|
export { FlippedPosition } from './__stories__/FlippedPosition.js';
|
|
36
|
-
export { ShiftedIntoView } from './__stories__/ShiftedIntoView.js';
|
|
36
|
+
export { ShiftedIntoView } from './__stories__/ShiftedIntoView.js';
|
|
37
|
+
export { WithMultipleSelectsAndScrollableParent } from './__stories__/WithMultipleSelectsAndScrollableParent.js';
|
package/build/es/simple-single-select/use-handle-key-press/use-handle-key-press-on-combobox.js
CHANGED
|
@@ -92,13 +92,13 @@ export function useHandleKeyPressOnCombobox(_ref2) {
|
|
|
92
92
|
focussedOptionIndex,
|
|
93
93
|
setFocussedOptionIndex
|
|
94
94
|
});
|
|
95
|
-
const handleKeyPress = useCallback(
|
|
96
|
-
|
|
95
|
+
const handleKeyPress = useCallback(event => {
|
|
96
|
+
const {
|
|
97
97
|
key,
|
|
98
98
|
altKey,
|
|
99
99
|
ctrlKey,
|
|
100
100
|
metaKey
|
|
101
|
-
} =
|
|
101
|
+
} = event;
|
|
102
102
|
if (disabled || loading) {
|
|
103
103
|
return;
|
|
104
104
|
}
|
|
@@ -117,6 +117,12 @@ export function useHandleKeyPressOnCombobox(_ref2) {
|
|
|
117
117
|
closeMenu();
|
|
118
118
|
return;
|
|
119
119
|
}
|
|
120
|
+
|
|
121
|
+
// ! This is necessary for cases where the parent window is scrollable
|
|
122
|
+
// ! otherwise the ArrowDown/Up would change the combo but also scroll the window
|
|
123
|
+
if (key === 'ArrowDown' || key === 'ArrowUp' || key === ' ') {
|
|
124
|
+
event.preventDefault();
|
|
125
|
+
}
|
|
120
126
|
if (expanded && (key === 'Escape' || key === 'Enter' || key === ' ' && !typing || key === 'ArrowUp' && altKey || key === 'ArrowDown' && altKey)) {
|
|
121
127
|
if (value !== options[focussedOptionIndex].value) {
|
|
122
128
|
selectFocussedOption();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dhis2-ui/select",
|
|
3
|
-
"version": "10.10.0-alpha.
|
|
3
|
+
"version": "10.10.0-alpha.3",
|
|
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-alpha.
|
|
37
|
-
"@dhis2-ui/button": "10.10.0-alpha.
|
|
38
|
-
"@dhis2-ui/card": "10.10.0-alpha.
|
|
39
|
-
"@dhis2-ui/checkbox": "10.10.0-alpha.
|
|
40
|
-
"@dhis2-ui/chip": "10.10.0-alpha.
|
|
41
|
-
"@dhis2-ui/field": "10.10.0-alpha.
|
|
42
|
-
"@dhis2-ui/input": "10.10.0-alpha.
|
|
43
|
-
"@dhis2-ui/layer": "10.10.0-alpha.
|
|
44
|
-
"@dhis2-ui/loader": "10.10.0-alpha.
|
|
45
|
-
"@dhis2-ui/popper": "10.10.0-alpha.
|
|
46
|
-
"@dhis2-ui/status-icon": "10.10.0-alpha.
|
|
47
|
-
"@dhis2-ui/tooltip": "10.10.0-alpha.
|
|
36
|
+
"@dhis2-ui/box": "10.10.0-alpha.3",
|
|
37
|
+
"@dhis2-ui/button": "10.10.0-alpha.3",
|
|
38
|
+
"@dhis2-ui/card": "10.10.0-alpha.3",
|
|
39
|
+
"@dhis2-ui/checkbox": "10.10.0-alpha.3",
|
|
40
|
+
"@dhis2-ui/chip": "10.10.0-alpha.3",
|
|
41
|
+
"@dhis2-ui/field": "10.10.0-alpha.3",
|
|
42
|
+
"@dhis2-ui/input": "10.10.0-alpha.3",
|
|
43
|
+
"@dhis2-ui/layer": "10.10.0-alpha.3",
|
|
44
|
+
"@dhis2-ui/loader": "10.10.0-alpha.3",
|
|
45
|
+
"@dhis2-ui/popper": "10.10.0-alpha.3",
|
|
46
|
+
"@dhis2-ui/status-icon": "10.10.0-alpha.3",
|
|
47
|
+
"@dhis2-ui/tooltip": "10.10.0-alpha.3",
|
|
48
48
|
"@dhis2/prop-types": "^3.1.2",
|
|
49
|
-
"@dhis2/ui-constants": "10.10.0-alpha.
|
|
50
|
-
"@dhis2/ui-icons": "10.10.0-alpha.
|
|
49
|
+
"@dhis2/ui-constants": "10.10.0-alpha.3",
|
|
50
|
+
"@dhis2/ui-icons": "10.10.0-alpha.3",
|
|
51
51
|
"classnames": "^2.3.1",
|
|
52
52
|
"prop-types": "^15.7.2"
|
|
53
53
|
},
|
package/types/index.d.ts
CHANGED
|
@@ -323,7 +323,7 @@ type SimpleSingleSelectCustomOptionProp = (props: {
|
|
|
323
323
|
|
|
324
324
|
export interface SimpleSingleSelectProps {
|
|
325
325
|
/** necessary for IDs that are required for accessibility **/
|
|
326
|
-
|
|
326
|
+
name: string.isRequired
|
|
327
327
|
|
|
328
328
|
/** An array of options **/
|
|
329
329
|
options: Array<{
|