@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
|
@@ -26,6 +26,8 @@ export function Menu({
|
|
|
26
26
|
loading,
|
|
27
27
|
loadingText,
|
|
28
28
|
maxHeight,
|
|
29
|
+
maxWidth,
|
|
30
|
+
minWidth,
|
|
29
31
|
noMatchText,
|
|
30
32
|
optionUpdateStrategy,
|
|
31
33
|
selectRef,
|
|
@@ -34,17 +36,16 @@ export function Menu({
|
|
|
34
36
|
onClose,
|
|
35
37
|
onEndReached
|
|
36
38
|
}) {
|
|
37
|
-
const [
|
|
39
|
+
const [selectWidth, setSelectWidth] = useState();
|
|
38
40
|
const dataTestPrefix = `${dataTest}-menu`;
|
|
41
|
+
|
|
42
|
+
// Re-measuring whenever `hidden` changes keeps the width current when the
|
|
43
|
+
// select's container has been resized since the menu was last opened
|
|
39
44
|
useEffect(() => {
|
|
40
45
|
if (selectRef) {
|
|
41
|
-
|
|
42
|
-
callback(); // We want to know the width as soon as the
|
|
43
|
-
|
|
44
|
-
selectRef.addEventListener('resize', callback);
|
|
45
|
-
return () => selectRef.removeEventListener('resize', callback);
|
|
46
|
+
setSelectWidth(`${selectRef.offsetWidth}px`);
|
|
46
47
|
}
|
|
47
|
-
}, [selectRef]);
|
|
48
|
+
}, [selectRef, hidden]);
|
|
48
49
|
if (hidden) {
|
|
49
50
|
return null;
|
|
50
51
|
}
|
|
@@ -53,6 +54,10 @@ export function Menu({
|
|
|
53
54
|
// we're in the process of loading options
|
|
54
55
|
!loading;
|
|
55
56
|
const isEmpty = !options.length && !filterValue;
|
|
57
|
+
const flexible = Boolean(minWidth || maxWidth);
|
|
58
|
+
// We never want the menu narrower than the select, so a maxWidth below
|
|
59
|
+
// the select's width intentionally has no effect
|
|
60
|
+
const flexibleMinWidth = minWidth && selectWidth ? `max(${selectWidth}, ${minWidth})` : minWidth || selectWidth;
|
|
56
61
|
return /*#__PURE__*/React.createElement(Layer, {
|
|
57
62
|
onBackdropClick: onClose,
|
|
58
63
|
transparent: true
|
|
@@ -62,7 +67,9 @@ export function Menu({
|
|
|
62
67
|
observeReferenceResize: true
|
|
63
68
|
}, /*#__PURE__*/React.createElement("div", {
|
|
64
69
|
style: {
|
|
65
|
-
width:
|
|
70
|
+
width: flexible ? 'fit-content' : selectWidth,
|
|
71
|
+
minWidth: flexible ? flexibleMinWidth : undefined,
|
|
72
|
+
maxWidth,
|
|
66
73
|
maxHeight
|
|
67
74
|
},
|
|
68
75
|
className: _JSXStyle.dynamic([["2949029222", [colors.white, colors.grey200, elevations.e300]]]) + " " + "menu"
|
|
@@ -113,6 +120,8 @@ Menu.propTypes = {
|
|
|
113
120
|
loading: PropTypes.bool,
|
|
114
121
|
loadingText: PropTypes.string,
|
|
115
122
|
maxHeight: PropTypes.string,
|
|
123
|
+
maxWidth: PropTypes.string,
|
|
124
|
+
minWidth: PropTypes.string,
|
|
116
125
|
noMatchText: PropTypes.string,
|
|
117
126
|
optionComponent: PropTypes.elementType,
|
|
118
127
|
optionUpdateStrategy: PropTypes.oneOf(['off', 'polite', 'assertive']),
|
|
@@ -8,6 +8,11 @@ import { Menu } from './menu/index.js';
|
|
|
8
8
|
import { SelectedValue } from './selected-value/index.js';
|
|
9
9
|
import { optionProp } from './shared-prop-types.js';
|
|
10
10
|
import { useHandleKeyPressOnCombobox, useHandleKeyPressOnFilterInput } from './use-handle-key-press/index.js';
|
|
11
|
+
const defaultSelected = {
|
|
12
|
+
label: '',
|
|
13
|
+
value: ''
|
|
14
|
+
};
|
|
15
|
+
const noop = () => undefined;
|
|
11
16
|
function useFocussedOptionIndex({
|
|
12
17
|
filterable,
|
|
13
18
|
filterValue,
|
|
@@ -65,22 +70,21 @@ export function SimpleSingleSelect({
|
|
|
65
70
|
loading = false,
|
|
66
71
|
menuLoadingText: _menuLoadingText = '',
|
|
67
72
|
menuMaxHeight = '288px',
|
|
73
|
+
menuMaxWidth,
|
|
74
|
+
menuMinWidth,
|
|
68
75
|
noMatchText: _noMatchText = '',
|
|
69
76
|
optionUpdateStrategy = 'polite',
|
|
70
77
|
placeholder = '',
|
|
71
78
|
prefix = '',
|
|
72
|
-
selected =
|
|
73
|
-
label: '',
|
|
74
|
-
value: ''
|
|
75
|
-
},
|
|
79
|
+
selected = defaultSelected,
|
|
76
80
|
tabIndex = '0',
|
|
77
81
|
valid = false,
|
|
78
82
|
warning = false,
|
|
79
|
-
onBlur =
|
|
80
|
-
onClear =
|
|
81
|
-
onEndReached =
|
|
82
|
-
onFilterChange =
|
|
83
|
-
onFocus =
|
|
83
|
+
onBlur = noop,
|
|
84
|
+
onClear = noop,
|
|
85
|
+
onEndReached = noop,
|
|
86
|
+
onFilterChange = noop,
|
|
87
|
+
onFocus = noop
|
|
84
88
|
}) {
|
|
85
89
|
// We can't translate with default props as the translation function would
|
|
86
90
|
// be called before we get any translations from the consuming app/lib
|
|
@@ -230,6 +234,8 @@ export function SimpleSingleSelect({
|
|
|
230
234
|
loading: loading,
|
|
231
235
|
loadingText: menuLoadingText,
|
|
232
236
|
maxHeight: menuMaxHeight,
|
|
237
|
+
maxWidth: menuMaxWidth,
|
|
238
|
+
minWidth: menuMinWidth,
|
|
233
239
|
noMatchText: noMatchText,
|
|
234
240
|
optionUpdateStrategy: optionUpdateStrategy,
|
|
235
241
|
options: options,
|
|
@@ -287,6 +293,10 @@ SimpleSingleSelect.propTypes = {
|
|
|
287
293
|
menuLoadingText: PropTypes.string,
|
|
288
294
|
/** Allows to modify the max height of the menu **/
|
|
289
295
|
menuMaxHeight: PropTypes.string,
|
|
296
|
+
/** See [dropdown menu width](https://developers.dhis2.org/docs/ui/components/select#dropdown-menu-width) **/
|
|
297
|
+
menuMaxWidth: PropTypes.string,
|
|
298
|
+
/** See [dropdown menu width](https://developers.dhis2.org/docs/ui/components/select#dropdown-menu-width) **/
|
|
299
|
+
menuMinWidth: PropTypes.string,
|
|
290
300
|
/** String that will be displayed when the select is being filtered but the options array is empty **/
|
|
291
301
|
noMatchText: requiredIf(props => props.filterable, PropTypes.string),
|
|
292
302
|
/** Allows to override what's rendered inside the `button[role="option"]`.
|
|
@@ -20,6 +20,8 @@ export { WithOptionsAndLoadingText } from './__stories__/WithOptionsAndLoadingTe
|
|
|
20
20
|
export { WithoutOptionsAndLoading } from './__stories__/WithoutOptionsAndLoading.js';
|
|
21
21
|
export { WithManyOptions } from './__stories__/WithManyOptions.js';
|
|
22
22
|
export { WithCustomLowMaxHeight } from './__stories__/WithCustomLowMaxHeight.js';
|
|
23
|
+
export { WithMenuMinWidth } from './__stories__/WithMenuMinWidth.js';
|
|
24
|
+
export { WithMenuMaxWidth } from './__stories__/WithMenuMaxWidth.js';
|
|
23
25
|
export { WithOptionsAndDisabled } from './__stories__/WithOptionsAndDisabled.js';
|
|
24
26
|
export { WithSelectionAndDisabled } from './__stories__/WithSelectionAndDisabled.js';
|
|
25
27
|
export { WithPrefix } from './__stories__/WithPrefix.js';
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
|
|
1
2
|
import '@testing-library/jest-dom';
|
|
2
3
|
import { render, fireEvent, screen } from '@testing-library/react';
|
|
3
4
|
import React, { useState } from 'react';
|
|
@@ -142,6 +143,67 @@ describe('<SimpleSingleSelect />', () => {
|
|
|
142
143
|
const menu = listbox.parentNode.parentNode.parentNode;
|
|
143
144
|
expect(menu.style.maxHeight).toBe('100px');
|
|
144
145
|
});
|
|
146
|
+
describe('dropdown menu width', () => {
|
|
147
|
+
let offsetWidth;
|
|
148
|
+
beforeEach(() => {
|
|
149
|
+
// The menu's width is derived from the select's measured width,
|
|
150
|
+
// which is always 0 in jsdom
|
|
151
|
+
offsetWidth = jest.spyOn(HTMLElement.prototype, 'offsetWidth', 'get').mockReturnValue(120);
|
|
152
|
+
});
|
|
153
|
+
afterEach(() => {
|
|
154
|
+
offsetWidth.mockRestore();
|
|
155
|
+
});
|
|
156
|
+
const renderAndOpen = props => {
|
|
157
|
+
render(/*#__PURE__*/React.createElement(SimpleSingleSelect, _extends({
|
|
158
|
+
name: "simple",
|
|
159
|
+
selected: {
|
|
160
|
+
value: 'foo',
|
|
161
|
+
label: 'Foo'
|
|
162
|
+
},
|
|
163
|
+
onChange: () => null,
|
|
164
|
+
options: [{
|
|
165
|
+
value: 'foo',
|
|
166
|
+
label: 'Foo'
|
|
167
|
+
}]
|
|
168
|
+
}, props)));
|
|
169
|
+
fireEvent.click(screen.getByRole('combobox'));
|
|
170
|
+
const listbox = screen.getByRole('listbox');
|
|
171
|
+
return listbox.parentNode.parentNode.parentNode;
|
|
172
|
+
};
|
|
173
|
+
it('should match the width of the select by default', () => {
|
|
174
|
+
const menu = renderAndOpen();
|
|
175
|
+
expect(menu.style.width).toBe('120px');
|
|
176
|
+
});
|
|
177
|
+
it('should not be narrower than menuMinWidth or the select', () => {
|
|
178
|
+
const menu = renderAndOpen({
|
|
179
|
+
menuMinWidth: '240px'
|
|
180
|
+
});
|
|
181
|
+
expect(menu.style.minWidth).toBe('max(120px, 240px)');
|
|
182
|
+
});
|
|
183
|
+
it('should not be wider than menuMaxWidth', () => {
|
|
184
|
+
const menu = renderAndOpen({
|
|
185
|
+
menuMaxWidth: '200px'
|
|
186
|
+
});
|
|
187
|
+
expect(menu.style.maxWidth).toBe('200px');
|
|
188
|
+
expect(menu.style.minWidth).toBe('120px');
|
|
189
|
+
});
|
|
190
|
+
it('should re-measure the select when the menu is reopened', () => {
|
|
191
|
+
renderAndOpen({
|
|
192
|
+
menuMinWidth: '240px'
|
|
193
|
+
});
|
|
194
|
+
const comboBox = screen.getByRole('combobox');
|
|
195
|
+
|
|
196
|
+
// close the menu
|
|
197
|
+
fireEvent.click(comboBox);
|
|
198
|
+
|
|
199
|
+
// widen the select while the menu is closed, then reopen it
|
|
200
|
+
offsetWidth.mockReturnValue(300);
|
|
201
|
+
fireEvent.click(comboBox);
|
|
202
|
+
const listbox = screen.getByRole('listbox');
|
|
203
|
+
const menu = listbox.parentNode.parentNode.parentNode;
|
|
204
|
+
expect(menu.style.minWidth).toBe('max(300px, 240px)');
|
|
205
|
+
});
|
|
206
|
+
});
|
|
145
207
|
it('should accept a placeholder', () => {
|
|
146
208
|
render(/*#__PURE__*/React.createElement(SimpleSingleSelect, {
|
|
147
209
|
name: "simple",
|
|
@@ -101,6 +101,10 @@ SimpleSingleSelectField.propTypes = {
|
|
|
101
101
|
menuLoadingText: PropTypes.string,
|
|
102
102
|
/** Allows to modify the max height of the menu **/
|
|
103
103
|
menuMaxHeight: PropTypes.string,
|
|
104
|
+
/** See [dropdown menu width](https://developers.dhis2.org/docs/ui/components/select#dropdown-menu-width) **/
|
|
105
|
+
menuMaxWidth: PropTypes.string,
|
|
106
|
+
/** See [dropdown menu width](https://developers.dhis2.org/docs/ui/components/select#dropdown-menu-width) **/
|
|
107
|
+
menuMinWidth: PropTypes.string,
|
|
104
108
|
/** String that will be displayed when the select is being filtered but the options array is empty **/
|
|
105
109
|
noMatchText: requiredIf(props => props.filterable, PropTypes.string),
|
|
106
110
|
/** Allows to override what's rendered inside the `button[role="option"]`.
|
|
@@ -42,6 +42,19 @@ const options = [{
|
|
|
42
42
|
value: '10',
|
|
43
43
|
label: 'ten'
|
|
44
44
|
}];
|
|
45
|
+
const longOptions = [{
|
|
46
|
+
value: '1',
|
|
47
|
+
label: 'option one'
|
|
48
|
+
}, {
|
|
49
|
+
value: '2',
|
|
50
|
+
label: 'option two'
|
|
51
|
+
}, {
|
|
52
|
+
value: '3',
|
|
53
|
+
label: 'option three'
|
|
54
|
+
}, {
|
|
55
|
+
value: '4',
|
|
56
|
+
label: 'A longer option that exceeds the minimum'
|
|
57
|
+
}];
|
|
45
58
|
export default {
|
|
46
59
|
title: 'SimpleSingleSelectField',
|
|
47
60
|
component: SimpleSingleSelectField,
|
|
@@ -169,4 +182,40 @@ export const InputWidth = () => {
|
|
|
169
182
|
onChange: nextValue => setValue(nextValue),
|
|
170
183
|
options: options
|
|
171
184
|
}));
|
|
185
|
+
};
|
|
186
|
+
export const WithMenuMinWidth = () => {
|
|
187
|
+
var _longOptions$find;
|
|
188
|
+
const [value, setValue] = useState('');
|
|
189
|
+
const valueLabel = value ? (_longOptions$find = longOptions.find(option => option.value === value)) === null || _longOptions$find === void 0 ? void 0 : _longOptions$find.label : '';
|
|
190
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
191
|
+
style: {
|
|
192
|
+
width: 120
|
|
193
|
+
}
|
|
194
|
+
}, /*#__PURE__*/React.createElement(SimpleSingleSelectField, {
|
|
195
|
+
name: "simple",
|
|
196
|
+
label: "This is the label",
|
|
197
|
+
value: value,
|
|
198
|
+
valueLabel: valueLabel,
|
|
199
|
+
onChange: nextValue => setValue(nextValue),
|
|
200
|
+
options: longOptions,
|
|
201
|
+
menuMinWidth: "240px"
|
|
202
|
+
}));
|
|
203
|
+
};
|
|
204
|
+
export const WithMenuMaxWidth = () => {
|
|
205
|
+
var _longOptions$find2;
|
|
206
|
+
const [value, setValue] = useState('');
|
|
207
|
+
const valueLabel = value ? (_longOptions$find2 = longOptions.find(option => option.value === value)) === null || _longOptions$find2 === void 0 ? void 0 : _longOptions$find2.label : '';
|
|
208
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
209
|
+
style: {
|
|
210
|
+
width: 120
|
|
211
|
+
}
|
|
212
|
+
}, /*#__PURE__*/React.createElement(SimpleSingleSelectField, {
|
|
213
|
+
name: "simple",
|
|
214
|
+
label: "This is the label",
|
|
215
|
+
value: value,
|
|
216
|
+
valueLabel: valueLabel,
|
|
217
|
+
onChange: nextValue => setValue(nextValue),
|
|
218
|
+
options: longOptions,
|
|
219
|
+
menuMaxWidth: "200px"
|
|
220
|
+
}));
|
|
172
221
|
};
|
|
@@ -49,6 +49,8 @@ describe('<SimpleSingleSelectField />', () => {
|
|
|
49
49
|
loading: false,
|
|
50
50
|
menuLoadingText: "",
|
|
51
51
|
menuMaxHeight: "",
|
|
52
|
+
menuMaxWidth: "400px",
|
|
53
|
+
menuMinWidth: "240px",
|
|
52
54
|
noMatchText: "",
|
|
53
55
|
optionUpdateStrategy: "off",
|
|
54
56
|
placeholder: "",
|
|
@@ -86,6 +88,8 @@ describe('<SimpleSingleSelectField />', () => {
|
|
|
86
88
|
expect(SimpleSingleSelect.mock.calls[0][0].loading).toBe(false);
|
|
87
89
|
expect(SimpleSingleSelect.mock.calls[0][0].menuLoadingText).toBe('');
|
|
88
90
|
expect(SimpleSingleSelect.mock.calls[0][0].menuMaxHeight).toBe('');
|
|
91
|
+
expect(SimpleSingleSelect.mock.calls[0][0].menuMaxWidth).toBe('400px');
|
|
92
|
+
expect(SimpleSingleSelect.mock.calls[0][0].menuMinWidth).toBe('240px');
|
|
89
93
|
expect(SimpleSingleSelect.mock.calls[0][0].noMatchText).toBe('');
|
|
90
94
|
expect(SimpleSingleSelect.mock.calls[0][0].optionUpdateStrategy).toBe('off');
|
|
91
95
|
expect(SimpleSingleSelect.mock.calls[0][0].placeholder).toBe('');
|
|
@@ -13,6 +13,8 @@ const SingleSelect = ({
|
|
|
13
13
|
selected = '',
|
|
14
14
|
tabIndex,
|
|
15
15
|
maxHeight,
|
|
16
|
+
menuMinWidth,
|
|
17
|
+
menuMaxWidth,
|
|
16
18
|
inputMaxHeight,
|
|
17
19
|
onChange,
|
|
18
20
|
onFocus,
|
|
@@ -66,6 +68,8 @@ const SingleSelect = ({
|
|
|
66
68
|
menu: menu,
|
|
67
69
|
tabIndex: tabIndex,
|
|
68
70
|
maxHeight: maxHeight,
|
|
71
|
+
menuMinWidth: menuMinWidth,
|
|
72
|
+
menuMaxWidth: menuMaxWidth,
|
|
69
73
|
onChange: onChange,
|
|
70
74
|
onFocus: onFocus,
|
|
71
75
|
onKeyDown: onKeyDown,
|
|
@@ -110,6 +114,10 @@ SingleSelect.propTypes = {
|
|
|
110
114
|
loading: PropTypes.bool,
|
|
111
115
|
loadingText: PropTypes.string,
|
|
112
116
|
maxHeight: PropTypes.string,
|
|
117
|
+
/** See [dropdown menu width](https://developers.dhis2.org/docs/ui/components/select#dropdown-menu-width) */
|
|
118
|
+
menuMaxWidth: PropTypes.string,
|
|
119
|
+
/** See [dropdown menu width](https://developers.dhis2.org/docs/ui/components/select#dropdown-menu-width) */
|
|
120
|
+
menuMinWidth: PropTypes.string,
|
|
113
121
|
/** Text to show when filter returns no results. Required if `filterable` prop is true */
|
|
114
122
|
noMatchText: requiredIf(props => props.filterable, PropTypes.string),
|
|
115
123
|
placeholder: PropTypes.string,
|
|
@@ -462,4 +462,41 @@ export const ShiftedIntoView = args => /*#__PURE__*/React.createElement(React.Fr
|
|
|
462
462
|
label: "option twelve"
|
|
463
463
|
})), /*#__PURE__*/React.createElement(_JSXStyle, {
|
|
464
464
|
id: "1828862170"
|
|
465
|
-
}, ["html,body,#root{position:relative;height:300px !important;max-height:300px;}", "#root{padding-top:130px !important;}"]));
|
|
465
|
+
}, ["html,body,#root{position:relative;height:300px !important;max-height:300px;}", "#root{padding-top:130px !important;}"]));
|
|
466
|
+
export const WithMenuMaxWidth = args => /*#__PURE__*/React.createElement("div", {
|
|
467
|
+
style: {
|
|
468
|
+
width: 120
|
|
469
|
+
}
|
|
470
|
+
}, /*#__PURE__*/React.createElement(SingleSelect, args, /*#__PURE__*/React.createElement(SingleSelectOption, {
|
|
471
|
+
value: "1",
|
|
472
|
+
label: "option one"
|
|
473
|
+
}), /*#__PURE__*/React.createElement(SingleSelectOption, {
|
|
474
|
+
value: "2",
|
|
475
|
+
label: "option two"
|
|
476
|
+
}), /*#__PURE__*/React.createElement(SingleSelectOption, {
|
|
477
|
+
value: "3",
|
|
478
|
+
label: "A much longer option label"
|
|
479
|
+
})));
|
|
480
|
+
WithMenuMaxWidth.args = {
|
|
481
|
+
menuMaxWidth: '200px'
|
|
482
|
+
};
|
|
483
|
+
export const WithMenuMinWidth = args => /*#__PURE__*/React.createElement("div", {
|
|
484
|
+
style: {
|
|
485
|
+
width: 120
|
|
486
|
+
}
|
|
487
|
+
}, /*#__PURE__*/React.createElement(SingleSelect, args, /*#__PURE__*/React.createElement(SingleSelectOption, {
|
|
488
|
+
value: "1",
|
|
489
|
+
label: "option one"
|
|
490
|
+
}), /*#__PURE__*/React.createElement(SingleSelectOption, {
|
|
491
|
+
value: "2",
|
|
492
|
+
label: "option two"
|
|
493
|
+
}), /*#__PURE__*/React.createElement(SingleSelectOption, {
|
|
494
|
+
value: "3",
|
|
495
|
+
label: "option three"
|
|
496
|
+
}), /*#__PURE__*/React.createElement(SingleSelectOption, {
|
|
497
|
+
value: "4",
|
|
498
|
+
label: "A longer option that exceeds the minimum"
|
|
499
|
+
})));
|
|
500
|
+
WithMenuMinWidth.args = {
|
|
501
|
+
menuMinWidth: '240px'
|
|
502
|
+
};
|
|
@@ -36,6 +36,8 @@ class SingleSelectField 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 SingleSelectField 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 @@ SingleSelectField.propTypes = {
|
|
|
140
144
|
loadingText: PropTypes.oneOfType([PropTypes.string, PropTypes.func]),
|
|
141
145
|
/** Constrains height of the SingleSelect */
|
|
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 SingleSelect is empty */
|
|
@@ -173,4 +173,44 @@ DefaultLoadingText.args = {
|
|
|
173
173
|
loading: true,
|
|
174
174
|
...DefaultEmpty.args
|
|
175
175
|
};
|
|
176
|
-
DefaultLoadingText.storyName = 'Default: loadingText';
|
|
176
|
+
DefaultLoadingText.storyName = 'Default: loadingText';
|
|
177
|
+
export const WithMenuMaxWidth = Template.bind({});
|
|
178
|
+
WithMenuMaxWidth.args = {
|
|
179
|
+
inputWidth: '120px',
|
|
180
|
+
menuMaxWidth: '200px',
|
|
181
|
+
children: [/*#__PURE__*/React.createElement(SingleSelectOption, {
|
|
182
|
+
key: "1",
|
|
183
|
+
value: "1",
|
|
184
|
+
label: "option one"
|
|
185
|
+
}), /*#__PURE__*/React.createElement(SingleSelectOption, {
|
|
186
|
+
key: "2",
|
|
187
|
+
value: "2",
|
|
188
|
+
label: "option two"
|
|
189
|
+
}), /*#__PURE__*/React.createElement(SingleSelectOption, {
|
|
190
|
+
key: "3",
|
|
191
|
+
value: "3",
|
|
192
|
+
label: "A much longer option label"
|
|
193
|
+
})]
|
|
194
|
+
};
|
|
195
|
+
export const WithMenuMinWidth = Template.bind({});
|
|
196
|
+
WithMenuMinWidth.args = {
|
|
197
|
+
inputWidth: '120px',
|
|
198
|
+
menuMinWidth: '240px',
|
|
199
|
+
children: [/*#__PURE__*/React.createElement(SingleSelectOption, {
|
|
200
|
+
key: "1",
|
|
201
|
+
value: "1",
|
|
202
|
+
label: "option one"
|
|
203
|
+
}), /*#__PURE__*/React.createElement(SingleSelectOption, {
|
|
204
|
+
key: "2",
|
|
205
|
+
value: "2",
|
|
206
|
+
label: "option two"
|
|
207
|
+
}), /*#__PURE__*/React.createElement(SingleSelectOption, {
|
|
208
|
+
key: "3",
|
|
209
|
+
value: "3",
|
|
210
|
+
label: "option three"
|
|
211
|
+
}), /*#__PURE__*/React.createElement(SingleSelectOption, {
|
|
212
|
+
key: "4",
|
|
213
|
+
value: "4",
|
|
214
|
+
label: "A longer option that exceeds the minimum"
|
|
215
|
+
})]
|
|
216
|
+
};
|
|
@@ -16,17 +16,17 @@ const SingleSelectOption = ({
|
|
|
16
16
|
"data-test": dataTest,
|
|
17
17
|
"data-value": value,
|
|
18
18
|
"data-label": label,
|
|
19
|
-
className: _JSXStyle.dynamic([["
|
|
19
|
+
className: _JSXStyle.dynamic([["556453451", [colors.grey900, spacers.dp8, spacers.dp12, colors.grey200, colors.teal050, colors.grey500, active ? `url('data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMTYiIGhlaWdodD0iMTYiIHZpZXdCb3g9IjAgMCAxNiAxNiIgZmlsbD0ibm9uZSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj4KPHBhdGggZD0iTTMuNjMyMDkgNy44MzIxNEMzLjI3MjA5IDcuNDcyMTQgMi43MjAwOSA3LjQ3MjE0IDIuMzYwMDkgNy44MzIxNEMyLjAwMDA5IDguMTkyMTQgMi4wMDAwOSA4Ljc0NDE0IDIuMzYwMDkgOS4xMDQxNEw1LjYyNDA5IDEyLjM2ODFDNS45ODQwOSAxMi43MjgxIDYuNTM2MDkgMTIuNzI4MSA2Ljg5NjA5IDEyLjM2ODFMMTQuNjQ4MSA0LjY0MDE0QzE1LjAwODEgNC4yODAxNCAxNS4wMDgxIDMuNzI4MTQgMTQuNjQ4MSAzLjM2ODE0QzE0LjI4ODEgMy4wMDgxNCAxMy43MzYxIDMuMDA4MTQgMTMuMzUyMSAzLjM2ODE0TDYuMjcyMDkgMTAuNDcyMUwzLjYzMjA5IDcuODMyMTRaIiBmaWxsPSIjMDA2OTVDIi8+Cjwvc3ZnPgo=')` : 'none']]]) + " " + (cx(className, {
|
|
20
20
|
disabled,
|
|
21
21
|
active
|
|
22
22
|
}) || "")
|
|
23
23
|
}, /*#__PURE__*/React.createElement("span", {
|
|
24
24
|
"aria-hidden": "true",
|
|
25
|
-
className: _JSXStyle.dynamic([["
|
|
25
|
+
className: _JSXStyle.dynamic([["556453451", [colors.grey900, spacers.dp8, spacers.dp12, colors.grey200, colors.teal050, colors.grey500, active ? `url('data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMTYiIGhlaWdodD0iMTYiIHZpZXdCb3g9IjAgMCAxNiAxNiIgZmlsbD0ibm9uZSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj4KPHBhdGggZD0iTTMuNjMyMDkgNy44MzIxNEMzLjI3MjA5IDcuNDcyMTQgMi43MjAwOSA3LjQ3MjE0IDIuMzYwMDkgNy44MzIxNEMyLjAwMDA5IDguMTkyMTQgMi4wMDAwOSA4Ljc0NDE0IDIuMzYwMDkgOS4xMDQxNEw1LjYyNDA5IDEyLjM2ODFDNS45ODQwOSAxMi43MjgxIDYuNTM2MDkgMTIuNzI4MSA2Ljg5NjA5IDEyLjM2ODFMMTQuNjQ4MSA0LjY0MDE0QzE1LjAwODEgNC4yODAxNCAxNS4wMDgxIDMuNzI4MTQgMTQuNjQ4MSAzLjM2ODE0QzE0LjI4ODEgMy4wMDgxNCAxMy43MzYxIDMuMDA4MTQgMTMuMzUyMSAzLjM2ODE0TDYuMjcyMDkgMTAuNDcyMUwzLjYzMjA5IDcuODMyMTRaIiBmaWxsPSIjMDA2OTVDIi8+Cjwvc3ZnPgo=')` : 'none']]]) + " " + "checkmark"
|
|
26
26
|
}), /*#__PURE__*/React.createElement("span", {
|
|
27
|
-
className: _JSXStyle.dynamic([["
|
|
27
|
+
className: _JSXStyle.dynamic([["556453451", [colors.grey900, spacers.dp8, spacers.dp12, colors.grey200, colors.teal050, colors.grey500, active ? `url('data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMTYiIGhlaWdodD0iMTYiIHZpZXdCb3g9IjAgMCAxNiAxNiIgZmlsbD0ibm9uZSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj4KPHBhdGggZD0iTTMuNjMyMDkgNy44MzIxNEMzLjI3MjA5IDcuNDcyMTQgMi43MjAwOSA3LjQ3MjE0IDIuMzYwMDkgNy44MzIxNEMyLjAwMDA5IDguMTkyMTQgMi4wMDAwOSA4Ljc0NDE0IDIuMzYwMDkgOS4xMDQxNEw1LjYyNDA5IDEyLjM2ODFDNS45ODQwOSAxMi43MjgxIDYuNTM2MDkgMTIuNzI4MSA2Ljg5NjA5IDEyLjM2ODFMMTQuNjQ4MSA0LjY0MDE0QzE1LjAwODEgNC4yODAxNCAxNS4wMDgxIDMuNzI4MTQgMTQuNjQ4MSAzLjM2ODE0QzE0LjI4ODEgMy4wMDgxNCAxMy43MzYxIDMuMDA4MTQgMTMuMzUyMSAzLjM2ODE0TDYuMjcyMDkgMTAuNDcyMUwzLjYzMjA5IDcuODMyMTRaIiBmaWxsPSIjMDA2OTVDIi8+Cjwvc3ZnPgo=')` : 'none']]]) + " " + "content"
|
|
28
28
|
}, label), /*#__PURE__*/React.createElement(_JSXStyle, {
|
|
29
|
-
id: "
|
|
29
|
+
id: "556453451",
|
|
30
30
|
dynamic: [colors.grey900, spacers.dp8, spacers.dp12, colors.grey200, colors.teal050, colors.grey500, active ? `url('data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMTYiIGhlaWdodD0iMTYiIHZpZXdCb3g9IjAgMCAxNiAxNiIgZmlsbD0ibm9uZSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj4KPHBhdGggZD0iTTMuNjMyMDkgNy44MzIxNEMzLjI3MjA5IDcuNDcyMTQgMi43MjAwOSA3LjQ3MjE0IDIuMzYwMDkgNy44MzIxNEMyLjAwMDA5IDguMTkyMTQgMi4wMDAwOSA4Ljc0NDE0IDIuMzYwMDkgOS4xMDQxNEw1LjYyNDA5IDEyLjM2ODFDNS45ODQwOSAxMi43MjgxIDYuNTM2MDkgMTIuNzI4MSA2Ljg5NjA5IDEyLjM2ODFMMTQuNjQ4MSA0LjY0MDE0QzE1LjAwODEgNC4yODAxNCAxNS4wMDgxIDMuNzI4MTQgMTQuNjQ4MSAzLjM2ODE0QzE0LjI4ODEgMy4wMDgxNCAxMy43MzYxIDMuMDA4MTQgMTMuMzUyMSAzLjM2ODE0TDYuMjcyMDkgMTAuNDcyMUwzLjYzMjA5IDcuODMyMTRaIiBmaWxsPSIjMDA2OTVDIi8+Cjwvc3ZnPgo=')` : 'none']
|
|
31
31
|
}, [`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:${colors.grey900};padding-block:${spacers.dp8};padding-inline:6px ${spacers.dp12};}`, `div.__jsx-style-dynamic-selector:hover{background-color:${colors.grey200};}`, `div.__jsx-style-dynamic-selector:active,div.active.__jsx-style-dynamic-selector{background-color:${colors.teal050};cursor:auto;}`, `div.disabled.__jsx-style-dynamic-selector{color:${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'};}`]));
|
|
32
32
|
SingleSelectOption.propTypes = {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dhis2-ui/select",
|
|
3
|
-
"version": "10.
|
|
3
|
+
"version": "10.18.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.
|
|
37
|
-
"@dhis2-ui/button": "10.
|
|
38
|
-
"@dhis2-ui/card": "10.
|
|
39
|
-
"@dhis2-ui/checkbox": "10.
|
|
40
|
-
"@dhis2-ui/chip": "10.
|
|
41
|
-
"@dhis2-ui/field": "10.
|
|
42
|
-
"@dhis2-ui/input": "10.
|
|
43
|
-
"@dhis2-ui/layer": "10.
|
|
44
|
-
"@dhis2-ui/loader": "10.
|
|
45
|
-
"@dhis2-ui/popper": "10.
|
|
46
|
-
"@dhis2-ui/status-icon": "10.
|
|
47
|
-
"@dhis2-ui/tooltip": "10.
|
|
36
|
+
"@dhis2-ui/box": "10.18.0",
|
|
37
|
+
"@dhis2-ui/button": "10.18.0",
|
|
38
|
+
"@dhis2-ui/card": "10.18.0",
|
|
39
|
+
"@dhis2-ui/checkbox": "10.18.0",
|
|
40
|
+
"@dhis2-ui/chip": "10.18.0",
|
|
41
|
+
"@dhis2-ui/field": "10.18.0",
|
|
42
|
+
"@dhis2-ui/input": "10.18.0",
|
|
43
|
+
"@dhis2-ui/layer": "10.18.0",
|
|
44
|
+
"@dhis2-ui/loader": "10.18.0",
|
|
45
|
+
"@dhis2-ui/popper": "10.18.0",
|
|
46
|
+
"@dhis2-ui/status-icon": "10.18.0",
|
|
47
|
+
"@dhis2-ui/tooltip": "10.18.0",
|
|
48
48
|
"@dhis2/prop-types": "^3.1.2",
|
|
49
|
-
"@dhis2/ui-constants": "10.
|
|
50
|
-
"@dhis2/ui-icons": "10.
|
|
49
|
+
"@dhis2/ui-constants": "10.18.0",
|
|
50
|
+
"@dhis2/ui-icons": "10.18.0",
|
|
51
51
|
"classnames": "^2.3.1",
|
|
52
52
|
"prop-types": "^15.7.2"
|
|
53
53
|
},
|
|
@@ -15,6 +15,8 @@ const MultiSelect = ({
|
|
|
15
15
|
selected = staticArr,
|
|
16
16
|
tabIndex,
|
|
17
17
|
maxHeight,
|
|
18
|
+
menuMinWidth,
|
|
19
|
+
menuMaxWidth,
|
|
18
20
|
inputMaxHeight,
|
|
19
21
|
onChange,
|
|
20
22
|
onFocus,
|
|
@@ -72,6 +74,8 @@ const MultiSelect = ({
|
|
|
72
74
|
menu={menu}
|
|
73
75
|
tabIndex={tabIndex}
|
|
74
76
|
maxHeight={maxHeight}
|
|
77
|
+
menuMinWidth={menuMinWidth}
|
|
78
|
+
menuMaxWidth={menuMaxWidth}
|
|
75
79
|
onChange={onChange}
|
|
76
80
|
onFocus={onFocus}
|
|
77
81
|
onKeyDown={onKeyDown}
|
|
@@ -131,6 +135,10 @@ MultiSelect.propTypes = {
|
|
|
131
135
|
loading: PropTypes.bool,
|
|
132
136
|
loadingText: PropTypes.string,
|
|
133
137
|
maxHeight: PropTypes.string,
|
|
138
|
+
/** See [dropdown menu width](https://developers.dhis2.org/docs/ui/components/select#dropdown-menu-width) */
|
|
139
|
+
menuMaxWidth: PropTypes.string,
|
|
140
|
+
/** See [dropdown menu width](https://developers.dhis2.org/docs/ui/components/select#dropdown-menu-width) */
|
|
141
|
+
menuMinWidth: PropTypes.string,
|
|
134
142
|
/** Required if `filterable` prop is `true` */
|
|
135
143
|
noMatchText: requiredIf((props) => props.filterable, PropTypes.string),
|
|
136
144
|
placeholder: PropTypes.string,
|
|
@@ -406,3 +406,29 @@ export const RTL = (args) => {
|
|
|
406
406
|
)
|
|
407
407
|
}
|
|
408
408
|
RTL.args = { selected: ['1', '2'], prefix: 'RTL text' }
|
|
409
|
+
|
|
410
|
+
export const WithMenuMaxWidth = (args) => (
|
|
411
|
+
<div style={{ width: 120 }}>
|
|
412
|
+
<MultiSelect {...args}>
|
|
413
|
+
<MultiSelectOption value="1" label="option one" />
|
|
414
|
+
<MultiSelectOption value="2" label="option two" />
|
|
415
|
+
<MultiSelectOption value="3" label="A much longer option label" />
|
|
416
|
+
</MultiSelect>
|
|
417
|
+
</div>
|
|
418
|
+
)
|
|
419
|
+
WithMenuMaxWidth.args = { menuMaxWidth: '200px' }
|
|
420
|
+
|
|
421
|
+
export const WithMenuMinWidth = (args) => (
|
|
422
|
+
<div style={{ width: 120 }}>
|
|
423
|
+
<MultiSelect {...args}>
|
|
424
|
+
<MultiSelectOption value="1" label="option one" />
|
|
425
|
+
<MultiSelectOption value="2" label="option two" />
|
|
426
|
+
<MultiSelectOption value="3" label="option three" />
|
|
427
|
+
<MultiSelectOption
|
|
428
|
+
value="4"
|
|
429
|
+
label="A longer option that exceeds the minimum"
|
|
430
|
+
/>
|
|
431
|
+
</MultiSelect>
|
|
432
|
+
</div>
|
|
433
|
+
)
|
|
434
|
+
WithMenuMinWidth.args = { menuMinWidth: '240px' }
|
|
@@ -46,6 +46,8 @@ class MultiSelectField extends React.Component {
|
|
|
46
46
|
helpText,
|
|
47
47
|
validationText,
|
|
48
48
|
maxHeight,
|
|
49
|
+
menuMinWidth,
|
|
50
|
+
menuMaxWidth,
|
|
49
51
|
inputMaxHeight,
|
|
50
52
|
inputWidth,
|
|
51
53
|
children,
|
|
@@ -81,6 +83,8 @@ class MultiSelectField extends React.Component {
|
|
|
81
83
|
selected={selected}
|
|
82
84
|
tabIndex={tabIndex}
|
|
83
85
|
maxHeight={maxHeight}
|
|
86
|
+
menuMinWidth={menuMinWidth}
|
|
87
|
+
menuMaxWidth={menuMaxWidth}
|
|
84
88
|
inputMaxHeight={inputMaxHeight}
|
|
85
89
|
onChange={onChange}
|
|
86
90
|
onFocus={onFocus}
|
|
@@ -148,6 +152,10 @@ MultiSelectField.propTypes = {
|
|
|
148
152
|
loadingText: PropTypes.oneOfType([PropTypes.string, PropTypes.func]),
|
|
149
153
|
/** Constrains height of the MultiSelect */
|
|
150
154
|
maxHeight: PropTypes.string,
|
|
155
|
+
/** See [dropdown menu width](https://developers.dhis2.org/docs/ui/components/select#dropdown-menu-width) */
|
|
156
|
+
menuMaxWidth: PropTypes.string,
|
|
157
|
+
/** See [dropdown menu width](https://developers.dhis2.org/docs/ui/components/select#dropdown-menu-width) */
|
|
158
|
+
menuMinWidth: PropTypes.string,
|
|
151
159
|
/** Text to display when there are no filter results */
|
|
152
160
|
noMatchText: PropTypes.oneOfType([PropTypes.string, PropTypes.func]),
|
|
153
161
|
/** Placeholder text when the MultiSelect is empty */
|
|
@@ -135,3 +135,34 @@ DefaultFilterPlaceholderAndNoMatchText.storyName =
|
|
|
135
135
|
export const DefaultLoadingText = Template.bind({})
|
|
136
136
|
DefaultLoadingText.args = { loading: true, ...DefaultEmpty.args }
|
|
137
137
|
DefaultLoadingText.storyName = 'Default: loadingText'
|
|
138
|
+
|
|
139
|
+
export const WithMenuMaxWidth = Template.bind({})
|
|
140
|
+
WithMenuMaxWidth.args = {
|
|
141
|
+
inputWidth: '120px',
|
|
142
|
+
menuMaxWidth: '200px',
|
|
143
|
+
children: [
|
|
144
|
+
<MultiSelectOption key="1" value="1" label="option one" />,
|
|
145
|
+
<MultiSelectOption key="2" value="2" label="option two" />,
|
|
146
|
+
<MultiSelectOption
|
|
147
|
+
key="3"
|
|
148
|
+
value="3"
|
|
149
|
+
label="A much longer option label"
|
|
150
|
+
/>,
|
|
151
|
+
],
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
export const WithMenuMinWidth = Template.bind({})
|
|
155
|
+
WithMenuMinWidth.args = {
|
|
156
|
+
inputWidth: '120px',
|
|
157
|
+
menuMinWidth: '240px',
|
|
158
|
+
children: [
|
|
159
|
+
<MultiSelectOption key="1" value="1" label="option one" />,
|
|
160
|
+
<MultiSelectOption key="2" value="2" label="option two" />,
|
|
161
|
+
<MultiSelectOption key="3" value="3" label="option three" />,
|
|
162
|
+
<MultiSelectOption
|
|
163
|
+
key="4"
|
|
164
|
+
value="4"
|
|
165
|
+
label="A longer option that exceeds the minimum"
|
|
166
|
+
/>,
|
|
167
|
+
],
|
|
168
|
+
}
|