@dhis2-ui/select 10.16.5 → 10.18.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/multi-select/multi-select.js +8 -0
- package/build/cjs/multi-select/multi-select.prod.stories.js +40 -1
- package/build/cjs/multi-select-field/multi-select-field.js +8 -0
- package/build/cjs/multi-select-field/multi-select-field.prod.stories.js +42 -2
- package/build/cjs/select/menu-wrapper.js +17 -6
- package/build/cjs/select/select.js +18 -12
- package/build/cjs/simple-single-select/__stories__/WithMenuMaxWidth.js +34 -0
- package/build/cjs/simple-single-select/__stories__/WithMenuMinWidth.js +37 -0
- package/build/cjs/simple-single-select/menu/menu.js +17 -8
- package/build/cjs/simple-single-select/simple-single-select.js +19 -9
- package/build/cjs/simple-single-select/simple-single-select.prod.stories.js +14 -0
- package/build/cjs/simple-single-select/simple-single-select.test.js +62 -0
- package/build/cjs/simple-single-select-field/simple-single-select-field.js +4 -0
- package/build/cjs/simple-single-select-field/simple-single-select-field.prod.stories.js +53 -2
- package/build/cjs/simple-single-select-field/simple-single-select-field.test.js +4 -0
- package/build/cjs/single-select/single-select.js +8 -0
- package/build/cjs/single-select/single-select.prod.stories.js +41 -2
- package/build/cjs/single-select-field/single-select-field.js +8 -0
- package/build/cjs/single-select-field/single-select-field.prod.stories.js +42 -2
- package/build/cjs/single-select-option/single-select-option.js +4 -4
- package/build/es/multi-select/multi-select.js +8 -0
- package/build/es/multi-select/multi-select.prod.stories.js +37 -0
- package/build/es/multi-select-field/multi-select-field.js +8 -0
- package/build/es/multi-select-field/multi-select-field.prod.stories.js +41 -1
- package/build/es/select/menu-wrapper.js +17 -6
- package/build/es/select/select.js +18 -12
- package/build/es/simple-single-select/__stories__/WithMenuMaxWidth.js +26 -0
- package/build/es/simple-single-select/__stories__/WithMenuMinWidth.js +29 -0
- package/build/es/simple-single-select/menu/menu.js +17 -8
- package/build/es/simple-single-select/simple-single-select.js +19 -9
- package/build/es/simple-single-select/simple-single-select.prod.stories.js +2 -0
- package/build/es/simple-single-select/simple-single-select.test.js +62 -0
- package/build/es/simple-single-select-field/simple-single-select-field.js +4 -0
- package/build/es/simple-single-select-field/simple-single-select-field.prod.stories.js +49 -0
- package/build/es/simple-single-select-field/simple-single-select-field.test.js +4 -0
- package/build/es/single-select/single-select.js +8 -0
- package/build/es/single-select/single-select.prod.stories.js +38 -1
- package/build/es/single-select-field/single-select-field.js +8 -0
- package/build/es/single-select-field/single-select-field.prod.stories.js +41 -1
- package/build/es/single-select-option/single-select-option.js +4 -4
- package/package.json +15 -15
- package/src/multi-select/multi-select.js +8 -0
- package/src/multi-select/multi-select.prod.stories.js +26 -0
- package/src/multi-select-field/multi-select-field.js +8 -0
- package/src/multi-select-field/multi-select-field.prod.stories.js +31 -0
- package/src/select/menu-wrapper.js +19 -3
- package/src/select/select.js +18 -12
- package/src/simple-single-select/__stories__/WithMenuMaxWidth.js +24 -0
- package/src/simple-single-select/__stories__/WithMenuMinWidth.js +25 -0
- package/src/simple-single-select/menu/menu.js +26 -8
- package/src/simple-single-select/simple-single-select.js +19 -6
- package/src/simple-single-select/simple-single-select.prod.stories.js +2 -0
- package/src/simple-single-select/simple-single-select.test.js +68 -0
- package/src/simple-single-select-field/simple-single-select-field.js +6 -0
- package/src/simple-single-select-field/simple-single-select-field.prod.stories.js +49 -0
- package/src/simple-single-select-field/simple-single-select-field.test.js +4 -0
- package/src/single-select/single-select.js +8 -0
- package/src/single-select/single-select.prod.stories.js +26 -0
- package/src/single-select-field/single-select-field.js +8 -0
- package/src/single-select-field/single-select-field.prod.stories.js +31 -0
- package/src/single-select-option/single-select-option.js +5 -3
- package/types/index.d.ts +45 -1
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.default = exports.WithHelpText = exports.StatusWarning = exports.StatusValid = exports.StatusError = exports.StatusDisabled = exports.Required = exports.InputWidth = exports.Default = void 0;
|
|
6
|
+
exports.default = exports.WithMenuMinWidth = exports.WithMenuMaxWidth = exports.WithHelpText = exports.StatusWarning = exports.StatusValid = exports.StatusError = exports.StatusDisabled = exports.Required = exports.InputWidth = exports.Default = void 0;
|
|
7
7
|
var _react = _interopRequireWildcard(require("react"));
|
|
8
8
|
var _index = require("./index.js");
|
|
9
9
|
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
|
|
@@ -49,6 +49,19 @@ const options = [{
|
|
|
49
49
|
value: '10',
|
|
50
50
|
label: 'ten'
|
|
51
51
|
}];
|
|
52
|
+
const longOptions = [{
|
|
53
|
+
value: '1',
|
|
54
|
+
label: 'option one'
|
|
55
|
+
}, {
|
|
56
|
+
value: '2',
|
|
57
|
+
label: 'option two'
|
|
58
|
+
}, {
|
|
59
|
+
value: '3',
|
|
60
|
+
label: 'option three'
|
|
61
|
+
}, {
|
|
62
|
+
value: '4',
|
|
63
|
+
label: 'A longer option that exceeds the minimum'
|
|
64
|
+
}];
|
|
52
65
|
var _default = exports.default = {
|
|
53
66
|
title: 'SimpleSingleSelectField',
|
|
54
67
|
component: _index.SimpleSingleSelectField,
|
|
@@ -184,4 +197,42 @@ const InputWidth = () => {
|
|
|
184
197
|
options: options
|
|
185
198
|
}));
|
|
186
199
|
};
|
|
187
|
-
exports.InputWidth = InputWidth;
|
|
200
|
+
exports.InputWidth = InputWidth;
|
|
201
|
+
const WithMenuMinWidth = () => {
|
|
202
|
+
var _longOptions$find;
|
|
203
|
+
const [value, setValue] = (0, _react.useState)('');
|
|
204
|
+
const valueLabel = value ? (_longOptions$find = longOptions.find(option => option.value === value)) === null || _longOptions$find === void 0 ? void 0 : _longOptions$find.label : '';
|
|
205
|
+
return /*#__PURE__*/_react.default.createElement("div", {
|
|
206
|
+
style: {
|
|
207
|
+
width: 120
|
|
208
|
+
}
|
|
209
|
+
}, /*#__PURE__*/_react.default.createElement(_index.SimpleSingleSelectField, {
|
|
210
|
+
name: "simple",
|
|
211
|
+
label: "This is the label",
|
|
212
|
+
value: value,
|
|
213
|
+
valueLabel: valueLabel,
|
|
214
|
+
onChange: nextValue => setValue(nextValue),
|
|
215
|
+
options: longOptions,
|
|
216
|
+
menuMinWidth: "240px"
|
|
217
|
+
}));
|
|
218
|
+
};
|
|
219
|
+
exports.WithMenuMinWidth = WithMenuMinWidth;
|
|
220
|
+
const WithMenuMaxWidth = () => {
|
|
221
|
+
var _longOptions$find2;
|
|
222
|
+
const [value, setValue] = (0, _react.useState)('');
|
|
223
|
+
const valueLabel = value ? (_longOptions$find2 = longOptions.find(option => option.value === value)) === null || _longOptions$find2 === void 0 ? void 0 : _longOptions$find2.label : '';
|
|
224
|
+
return /*#__PURE__*/_react.default.createElement("div", {
|
|
225
|
+
style: {
|
|
226
|
+
width: 120
|
|
227
|
+
}
|
|
228
|
+
}, /*#__PURE__*/_react.default.createElement(_index.SimpleSingleSelectField, {
|
|
229
|
+
name: "simple",
|
|
230
|
+
label: "This is the label",
|
|
231
|
+
value: value,
|
|
232
|
+
valueLabel: valueLabel,
|
|
233
|
+
onChange: nextValue => setValue(nextValue),
|
|
234
|
+
options: longOptions,
|
|
235
|
+
menuMaxWidth: "200px"
|
|
236
|
+
}));
|
|
237
|
+
};
|
|
238
|
+
exports.WithMenuMaxWidth = WithMenuMaxWidth;
|
|
@@ -52,6 +52,8 @@ describe('<SimpleSingleSelectField />', () => {
|
|
|
52
52
|
loading: false,
|
|
53
53
|
menuLoadingText: "",
|
|
54
54
|
menuMaxHeight: "",
|
|
55
|
+
menuMaxWidth: "400px",
|
|
56
|
+
menuMinWidth: "240px",
|
|
55
57
|
noMatchText: "",
|
|
56
58
|
optionUpdateStrategy: "off",
|
|
57
59
|
placeholder: "",
|
|
@@ -89,6 +91,8 @@ describe('<SimpleSingleSelectField />', () => {
|
|
|
89
91
|
expect(_simpleSingleSelect.SimpleSingleSelect.mock.calls[0][0].loading).toBe(false);
|
|
90
92
|
expect(_simpleSingleSelect.SimpleSingleSelect.mock.calls[0][0].menuLoadingText).toBe('');
|
|
91
93
|
expect(_simpleSingleSelect.SimpleSingleSelect.mock.calls[0][0].menuMaxHeight).toBe('');
|
|
94
|
+
expect(_simpleSingleSelect.SimpleSingleSelect.mock.calls[0][0].menuMaxWidth).toBe('400px');
|
|
95
|
+
expect(_simpleSingleSelect.SimpleSingleSelect.mock.calls[0][0].menuMinWidth).toBe('240px');
|
|
92
96
|
expect(_simpleSingleSelect.SimpleSingleSelect.mock.calls[0][0].noMatchText).toBe('');
|
|
93
97
|
expect(_simpleSingleSelect.SimpleSingleSelect.mock.calls[0][0].optionUpdateStrategy).toBe('off');
|
|
94
98
|
expect(_simpleSingleSelect.SimpleSingleSelect.mock.calls[0][0].placeholder).toBe('');
|
|
@@ -20,6 +20,8 @@ const SingleSelect = ({
|
|
|
20
20
|
selected = '',
|
|
21
21
|
tabIndex,
|
|
22
22
|
maxHeight,
|
|
23
|
+
menuMinWidth,
|
|
24
|
+
menuMaxWidth,
|
|
23
25
|
inputMaxHeight,
|
|
24
26
|
onChange,
|
|
25
27
|
onFocus,
|
|
@@ -73,6 +75,8 @@ const SingleSelect = ({
|
|
|
73
75
|
menu: menu,
|
|
74
76
|
tabIndex: tabIndex,
|
|
75
77
|
maxHeight: maxHeight,
|
|
78
|
+
menuMinWidth: menuMinWidth,
|
|
79
|
+
menuMaxWidth: menuMaxWidth,
|
|
76
80
|
onChange: onChange,
|
|
77
81
|
onFocus: onFocus,
|
|
78
82
|
onKeyDown: onKeyDown,
|
|
@@ -118,6 +122,10 @@ SingleSelect.propTypes = {
|
|
|
118
122
|
loading: _propTypes2.default.bool,
|
|
119
123
|
loadingText: _propTypes2.default.string,
|
|
120
124
|
maxHeight: _propTypes2.default.string,
|
|
125
|
+
/** See [dropdown menu width](https://developers.dhis2.org/docs/ui/components/select#dropdown-menu-width) */
|
|
126
|
+
menuMaxWidth: _propTypes2.default.string,
|
|
127
|
+
/** See [dropdown menu width](https://developers.dhis2.org/docs/ui/components/select#dropdown-menu-width) */
|
|
128
|
+
menuMinWidth: _propTypes2.default.string,
|
|
121
129
|
/** Text to show when filter returns no results. Required if `filterable` prop is true */
|
|
122
130
|
noMatchText: (0, _propTypes.requiredIf)(props => props.filterable, _propTypes2.default.string),
|
|
123
131
|
placeholder: _propTypes2.default.string,
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.default = exports.WithRTL = exports.WithPrefixAndSelection = exports.WithPrefix = exports.WithPlaceholderAndSelection = exports.WithPlaceholder = exports.WithOptionsLoadingAndLoadingText = exports.WithOptionsAndOnChange = exports.WithOptionsAndLoading = exports.WithOptionsAndDisabled = exports.WithOptionsAndASelection = exports.WithOptionsASelectionAndDisabled = exports.WithOnFocus = exports.WithOnBlur = exports.WithMoreThanThreeOptionsAndA100PxMaxHeight = exports.WithMoreThanTenOptions = exports.WithInvalidOptions = exports.WithInvalidFilterableOptions = exports.WithInitialFocus = exports.WithFilterField = exports.WithDisabledOptionAndOnChange = exports.WithCustomOptionsAndOnChange = exports.WithClearButtonSelectionAndOnChange = exports.ShiftedIntoView = exports.FlippedPosition = exports.EmptyWithEmptyText = exports.EmptyWithEmptyComponent = exports.Empty = exports.Dense = exports.DefaultPosition = void 0;
|
|
6
|
+
exports.default = exports.WithRTL = exports.WithPrefixAndSelection = exports.WithPrefix = exports.WithPlaceholderAndSelection = exports.WithPlaceholder = exports.WithOptionsLoadingAndLoadingText = exports.WithOptionsAndOnChange = exports.WithOptionsAndLoading = exports.WithOptionsAndDisabled = exports.WithOptionsAndASelection = exports.WithOptionsASelectionAndDisabled = exports.WithOnFocus = exports.WithOnBlur = exports.WithMoreThanThreeOptionsAndA100PxMaxHeight = exports.WithMoreThanTenOptions = exports.WithMenuMinWidth = exports.WithMenuMaxWidth = exports.WithInvalidOptions = exports.WithInvalidFilterableOptions = exports.WithInitialFocus = exports.WithFilterField = exports.WithDisabledOptionAndOnChange = exports.WithCustomOptionsAndOnChange = exports.WithClearButtonSelectionAndOnChange = exports.ShiftedIntoView = exports.FlippedPosition = exports.EmptyWithEmptyText = exports.EmptyWithEmptyComponent = exports.Empty = exports.Dense = exports.DefaultPosition = 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"));
|
|
@@ -480,4 +480,43 @@ const ShiftedIntoView = args => /*#__PURE__*/_react.default.createElement(_react
|
|
|
480
480
|
})), /*#__PURE__*/_react.default.createElement(_style.default, {
|
|
481
481
|
id: "1828862170"
|
|
482
482
|
}, ["html,body,#root{position:relative;height:300px !important;max-height:300px;}", "#root{padding-top:130px !important;}"]));
|
|
483
|
-
exports.ShiftedIntoView = ShiftedIntoView;
|
|
483
|
+
exports.ShiftedIntoView = ShiftedIntoView;
|
|
484
|
+
const WithMenuMaxWidth = args => /*#__PURE__*/_react.default.createElement("div", {
|
|
485
|
+
style: {
|
|
486
|
+
width: 120
|
|
487
|
+
}
|
|
488
|
+
}, /*#__PURE__*/_react.default.createElement(_index2.SingleSelect, args, /*#__PURE__*/_react.default.createElement(_index.SingleSelectOption, {
|
|
489
|
+
value: "1",
|
|
490
|
+
label: "option one"
|
|
491
|
+
}), /*#__PURE__*/_react.default.createElement(_index.SingleSelectOption, {
|
|
492
|
+
value: "2",
|
|
493
|
+
label: "option two"
|
|
494
|
+
}), /*#__PURE__*/_react.default.createElement(_index.SingleSelectOption, {
|
|
495
|
+
value: "3",
|
|
496
|
+
label: "A much longer option label"
|
|
497
|
+
})));
|
|
498
|
+
exports.WithMenuMaxWidth = WithMenuMaxWidth;
|
|
499
|
+
WithMenuMaxWidth.args = {
|
|
500
|
+
menuMaxWidth: '200px'
|
|
501
|
+
};
|
|
502
|
+
const WithMenuMinWidth = args => /*#__PURE__*/_react.default.createElement("div", {
|
|
503
|
+
style: {
|
|
504
|
+
width: 120
|
|
505
|
+
}
|
|
506
|
+
}, /*#__PURE__*/_react.default.createElement(_index2.SingleSelect, args, /*#__PURE__*/_react.default.createElement(_index.SingleSelectOption, {
|
|
507
|
+
value: "1",
|
|
508
|
+
label: "option one"
|
|
509
|
+
}), /*#__PURE__*/_react.default.createElement(_index.SingleSelectOption, {
|
|
510
|
+
value: "2",
|
|
511
|
+
label: "option two"
|
|
512
|
+
}), /*#__PURE__*/_react.default.createElement(_index.SingleSelectOption, {
|
|
513
|
+
value: "3",
|
|
514
|
+
label: "option three"
|
|
515
|
+
}), /*#__PURE__*/_react.default.createElement(_index.SingleSelectOption, {
|
|
516
|
+
value: "4",
|
|
517
|
+
label: "A longer option that exceeds the minimum"
|
|
518
|
+
})));
|
|
519
|
+
exports.WithMenuMinWidth = WithMenuMinWidth;
|
|
520
|
+
WithMenuMinWidth.args = {
|
|
521
|
+
menuMinWidth: '240px'
|
|
522
|
+
};
|
|
@@ -42,6 +42,8 @@ class SingleSelectField extends _react.default.Component {
|
|
|
42
42
|
helpText,
|
|
43
43
|
validationText,
|
|
44
44
|
maxHeight,
|
|
45
|
+
menuMinWidth,
|
|
46
|
+
menuMaxWidth,
|
|
45
47
|
inputMaxHeight,
|
|
46
48
|
inputWidth,
|
|
47
49
|
children,
|
|
@@ -76,6 +78,8 @@ class SingleSelectField extends _react.default.Component {
|
|
|
76
78
|
selected: selected,
|
|
77
79
|
tabIndex: tabIndex,
|
|
78
80
|
maxHeight: maxHeight,
|
|
81
|
+
menuMinWidth: menuMinWidth,
|
|
82
|
+
menuMaxWidth: menuMaxWidth,
|
|
79
83
|
inputMaxHeight: inputMaxHeight,
|
|
80
84
|
onChange: onChange,
|
|
81
85
|
onFocus: onFocus,
|
|
@@ -147,6 +151,10 @@ SingleSelectField.propTypes = {
|
|
|
147
151
|
loadingText: _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.func]),
|
|
148
152
|
/** Constrains height of the SingleSelect */
|
|
149
153
|
maxHeight: _propTypes.default.string,
|
|
154
|
+
/** See [dropdown menu width](https://developers.dhis2.org/docs/ui/components/select#dropdown-menu-width) */
|
|
155
|
+
menuMaxWidth: _propTypes.default.string,
|
|
156
|
+
/** See [dropdown menu width](https://developers.dhis2.org/docs/ui/components/select#dropdown-menu-width) */
|
|
157
|
+
menuMinWidth: _propTypes.default.string,
|
|
150
158
|
/** Text to display when there are no filter results */
|
|
151
159
|
noMatchText: _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.func]),
|
|
152
160
|
/** Placeholder text when the SingleSelect is empty */
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.default = exports.WithHelpText = exports.StatusWarning = exports.StatusValid = exports.StatusError = exports.StatusDisabled = exports.Required = exports.InputWidth = exports.DefaultLoadingText = exports.DefaultFilterPlaceholderAndNoMatchText = exports.DefaultEmpty = exports.DefaultClearText = exports.Default = void 0;
|
|
6
|
+
exports.default = exports.WithMenuMinWidth = exports.WithMenuMaxWidth = exports.WithHelpText = exports.StatusWarning = exports.StatusValid = exports.StatusError = exports.StatusDisabled = exports.Required = exports.InputWidth = exports.DefaultLoadingText = exports.DefaultFilterPlaceholderAndNoMatchText = exports.DefaultEmpty = exports.DefaultClearText = exports.Default = void 0;
|
|
7
7
|
var _uiConstants = require("@dhis2/ui-constants");
|
|
8
8
|
var _react = _interopRequireDefault(require("react"));
|
|
9
9
|
var _index = require("../index.js");
|
|
@@ -180,4 +180,44 @@ DefaultLoadingText.args = {
|
|
|
180
180
|
loading: true,
|
|
181
181
|
...DefaultEmpty.args
|
|
182
182
|
};
|
|
183
|
-
DefaultLoadingText.storyName = 'Default: loadingText';
|
|
183
|
+
DefaultLoadingText.storyName = 'Default: loadingText';
|
|
184
|
+
const WithMenuMaxWidth = exports.WithMenuMaxWidth = Template.bind({});
|
|
185
|
+
WithMenuMaxWidth.args = {
|
|
186
|
+
inputWidth: '120px',
|
|
187
|
+
menuMaxWidth: '200px',
|
|
188
|
+
children: [/*#__PURE__*/_react.default.createElement(_index.SingleSelectOption, {
|
|
189
|
+
key: "1",
|
|
190
|
+
value: "1",
|
|
191
|
+
label: "option one"
|
|
192
|
+
}), /*#__PURE__*/_react.default.createElement(_index.SingleSelectOption, {
|
|
193
|
+
key: "2",
|
|
194
|
+
value: "2",
|
|
195
|
+
label: "option two"
|
|
196
|
+
}), /*#__PURE__*/_react.default.createElement(_index.SingleSelectOption, {
|
|
197
|
+
key: "3",
|
|
198
|
+
value: "3",
|
|
199
|
+
label: "A much longer option label"
|
|
200
|
+
})]
|
|
201
|
+
};
|
|
202
|
+
const WithMenuMinWidth = exports.WithMenuMinWidth = Template.bind({});
|
|
203
|
+
WithMenuMinWidth.args = {
|
|
204
|
+
inputWidth: '120px',
|
|
205
|
+
menuMinWidth: '240px',
|
|
206
|
+
children: [/*#__PURE__*/_react.default.createElement(_index.SingleSelectOption, {
|
|
207
|
+
key: "1",
|
|
208
|
+
value: "1",
|
|
209
|
+
label: "option one"
|
|
210
|
+
}), /*#__PURE__*/_react.default.createElement(_index.SingleSelectOption, {
|
|
211
|
+
key: "2",
|
|
212
|
+
value: "2",
|
|
213
|
+
label: "option two"
|
|
214
|
+
}), /*#__PURE__*/_react.default.createElement(_index.SingleSelectOption, {
|
|
215
|
+
key: "3",
|
|
216
|
+
value: "3",
|
|
217
|
+
label: "option three"
|
|
218
|
+
}), /*#__PURE__*/_react.default.createElement(_index.SingleSelectOption, {
|
|
219
|
+
key: "4",
|
|
220
|
+
value: "4",
|
|
221
|
+
label: "A longer option that exceeds the minimum"
|
|
222
|
+
})]
|
|
223
|
+
};
|
|
@@ -23,17 +23,17 @@ const SingleSelectOption = ({
|
|
|
23
23
|
"data-test": dataTest,
|
|
24
24
|
"data-value": value,
|
|
25
25
|
"data-label": label,
|
|
26
|
-
className: _style.default.dynamic([["
|
|
26
|
+
className: _style.default.dynamic([["556453451", [_uiConstants.colors.grey900, _uiConstants.spacers.dp8, _uiConstants.spacers.dp12, _uiConstants.colors.grey200, _uiConstants.colors.teal050, _uiConstants.colors.grey500, active ? `url('data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMTYiIGhlaWdodD0iMTYiIHZpZXdCb3g9IjAgMCAxNiAxNiIgZmlsbD0ibm9uZSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj4KPHBhdGggZD0iTTMuNjMyMDkgNy44MzIxNEMzLjI3MjA5IDcuNDcyMTQgMi43MjAwOSA3LjQ3MjE0IDIuMzYwMDkgNy44MzIxNEMyLjAwMDA5IDguMTkyMTQgMi4wMDAwOSA4Ljc0NDE0IDIuMzYwMDkgOS4xMDQxNEw1LjYyNDA5IDEyLjM2ODFDNS45ODQwOSAxMi43MjgxIDYuNTM2MDkgMTIuNzI4MSA2Ljg5NjA5IDEyLjM2ODFMMTQuNjQ4MSA0LjY0MDE0QzE1LjAwODEgNC4yODAxNCAxNS4wMDgxIDMuNzI4MTQgMTQuNjQ4MSAzLjM2ODE0QzE0LjI4ODEgMy4wMDgxNCAxMy43MzYxIDMuMDA4MTQgMTMuMzUyMSAzLjM2ODE0TDYuMjcyMDkgMTAuNDcyMUwzLjYzMjA5IDcuODMyMTRaIiBmaWxsPSIjMDA2OTVDIi8+Cjwvc3ZnPgo=')` : 'none']]]) + " " + ((0, _classnames.default)(className, {
|
|
27
27
|
disabled,
|
|
28
28
|
active
|
|
29
29
|
}) || "")
|
|
30
30
|
}, /*#__PURE__*/_react.default.createElement("span", {
|
|
31
31
|
"aria-hidden": "true",
|
|
32
|
-
className: _style.default.dynamic([["
|
|
32
|
+
className: _style.default.dynamic([["556453451", [_uiConstants.colors.grey900, _uiConstants.spacers.dp8, _uiConstants.spacers.dp12, _uiConstants.colors.grey200, _uiConstants.colors.teal050, _uiConstants.colors.grey500, active ? `url('data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMTYiIGhlaWdodD0iMTYiIHZpZXdCb3g9IjAgMCAxNiAxNiIgZmlsbD0ibm9uZSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj4KPHBhdGggZD0iTTMuNjMyMDkgNy44MzIxNEMzLjI3MjA5IDcuNDcyMTQgMi43MjAwOSA3LjQ3MjE0IDIuMzYwMDkgNy44MzIxNEMyLjAwMDA5IDguMTkyMTQgMi4wMDAwOSA4Ljc0NDE0IDIuMzYwMDkgOS4xMDQxNEw1LjYyNDA5IDEyLjM2ODFDNS45ODQwOSAxMi43MjgxIDYuNTM2MDkgMTIuNzI4MSA2Ljg5NjA5IDEyLjM2ODFMMTQuNjQ4MSA0LjY0MDE0QzE1LjAwODEgNC4yODAxNCAxNS4wMDgxIDMuNzI4MTQgMTQuNjQ4MSAzLjM2ODE0QzE0LjI4ODEgMy4wMDgxNCAxMy43MzYxIDMuMDA4MTQgMTMuMzUyMSAzLjM2ODE0TDYuMjcyMDkgMTAuNDcyMUwzLjYzMjA5IDcuODMyMTRaIiBmaWxsPSIjMDA2OTVDIi8+Cjwvc3ZnPgo=')` : 'none']]]) + " " + "checkmark"
|
|
33
33
|
}), /*#__PURE__*/_react.default.createElement("span", {
|
|
34
|
-
className: _style.default.dynamic([["
|
|
34
|
+
className: _style.default.dynamic([["556453451", [_uiConstants.colors.grey900, _uiConstants.spacers.dp8, _uiConstants.spacers.dp12, _uiConstants.colors.grey200, _uiConstants.colors.teal050, _uiConstants.colors.grey500, active ? `url('data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMTYiIGhlaWdodD0iMTYiIHZpZXdCb3g9IjAgMCAxNiAxNiIgZmlsbD0ibm9uZSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj4KPHBhdGggZD0iTTMuNjMyMDkgNy44MzIxNEMzLjI3MjA5IDcuNDcyMTQgMi43MjAwOSA3LjQ3MjE0IDIuMzYwMDkgNy44MzIxNEMyLjAwMDA5IDguMTkyMTQgMi4wMDAwOSA4Ljc0NDE0IDIuMzYwMDkgOS4xMDQxNEw1LjYyNDA5IDEyLjM2ODFDNS45ODQwOSAxMi43MjgxIDYuNTM2MDkgMTIuNzI4MSA2Ljg5NjA5IDEyLjM2ODFMMTQuNjQ4MSA0LjY0MDE0QzE1LjAwODEgNC4yODAxNCAxNS4wMDgxIDMuNzI4MTQgMTQuNjQ4MSAzLjM2ODE0QzE0LjI4ODEgMy4wMDgxNCAxMy43MzYxIDMuMDA4MTQgMTMuMzUyMSAzLjM2ODE0TDYuMjcyMDkgMTAuNDcyMUwzLjYzMjA5IDcuODMyMTRaIiBmaWxsPSIjMDA2OTVDIi8+Cjwvc3ZnPgo=')` : 'none']]]) + " " + "content"
|
|
35
35
|
}, label), /*#__PURE__*/_react.default.createElement(_style.default, {
|
|
36
|
-
id: "
|
|
36
|
+
id: "556453451",
|
|
37
37
|
dynamic: [_uiConstants.colors.grey900, _uiConstants.spacers.dp8, _uiConstants.spacers.dp12, _uiConstants.colors.grey200, _uiConstants.colors.teal050, _uiConstants.colors.grey500, active ? `url('data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMTYiIGhlaWdodD0iMTYiIHZpZXdCb3g9IjAgMCAxNiAxNiIgZmlsbD0ibm9uZSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj4KPHBhdGggZD0iTTMuNjMyMDkgNy44MzIxNEMzLjI3MjA5IDcuNDcyMTQgMi43MjAwOSA3LjQ3MjE0IDIuMzYwMDkgNy44MzIxNEMyLjAwMDA5IDguMTkyMTQgMi4wMDAwOSA4Ljc0NDE0IDIuMzYwMDkgOS4xMDQxNEw1LjYyNDA5IDEyLjM2ODFDNS45ODQwOSAxMi43MjgxIDYuNTM2MDkgMTIuNzI4MSA2Ljg5NjA5IDEyLjM2ODFMMTQuNjQ4MSA0LjY0MDE0QzE1LjAwODEgNC4yODAxNCAxNS4wMDgxIDMuNzI4MTQgMTQuNjQ4MSAzLjM2ODE0QzE0LjI4ODEgMy4wMDgxNCAxMy43MzYxIDMuMDA4MTQgMTMuMzUyMSAzLjM2ODE0TDYuMjcyMDkgMTAuNDcyMUwzLjYzMjA5IDcuODMyMTRaIiBmaWxsPSIjMDA2OTVDIi8+Cjwvc3ZnPgo=')` : 'none']
|
|
38
38
|
}, [`div.__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;cursor:pointer;font-size:14px;-webkit-text-decoration:none;text-decoration:none;color:${_uiConstants.colors.grey900};padding-block:${_uiConstants.spacers.dp8};padding-inline:6px ${_uiConstants.spacers.dp12};}`, `div.__jsx-style-dynamic-selector:hover{background-color:${_uiConstants.colors.grey200};}`, `div.__jsx-style-dynamic-selector:active,div.active.__jsx-style-dynamic-selector{background-color:${_uiConstants.colors.teal050};cursor:auto;}`, `div.disabled.__jsx-style-dynamic-selector{color:${_uiConstants.colors.grey500};cursor:not-allowed;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;}`, "div.disabled.__jsx-style-dynamic-selector:hover{background-color:initial;}", `div.__jsx-style-dynamic-selector .checkmark.__jsx-style-dynamic-selector{width:16px;height:16px;margin-inline-end:6px;-webkit-flex-shrink:0;-ms-flex-negative:0;flex-shrink:0;background-size:contain;background-repeat:no-repeat;background-image:${active ? `url('data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMTYiIGhlaWdodD0iMTYiIHZpZXdCb3g9IjAgMCAxNiAxNiIgZmlsbD0ibm9uZSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj4KPHBhdGggZD0iTTMuNjMyMDkgNy44MzIxNEMzLjI3MjA5IDcuNDcyMTQgMi43MjAwOSA3LjQ3MjE0IDIuMzYwMDkgNy44MzIxNEMyLjAwMDA5IDguMTkyMTQgMi4wMDAwOSA4Ljc0NDE0IDIuMzYwMDkgOS4xMDQxNEw1LjYyNDA5IDEyLjM2ODFDNS45ODQwOSAxMi43MjgxIDYuNTM2MDkgMTIuNzI4MSA2Ljg5NjA5IDEyLjM2ODFMMTQuNjQ4MSA0LjY0MDE0QzE1LjAwODEgNC4yODAxNCAxNS4wMDgxIDMuNzI4MTQgMTQuNjQ4MSAzLjM2ODE0QzE0LjI4ODEgMy4wMDgxNCAxMy43MzYxIDMuMDA4MTQgMTMuMzUyMSAzLjM2ODE0TDYuMjcyMDkgMTAuNDcyMUwzLjYzMjA5IDcuODMyMTRaIiBmaWxsPSIjMDA2OTVDIi8+Cjwvc3ZnPgo=')` : 'none'};}`]));
|
|
39
39
|
exports.SingleSelectOption = SingleSelectOption;
|
|
@@ -16,6 +16,8 @@ const MultiSelect = ({
|
|
|
16
16
|
selected = staticArr,
|
|
17
17
|
tabIndex,
|
|
18
18
|
maxHeight,
|
|
19
|
+
menuMinWidth,
|
|
20
|
+
menuMaxWidth,
|
|
19
21
|
inputMaxHeight,
|
|
20
22
|
onChange,
|
|
21
23
|
onFocus,
|
|
@@ -71,6 +73,8 @@ const MultiSelect = ({
|
|
|
71
73
|
menu: menu,
|
|
72
74
|
tabIndex: tabIndex,
|
|
73
75
|
maxHeight: maxHeight,
|
|
76
|
+
menuMinWidth: menuMinWidth,
|
|
77
|
+
menuMaxWidth: menuMaxWidth,
|
|
74
78
|
onChange: onChange,
|
|
75
79
|
onFocus: onFocus,
|
|
76
80
|
onKeyDown: onKeyDown,
|
|
@@ -115,6 +119,10 @@ MultiSelect.propTypes = {
|
|
|
115
119
|
loading: PropTypes.bool,
|
|
116
120
|
loadingText: PropTypes.string,
|
|
117
121
|
maxHeight: PropTypes.string,
|
|
122
|
+
/** See [dropdown menu width](https://developers.dhis2.org/docs/ui/components/select#dropdown-menu-width) */
|
|
123
|
+
menuMaxWidth: PropTypes.string,
|
|
124
|
+
/** See [dropdown menu width](https://developers.dhis2.org/docs/ui/components/select#dropdown-menu-width) */
|
|
125
|
+
menuMinWidth: PropTypes.string,
|
|
118
126
|
/** Required if `filterable` prop is `true` */
|
|
119
127
|
noMatchText: requiredIf(props => props.filterable, PropTypes.string),
|
|
120
128
|
placeholder: PropTypes.string,
|
|
@@ -541,4 +541,41 @@ export const RTL = args => {
|
|
|
541
541
|
RTL.args = {
|
|
542
542
|
selected: ['1', '2'],
|
|
543
543
|
prefix: 'RTL text'
|
|
544
|
+
};
|
|
545
|
+
export const WithMenuMaxWidth = args => /*#__PURE__*/React.createElement("div", {
|
|
546
|
+
style: {
|
|
547
|
+
width: 120
|
|
548
|
+
}
|
|
549
|
+
}, /*#__PURE__*/React.createElement(MultiSelect, args, /*#__PURE__*/React.createElement(MultiSelectOption, {
|
|
550
|
+
value: "1",
|
|
551
|
+
label: "option one"
|
|
552
|
+
}), /*#__PURE__*/React.createElement(MultiSelectOption, {
|
|
553
|
+
value: "2",
|
|
554
|
+
label: "option two"
|
|
555
|
+
}), /*#__PURE__*/React.createElement(MultiSelectOption, {
|
|
556
|
+
value: "3",
|
|
557
|
+
label: "A much longer option label"
|
|
558
|
+
})));
|
|
559
|
+
WithMenuMaxWidth.args = {
|
|
560
|
+
menuMaxWidth: '200px'
|
|
561
|
+
};
|
|
562
|
+
export const WithMenuMinWidth = args => /*#__PURE__*/React.createElement("div", {
|
|
563
|
+
style: {
|
|
564
|
+
width: 120
|
|
565
|
+
}
|
|
566
|
+
}, /*#__PURE__*/React.createElement(MultiSelect, args, /*#__PURE__*/React.createElement(MultiSelectOption, {
|
|
567
|
+
value: "1",
|
|
568
|
+
label: "option one"
|
|
569
|
+
}), /*#__PURE__*/React.createElement(MultiSelectOption, {
|
|
570
|
+
value: "2",
|
|
571
|
+
label: "option two"
|
|
572
|
+
}), /*#__PURE__*/React.createElement(MultiSelectOption, {
|
|
573
|
+
value: "3",
|
|
574
|
+
label: "option three"
|
|
575
|
+
}), /*#__PURE__*/React.createElement(MultiSelectOption, {
|
|
576
|
+
value: "4",
|
|
577
|
+
label: "A longer option that exceeds the minimum"
|
|
578
|
+
})));
|
|
579
|
+
WithMenuMinWidth.args = {
|
|
580
|
+
menuMinWidth: '240px'
|
|
544
581
|
};
|
|
@@ -36,6 +36,8 @@ class MultiSelectField extends React.Component {
|
|
|
36
36
|
helpText,
|
|
37
37
|
validationText,
|
|
38
38
|
maxHeight,
|
|
39
|
+
menuMinWidth,
|
|
40
|
+
menuMaxWidth,
|
|
39
41
|
inputMaxHeight,
|
|
40
42
|
inputWidth,
|
|
41
43
|
children,
|
|
@@ -70,6 +72,8 @@ class MultiSelectField extends React.Component {
|
|
|
70
72
|
selected: selected,
|
|
71
73
|
tabIndex: tabIndex,
|
|
72
74
|
maxHeight: maxHeight,
|
|
75
|
+
menuMinWidth: menuMinWidth,
|
|
76
|
+
menuMaxWidth: menuMaxWidth,
|
|
73
77
|
inputMaxHeight: inputMaxHeight,
|
|
74
78
|
onChange: onChange,
|
|
75
79
|
onFocus: onFocus,
|
|
@@ -140,6 +144,10 @@ MultiSelectField.propTypes = {
|
|
|
140
144
|
loadingText: PropTypes.oneOfType([PropTypes.string, PropTypes.func]),
|
|
141
145
|
/** Constrains height of the MultiSelect */
|
|
142
146
|
maxHeight: PropTypes.string,
|
|
147
|
+
/** See [dropdown menu width](https://developers.dhis2.org/docs/ui/components/select#dropdown-menu-width) */
|
|
148
|
+
menuMaxWidth: PropTypes.string,
|
|
149
|
+
/** See [dropdown menu width](https://developers.dhis2.org/docs/ui/components/select#dropdown-menu-width) */
|
|
150
|
+
menuMinWidth: PropTypes.string,
|
|
143
151
|
/** Text to display when there are no filter results */
|
|
144
152
|
noMatchText: PropTypes.oneOfType([PropTypes.string, PropTypes.func]),
|
|
145
153
|
/** Placeholder text when the MultiSelect is empty */
|
|
@@ -167,4 +167,44 @@ DefaultLoadingText.args = {
|
|
|
167
167
|
loading: true,
|
|
168
168
|
...DefaultEmpty.args
|
|
169
169
|
};
|
|
170
|
-
DefaultLoadingText.storyName = 'Default: loadingText';
|
|
170
|
+
DefaultLoadingText.storyName = 'Default: loadingText';
|
|
171
|
+
export const WithMenuMaxWidth = Template.bind({});
|
|
172
|
+
WithMenuMaxWidth.args = {
|
|
173
|
+
inputWidth: '120px',
|
|
174
|
+
menuMaxWidth: '200px',
|
|
175
|
+
children: [/*#__PURE__*/React.createElement(MultiSelectOption, {
|
|
176
|
+
key: "1",
|
|
177
|
+
value: "1",
|
|
178
|
+
label: "option one"
|
|
179
|
+
}), /*#__PURE__*/React.createElement(MultiSelectOption, {
|
|
180
|
+
key: "2",
|
|
181
|
+
value: "2",
|
|
182
|
+
label: "option two"
|
|
183
|
+
}), /*#__PURE__*/React.createElement(MultiSelectOption, {
|
|
184
|
+
key: "3",
|
|
185
|
+
value: "3",
|
|
186
|
+
label: "A much longer option label"
|
|
187
|
+
})]
|
|
188
|
+
};
|
|
189
|
+
export const WithMenuMinWidth = Template.bind({});
|
|
190
|
+
WithMenuMinWidth.args = {
|
|
191
|
+
inputWidth: '120px',
|
|
192
|
+
menuMinWidth: '240px',
|
|
193
|
+
children: [/*#__PURE__*/React.createElement(MultiSelectOption, {
|
|
194
|
+
key: "1",
|
|
195
|
+
value: "1",
|
|
196
|
+
label: "option one"
|
|
197
|
+
}), /*#__PURE__*/React.createElement(MultiSelectOption, {
|
|
198
|
+
key: "2",
|
|
199
|
+
value: "2",
|
|
200
|
+
label: "option two"
|
|
201
|
+
}), /*#__PURE__*/React.createElement(MultiSelectOption, {
|
|
202
|
+
key: "3",
|
|
203
|
+
value: "3",
|
|
204
|
+
label: "option three"
|
|
205
|
+
}), /*#__PURE__*/React.createElement(MultiSelectOption, {
|
|
206
|
+
key: "4",
|
|
207
|
+
value: "4",
|
|
208
|
+
label: "A longer option that exceeds the minimum"
|
|
209
|
+
})]
|
|
210
|
+
};
|
|
@@ -7,11 +7,20 @@ import React from 'react';
|
|
|
7
7
|
const MenuWrapper = ({
|
|
8
8
|
children,
|
|
9
9
|
dataTest,
|
|
10
|
+
inputWidth,
|
|
10
11
|
maxHeight = '280px',
|
|
11
|
-
|
|
12
|
+
menuMaxWidth,
|
|
13
|
+
menuMinWidth,
|
|
12
14
|
onClick,
|
|
13
15
|
selectRef
|
|
14
16
|
}) => {
|
|
17
|
+
// menuMinWidth or menuMaxWidth enables flexible sizing (fit-content), with
|
|
18
|
+
// min-width = max(input, menuMinWidth). Without them, width matches the input.
|
|
19
|
+
const flexible = menuMinWidth || menuMaxWidth;
|
|
20
|
+
const width = flexible ? 'fit-content' : inputWidth;
|
|
21
|
+
const flexibleMinWidth = menuMinWidth ? `max(${inputWidth}, ${menuMinWidth})` : inputWidth;
|
|
22
|
+
const minWidth = flexible ? flexibleMinWidth : 'auto';
|
|
23
|
+
const maxWidth = menuMaxWidth || 'none';
|
|
15
24
|
return /*#__PURE__*/React.createElement(Layer, {
|
|
16
25
|
onBackdropClick: onClick,
|
|
17
26
|
transparent: true
|
|
@@ -21,18 +30,20 @@ const MenuWrapper = ({
|
|
|
21
30
|
observeReferenceResize: true
|
|
22
31
|
}, /*#__PURE__*/React.createElement("div", {
|
|
23
32
|
"data-test": `${dataTest}-menuwrapper`,
|
|
24
|
-
className: _JSXStyle.dynamic([["
|
|
33
|
+
className: _JSXStyle.dynamic([["3752211706", [width, minWidth, maxWidth, maxHeight, colors.white, colors.grey200, elevations.popover]]])
|
|
25
34
|
}, children, /*#__PURE__*/React.createElement(_JSXStyle, {
|
|
26
|
-
id: "
|
|
27
|
-
dynamic: [
|
|
28
|
-
}, [`div.__jsx-style-dynamic-selector{width:${
|
|
35
|
+
id: "3752211706",
|
|
36
|
+
dynamic: [width, minWidth, maxWidth, maxHeight, colors.white, colors.grey200, elevations.popover]
|
|
37
|
+
}, [`div.__jsx-style-dynamic-selector{width:${width};min-width:${minWidth};max-width:${maxWidth};height:auto;max-height:${maxHeight};overflow:auto;background:${colors.white};border:1px solid ${colors.grey200};border-radius:3px;box-shadow:${elevations.popover};}`]))));
|
|
29
38
|
};
|
|
30
39
|
MenuWrapper.propTypes = {
|
|
31
40
|
dataTest: PropTypes.string.isRequired,
|
|
32
|
-
|
|
41
|
+
inputWidth: PropTypes.string.isRequired,
|
|
33
42
|
selectRef: PropTypes.object.isRequired,
|
|
34
43
|
children: PropTypes.node,
|
|
35
44
|
maxHeight: PropTypes.string,
|
|
45
|
+
menuMaxWidth: PropTypes.string,
|
|
46
|
+
menuMinWidth: PropTypes.string,
|
|
36
47
|
onClick: PropTypes.func
|
|
37
48
|
};
|
|
38
49
|
export { MenuWrapper };
|
|
@@ -19,7 +19,7 @@ export class Select extends Component {
|
|
|
19
19
|
super(...args);
|
|
20
20
|
_defineProperty(this, "state", {
|
|
21
21
|
open: false,
|
|
22
|
-
|
|
22
|
+
inputWidth: 'auto'
|
|
23
23
|
});
|
|
24
24
|
_defineProperty(this, "selectRef", /*#__PURE__*/React.createRef());
|
|
25
25
|
_defineProperty(this, "inputRef", /*#__PURE__*/React.createRef());
|
|
@@ -33,10 +33,10 @@ export class Select extends Component {
|
|
|
33
33
|
* See: https://nolanlawson.com/2018/09/25/accurately-measuring-layout-on-the-web
|
|
34
34
|
*/
|
|
35
35
|
_defineProperty(this, "onResize", debounce(() => {
|
|
36
|
-
const
|
|
37
|
-
if (this.state.
|
|
36
|
+
const inputWidth = this.getInputWidth();
|
|
37
|
+
if (this.state.inputWidth !== inputWidth) {
|
|
38
38
|
this.setState({
|
|
39
|
-
|
|
39
|
+
inputWidth
|
|
40
40
|
});
|
|
41
41
|
}
|
|
42
42
|
}, 50));
|
|
@@ -59,7 +59,7 @@ export class Select extends Component {
|
|
|
59
59
|
_defineProperty(this, "handleOpen", () => {
|
|
60
60
|
this.setState({
|
|
61
61
|
open: true,
|
|
62
|
-
|
|
62
|
+
inputWidth: this.getInputWidth()
|
|
63
63
|
});
|
|
64
64
|
});
|
|
65
65
|
_defineProperty(this, "handleClose", () => {
|
|
@@ -138,29 +138,29 @@ export class Select extends Component {
|
|
|
138
138
|
this.inputRef.current.focus();
|
|
139
139
|
}
|
|
140
140
|
this.setState({
|
|
141
|
-
|
|
141
|
+
inputWidth: this.getInputWidth()
|
|
142
142
|
});
|
|
143
143
|
window.addEventListener('resize', this.onResize);
|
|
144
144
|
}
|
|
145
145
|
componentWillUnmount() {
|
|
146
146
|
window.removeEventListener('resize', this.onResize);
|
|
147
147
|
}
|
|
148
|
-
|
|
148
|
+
getInputWidth() {
|
|
149
149
|
const {
|
|
150
150
|
offsetWidth
|
|
151
151
|
} = this.inputRef.current;
|
|
152
152
|
const {
|
|
153
|
-
|
|
153
|
+
inputWidth
|
|
154
154
|
} = this.state;
|
|
155
|
-
if (offsetWidth && `${offsetWidth}px` !==
|
|
155
|
+
if (offsetWidth && `${offsetWidth}px` !== inputWidth) {
|
|
156
156
|
return `${offsetWidth}px`;
|
|
157
157
|
}
|
|
158
|
-
return
|
|
158
|
+
return inputWidth;
|
|
159
159
|
}
|
|
160
160
|
render() {
|
|
161
161
|
const {
|
|
162
162
|
open,
|
|
163
|
-
|
|
163
|
+
inputWidth
|
|
164
164
|
} = this.state;
|
|
165
165
|
const {
|
|
166
166
|
children,
|
|
@@ -169,6 +169,8 @@ export class Select extends Component {
|
|
|
169
169
|
onChange,
|
|
170
170
|
tabIndex,
|
|
171
171
|
maxHeight,
|
|
172
|
+
menuMinWidth,
|
|
173
|
+
menuMaxWidth,
|
|
172
174
|
error,
|
|
173
175
|
warning,
|
|
174
176
|
valid,
|
|
@@ -215,7 +217,9 @@ export class Select extends Component {
|
|
|
215
217
|
onClick: this.onOutsideClick,
|
|
216
218
|
maxHeight: maxHeight,
|
|
217
219
|
selectRef: this.selectRef,
|
|
218
|
-
|
|
220
|
+
inputWidth: inputWidth,
|
|
221
|
+
menuMinWidth: menuMinWidth,
|
|
222
|
+
menuMaxWidth: menuMaxWidth,
|
|
219
223
|
dataTest: `${dataTest}-menu`
|
|
220
224
|
}, menu));
|
|
221
225
|
}
|
|
@@ -235,6 +239,8 @@ Select.propTypes = {
|
|
|
235
239
|
error: sharedPropTypes.statusPropType,
|
|
236
240
|
initialFocus: PropTypes.bool,
|
|
237
241
|
maxHeight: PropTypes.string,
|
|
242
|
+
menuMaxWidth: PropTypes.string,
|
|
243
|
+
menuMinWidth: PropTypes.string,
|
|
238
244
|
tabIndex: PropTypes.string,
|
|
239
245
|
valid: sharedPropTypes.statusPropType,
|
|
240
246
|
warning: sharedPropTypes.statusPropType,
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import React, { useState } from 'react';
|
|
2
|
+
import { SimpleSingleSelect } from '../simple-single-select.js';
|
|
3
|
+
const options = [{
|
|
4
|
+
value: '1',
|
|
5
|
+
label: 'option one'
|
|
6
|
+
}, {
|
|
7
|
+
value: '2',
|
|
8
|
+
label: 'option two'
|
|
9
|
+
}, {
|
|
10
|
+
value: '3',
|
|
11
|
+
label: 'A much longer option label that gets clamped'
|
|
12
|
+
}];
|
|
13
|
+
export const WithMenuMaxWidth = () => {
|
|
14
|
+
const [selected, setSelected] = useState(null);
|
|
15
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
16
|
+
style: {
|
|
17
|
+
width: 120
|
|
18
|
+
}
|
|
19
|
+
}, /*#__PURE__*/React.createElement(SimpleSingleSelect, {
|
|
20
|
+
name: "simple",
|
|
21
|
+
selected: selected,
|
|
22
|
+
onChange: setSelected,
|
|
23
|
+
options: options,
|
|
24
|
+
menuMaxWidth: "200px"
|
|
25
|
+
}));
|
|
26
|
+
};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import React, { useState } from 'react';
|
|
2
|
+
import { SimpleSingleSelect } from '../simple-single-select.js';
|
|
3
|
+
const options = [{
|
|
4
|
+
value: '1',
|
|
5
|
+
label: 'option one'
|
|
6
|
+
}, {
|
|
7
|
+
value: '2',
|
|
8
|
+
label: 'option two'
|
|
9
|
+
}, {
|
|
10
|
+
value: '3',
|
|
11
|
+
label: 'option three'
|
|
12
|
+
}, {
|
|
13
|
+
value: '4',
|
|
14
|
+
label: 'A longer option that exceeds the minimum'
|
|
15
|
+
}];
|
|
16
|
+
export const WithMenuMinWidth = () => {
|
|
17
|
+
const [selected, setSelected] = useState(null);
|
|
18
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
19
|
+
style: {
|
|
20
|
+
width: 120
|
|
21
|
+
}
|
|
22
|
+
}, /*#__PURE__*/React.createElement(SimpleSingleSelect, {
|
|
23
|
+
name: "simple",
|
|
24
|
+
selected: selected,
|
|
25
|
+
onChange: setSelected,
|
|
26
|
+
options: options,
|
|
27
|
+
menuMinWidth: "240px"
|
|
28
|
+
}));
|
|
29
|
+
};
|