carbon-react 104.10.1 → 104.12.1
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/lib/components/flat-table/flat-table-body-draggable/flat-table-body-draggable.component.js +3 -0
- package/lib/components/navigation-bar/navigation-bar.style.js +10 -9
- package/lib/components/pager/pager.style.js +3 -1
- package/lib/components/search/search.style.js +31 -40
- package/lib/components/select/__internal__/select-list-context.d.ts +3 -0
- package/lib/components/select/__internal__/select-list-context.js +15 -0
- package/lib/components/select/__internal__/select-text/select-text.component.d.ts +30 -0
- package/lib/components/select/__internal__/select-text/select-text.component.js +111 -0
- package/lib/components/select/__internal__/select-text/select-text.d.ts +34 -0
- package/lib/components/select/__internal__/select-text/select-text.style.d.ts +2 -0
- package/lib/components/select/__internal__/select-text/select-text.style.js +65 -0
- package/lib/components/select/filterable-select/filterable-select.component.js +7 -4
- package/lib/components/select/multi-select/multi-select.component.js +23 -7
- package/lib/components/select/multi-select/multi-select.style.d.ts +1 -0
- package/lib/components/select/multi-select/multi-select.style.js +5 -1
- package/lib/components/select/option/option.component.js +32 -8
- package/lib/components/select/option-row/option-row.component.js +23 -6
- package/lib/components/select/select-list/select-list.component.js +36 -23
- package/lib/components/select/select-textbox/select-textbox.component.d.ts +113 -26
- package/lib/components/select/select-textbox/select-textbox.component.js +82 -3
- package/lib/components/select/select-textbox/select-textbox.d.ts +8 -2
- package/lib/components/select/select.style.js +10 -7
- package/lib/components/select/simple-select/simple-select.component.js +13 -20
- package/package.json +1 -1
|
@@ -5,46 +5,63 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
|
|
8
|
-
var _react =
|
|
8
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
9
9
|
|
|
10
10
|
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
11
11
|
|
|
12
12
|
var _option = _interopRequireDefault(require("./option.style"));
|
|
13
13
|
|
|
14
|
+
var _selectListContext = _interopRequireDefault(require("../__internal__/select-list-context"));
|
|
15
|
+
|
|
14
16
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
15
17
|
|
|
18
|
+
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
|
|
19
|
+
|
|
20
|
+
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
21
|
+
|
|
16
22
|
const Option = /*#__PURE__*/_react.default.forwardRef(({
|
|
17
23
|
text,
|
|
18
24
|
children,
|
|
19
25
|
onSelect,
|
|
20
26
|
value,
|
|
21
|
-
|
|
27
|
+
id,
|
|
28
|
+
index,
|
|
22
29
|
hidden,
|
|
23
30
|
onClick
|
|
24
31
|
}, ref) => {
|
|
32
|
+
const selectListContext = (0, _react.useContext)(_selectListContext.default);
|
|
33
|
+
let isSelected = selectListContext.currentOptionsListIndex === index;
|
|
34
|
+
|
|
35
|
+
if (selectListContext.multiselectValues) {
|
|
36
|
+
isSelected = selectListContext.multiselectValues.includes(value);
|
|
37
|
+
}
|
|
38
|
+
|
|
25
39
|
function handleClick() {
|
|
26
40
|
if (!onClick) {
|
|
27
41
|
onSelect({
|
|
28
42
|
text,
|
|
29
|
-
value
|
|
43
|
+
value,
|
|
44
|
+
id
|
|
30
45
|
});
|
|
31
46
|
} else {
|
|
32
47
|
onSelect();
|
|
33
48
|
onClick({
|
|
34
49
|
target: {
|
|
35
50
|
text,
|
|
36
|
-
value
|
|
51
|
+
value,
|
|
52
|
+
id
|
|
37
53
|
}
|
|
38
54
|
});
|
|
39
55
|
}
|
|
40
56
|
}
|
|
41
57
|
|
|
42
58
|
return /*#__PURE__*/_react.default.createElement(_option.default, {
|
|
59
|
+
id: id,
|
|
43
60
|
ref: ref,
|
|
44
|
-
"aria-selected":
|
|
61
|
+
"aria-selected": isSelected,
|
|
45
62
|
"data-component": "option",
|
|
46
63
|
onClick: handleClick,
|
|
47
|
-
isHighlighted:
|
|
64
|
+
isHighlighted: selectListContext.currentOptionsListIndex === index,
|
|
48
65
|
role: "option",
|
|
49
66
|
hidden: hidden
|
|
50
67
|
}, children || text);
|
|
@@ -60,6 +77,13 @@ Option.propTypes = {
|
|
|
60
77
|
/** The option's invisible internal value */
|
|
61
78
|
value: _propTypes.default.oneOfType([_propTypes.default.object, _propTypes.default.string]).isRequired,
|
|
62
79
|
|
|
80
|
+
/**
|
|
81
|
+
* @private
|
|
82
|
+
* @ignore
|
|
83
|
+
* Component id (prop added by the SelectList component)
|
|
84
|
+
*/
|
|
85
|
+
id: _propTypes.default.string,
|
|
86
|
+
|
|
63
87
|
/**
|
|
64
88
|
* @private
|
|
65
89
|
* @ignore
|
|
@@ -75,8 +99,8 @@ Option.propTypes = {
|
|
|
75
99
|
/**
|
|
76
100
|
* @private
|
|
77
101
|
* @ignore
|
|
78
|
-
*
|
|
79
|
-
|
|
102
|
+
* Position of the element in the list */
|
|
103
|
+
index: _propTypes.default.number,
|
|
80
104
|
|
|
81
105
|
/**
|
|
82
106
|
* @private
|
|
@@ -5,35 +5,45 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
|
|
8
|
-
var _react =
|
|
8
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
9
9
|
|
|
10
10
|
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
11
11
|
|
|
12
12
|
var _optionRow = _interopRequireDefault(require("./option-row.style"));
|
|
13
13
|
|
|
14
|
+
var _selectListContext = _interopRequireDefault(require("../__internal__/select-list-context"));
|
|
15
|
+
|
|
14
16
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
15
17
|
|
|
18
|
+
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
|
|
19
|
+
|
|
20
|
+
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
21
|
+
|
|
16
22
|
const OptionRow = /*#__PURE__*/_react.default.forwardRef(({
|
|
23
|
+
id,
|
|
17
24
|
text,
|
|
18
25
|
children,
|
|
19
26
|
onSelect,
|
|
20
27
|
value,
|
|
21
|
-
|
|
28
|
+
index,
|
|
22
29
|
hidden
|
|
23
30
|
}, ref) => {
|
|
24
31
|
const handleClick = () => {
|
|
25
32
|
onSelect({
|
|
33
|
+
id,
|
|
26
34
|
text,
|
|
27
35
|
value
|
|
28
36
|
});
|
|
29
37
|
};
|
|
30
38
|
|
|
39
|
+
const selectListContext = (0, _react.useContext)(_selectListContext.default);
|
|
31
40
|
return /*#__PURE__*/_react.default.createElement(_optionRow.default, {
|
|
41
|
+
id: id,
|
|
32
42
|
ref: ref,
|
|
33
|
-
"aria-selected":
|
|
43
|
+
"aria-selected": selectListContext.currentOptionsListIndex === index,
|
|
34
44
|
"data-component": "option-row",
|
|
35
45
|
onClick: handleClick,
|
|
36
|
-
isHighlighted:
|
|
46
|
+
isHighlighted: selectListContext.currentOptionsListIndex === index,
|
|
37
47
|
role: "option",
|
|
38
48
|
hidden: hidden
|
|
39
49
|
}, children);
|
|
@@ -49,6 +59,13 @@ OptionRow.propTypes = {
|
|
|
49
59
|
/** The option's invisible internal value */
|
|
50
60
|
value: _propTypes.default.oneOfType([_propTypes.default.object, _propTypes.default.string]).isRequired,
|
|
51
61
|
|
|
62
|
+
/**
|
|
63
|
+
* @private
|
|
64
|
+
* @ignore
|
|
65
|
+
* Component id (prop added by the SelectList component)
|
|
66
|
+
*/
|
|
67
|
+
id: _propTypes.default.string.isRequired,
|
|
68
|
+
|
|
52
69
|
/**
|
|
53
70
|
* @private
|
|
54
71
|
* @ignore
|
|
@@ -58,8 +75,8 @@ OptionRow.propTypes = {
|
|
|
58
75
|
/**
|
|
59
76
|
* @private
|
|
60
77
|
* @ignore
|
|
61
|
-
*
|
|
62
|
-
|
|
78
|
+
* Position of the element in the list */
|
|
79
|
+
index: _propTypes.default.number,
|
|
63
80
|
|
|
64
81
|
/**
|
|
65
82
|
* @private
|
|
@@ -29,6 +29,10 @@ var _loader = _interopRequireDefault(require("../../loader"));
|
|
|
29
29
|
|
|
30
30
|
var _option = _interopRequireDefault(require("../option/option.component"));
|
|
31
31
|
|
|
32
|
+
var _guid = _interopRequireDefault(require("../../../__internal__/utils/helpers/guid/guid"));
|
|
33
|
+
|
|
34
|
+
var _selectListContext = _interopRequireDefault(require("../__internal__/select-list-context"));
|
|
35
|
+
|
|
32
36
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
33
37
|
|
|
34
38
|
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
|
|
@@ -84,7 +88,6 @@ const SelectList = /*#__PURE__*/_react.default.forwardRef(({
|
|
|
84
88
|
const anchorRef = (0, _react.useMemo)(() => ({
|
|
85
89
|
current: anchorElement
|
|
86
90
|
}), [anchorElement]);
|
|
87
|
-
const childrenList = (0, _react.useMemo)(() => _react.default.Children.toArray(children), [children]);
|
|
88
91
|
const optionRefList = (0, _react.useMemo)(() => _react.default.Children.map(children, child => {
|
|
89
92
|
if ((child === null || child === void 0 ? void 0 : child.type) === _option.default || (child === null || child === void 0 ? void 0 : child.type) === _optionRow.default) {
|
|
90
93
|
return /*#__PURE__*/_react.default.createRef();
|
|
@@ -92,6 +95,26 @@ const SelectList = /*#__PURE__*/_react.default.forwardRef(({
|
|
|
92
95
|
|
|
93
96
|
return null;
|
|
94
97
|
}).filter(child => child), [children]);
|
|
98
|
+
const handleSelect = (0, _react.useCallback)(optionData => {
|
|
99
|
+
onSelect({ ...optionData,
|
|
100
|
+
selectionType: "click"
|
|
101
|
+
});
|
|
102
|
+
}, [onSelect]);
|
|
103
|
+
const childrenWithListProps = (0, _react.useMemo)(() => _react.default.Children.map(children, (child, index) => {
|
|
104
|
+
if (!child || child.type !== _option.default && child.type !== _optionRow.default) {
|
|
105
|
+
return child;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
const newProps = {
|
|
109
|
+
index,
|
|
110
|
+
id: (0, _guid.default)(),
|
|
111
|
+
onSelect: handleSelect,
|
|
112
|
+
hidden: isLoading && _react.default.Children.count(children) === 1,
|
|
113
|
+
ref: optionRefList[index]
|
|
114
|
+
};
|
|
115
|
+
return /*#__PURE__*/_react.default.cloneElement(child, newProps);
|
|
116
|
+
}), [children, handleSelect, isLoading, optionRefList]);
|
|
117
|
+
const childrenList = (0, _react.useMemo)(() => _react.default.Children.toArray(childrenWithListProps), [childrenWithListProps]);
|
|
95
118
|
const lastOptionIndex = (0, _react.useMemo)(() => {
|
|
96
119
|
let lastIndex = 0;
|
|
97
120
|
childrenList.forEach((element, index) => {
|
|
@@ -131,12 +154,14 @@ const SelectList = /*#__PURE__*/_react.default.forwardRef(({
|
|
|
131
154
|
|
|
132
155
|
const {
|
|
133
156
|
text,
|
|
134
|
-
value
|
|
157
|
+
value,
|
|
158
|
+
id: itemId
|
|
135
159
|
} = childrenList[nextIndex].props;
|
|
136
160
|
onSelect({
|
|
137
161
|
text,
|
|
138
162
|
value,
|
|
139
|
-
selectionType: "navigationKey"
|
|
163
|
+
selectionType: "navigationKey",
|
|
164
|
+
id: itemId
|
|
140
165
|
});
|
|
141
166
|
}, [childrenList, currentOptionsListIndex, getIndexOfMatch, getNextHighlightableItemIndex, highlightedValue, onSelect]);
|
|
142
167
|
const handleActionButtonTab = (0, _react.useCallback)((event, isActionButtonFocused) => {
|
|
@@ -174,10 +199,12 @@ const SelectList = /*#__PURE__*/_react.default.forwardRef(({
|
|
|
174
199
|
}
|
|
175
200
|
|
|
176
201
|
const {
|
|
202
|
+
id: itemId,
|
|
177
203
|
text,
|
|
178
204
|
value
|
|
179
205
|
} = currentOption.props;
|
|
180
206
|
onSelect({
|
|
207
|
+
id: itemId,
|
|
181
208
|
text,
|
|
182
209
|
value,
|
|
183
210
|
selectionType: "enterKey"
|
|
@@ -194,24 +221,6 @@ const SelectList = /*#__PURE__*/_react.default.forwardRef(({
|
|
|
194
221
|
onListScrollBottom();
|
|
195
222
|
}
|
|
196
223
|
}, [onListScrollBottom]);
|
|
197
|
-
const handleSelect = (0, _react.useCallback)(optionData => {
|
|
198
|
-
onSelect({ ...optionData,
|
|
199
|
-
selectionType: "click"
|
|
200
|
-
});
|
|
201
|
-
}, [onSelect]);
|
|
202
|
-
const childrenWithListProps = (0, _react.useMemo)(() => _react.default.Children.map(children, (child, index) => {
|
|
203
|
-
if (!child || child.type !== _option.default && child.type !== _optionRow.default) {
|
|
204
|
-
return child;
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
const newProps = {
|
|
208
|
-
onSelect: handleSelect,
|
|
209
|
-
isHighlighted: currentOptionsListIndex === index,
|
|
210
|
-
hidden: isLoading && _react.default.Children.count(children) === 1,
|
|
211
|
-
ref: optionRefList[index]
|
|
212
|
-
};
|
|
213
|
-
return /*#__PURE__*/_react.default.cloneElement(child, newProps);
|
|
214
|
-
}), [children, currentOptionsListIndex, handleSelect, isLoading, optionRefList]);
|
|
215
224
|
const assignListWidth = (0, _react.useCallback)(() => {
|
|
216
225
|
if (!disablePortal && anchorElement) {
|
|
217
226
|
const inputBoundingRect = anchorElement.getBoundingClientRect();
|
|
@@ -313,6 +322,10 @@ const SelectList = /*#__PURE__*/_react.default.forwardRef(({
|
|
|
313
322
|
height: listHeight,
|
|
314
323
|
width: listWidth,
|
|
315
324
|
ref: listContainerRef
|
|
325
|
+
}, /*#__PURE__*/_react.default.createElement(_selectListContext.default.Provider, {
|
|
326
|
+
value: {
|
|
327
|
+
currentOptionsListIndex
|
|
328
|
+
}
|
|
316
329
|
}, /*#__PURE__*/_react.default.createElement(_selectListContainer.default, _extends({
|
|
317
330
|
"data-element": "select-list-wrapper",
|
|
318
331
|
height: listHeight,
|
|
@@ -324,14 +337,14 @@ const SelectList = /*#__PURE__*/_react.default.forwardRef(({
|
|
|
324
337
|
"data-element": "select-list",
|
|
325
338
|
role: "listbox",
|
|
326
339
|
ref: listRef,
|
|
327
|
-
tabIndex: "
|
|
340
|
+
tabIndex: "-1",
|
|
328
341
|
isLoading: isLoading,
|
|
329
342
|
multiColumn: multiColumn
|
|
330
343
|
}, selectListContent, isLoading && loader()), listActionButton && /*#__PURE__*/_react.default.createElement(_listActionButton.default, {
|
|
331
344
|
ref: listActionButtonRef,
|
|
332
345
|
listActionButton: listActionButton,
|
|
333
346
|
onListAction: onListAction
|
|
334
|
-
}))));
|
|
347
|
+
})))));
|
|
335
348
|
});
|
|
336
349
|
|
|
337
350
|
SelectList.propTypes = {
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
export default SelectTextbox;
|
|
2
|
-
declare function SelectTextbox({ value, disabled, readOnly, placeholder, labelId, size, onClick, onFocus, onBlur, selectedValue, required, ...restProps }: {
|
|
2
|
+
declare function SelectTextbox({ accessibilityLabelId, "aria-controls": ariaControls, value, disabled, isOpen, readOnly, placeholder, labelId, size, onClick, onFocus, onBlur, onChange, selectedValue, required, hasTextCursor, transparent, activeDescendantId, ...restProps }: {
|
|
3
3
|
[x: string]: any;
|
|
4
|
+
accessibilityLabelId?: string | undefined;
|
|
5
|
+
"aria-controls": any;
|
|
4
6
|
value: any;
|
|
5
7
|
disabled: any;
|
|
8
|
+
isOpen: any;
|
|
6
9
|
readOnly: any;
|
|
7
10
|
placeholder: any;
|
|
8
11
|
labelId: any;
|
|
@@ -10,34 +13,118 @@ declare function SelectTextbox({ value, disabled, readOnly, placeholder, labelId
|
|
|
10
13
|
onClick: any;
|
|
11
14
|
onFocus: any;
|
|
12
15
|
onBlur: any;
|
|
16
|
+
onChange: any;
|
|
13
17
|
selectedValue: any;
|
|
14
18
|
required: any;
|
|
19
|
+
hasTextCursor: any;
|
|
20
|
+
transparent: any;
|
|
21
|
+
activeDescendantId: any;
|
|
15
22
|
}): JSX.Element;
|
|
16
23
|
declare namespace SelectTextbox {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
24
|
+
const propTypes: {
|
|
25
|
+
/**
|
|
26
|
+
* @ignore
|
|
27
|
+
* @private
|
|
28
|
+
* Id attribute of the select list
|
|
29
|
+
*/
|
|
30
|
+
"aria-controls": PropTypes.Requireable<string>;
|
|
31
|
+
/**
|
|
32
|
+
* @private
|
|
33
|
+
* @ignore
|
|
34
|
+
* Value to be displayed in the Textbox */
|
|
35
|
+
formattedValue: PropTypes.Requireable<string>;
|
|
36
|
+
/**
|
|
37
|
+
* @private
|
|
38
|
+
* @ignore
|
|
39
|
+
* If true, the input will be displayed */
|
|
40
|
+
hasTextCursor: PropTypes.Requireable<boolean>;
|
|
41
|
+
/**
|
|
42
|
+
* @private
|
|
43
|
+
* @ignore
|
|
44
|
+
* Value of the Select Input */
|
|
45
|
+
selectedValue: PropTypes.Requireable<string | object>;
|
|
46
|
+
/**
|
|
47
|
+
* Id of the element containing the currently displayed value
|
|
48
|
+
* to be read by voice readers
|
|
49
|
+
* @private
|
|
50
|
+
* @ignore
|
|
51
|
+
*/
|
|
52
|
+
accessibilityLabelId: PropTypes.Requireable<string>;
|
|
53
|
+
/** Id attribute of the input element */
|
|
54
|
+
id: PropTypes.Requireable<string>;
|
|
55
|
+
/** Name attribute of the input element */
|
|
56
|
+
name: PropTypes.Requireable<string>;
|
|
57
|
+
/** If true the Component will be read-only */
|
|
58
|
+
readOnly: PropTypes.Requireable<boolean>;
|
|
59
|
+
/** If true the Component will be disabled */
|
|
60
|
+
disabled: PropTypes.Requireable<boolean>;
|
|
61
|
+
/** If true the Component will be focused when rendered */
|
|
62
|
+
autoFocus: PropTypes.Requireable<boolean>;
|
|
63
|
+
/**
|
|
64
|
+
* Label id passed from Select component
|
|
65
|
+
* @private
|
|
66
|
+
* @ignore
|
|
67
|
+
*
|
|
68
|
+
*/
|
|
69
|
+
labelId: PropTypes.Requireable<string>;
|
|
70
|
+
/** Label */
|
|
71
|
+
label: PropTypes.Requireable<string>;
|
|
72
|
+
/** Text applied to label help tooltip */
|
|
73
|
+
labelHelp: PropTypes.Requireable<PropTypes.ReactNodeLike>;
|
|
74
|
+
/** When true, label is placed in line with an input */
|
|
75
|
+
labelInline: PropTypes.Requireable<boolean>;
|
|
76
|
+
/** Width of a label in percentage. Works only when labelInline is true */
|
|
77
|
+
labelWidth: PropTypes.Requireable<number>;
|
|
78
|
+
/** Width of an input in percentage. Works only when labelInline is true */
|
|
79
|
+
inputWidth: PropTypes.Requireable<number>;
|
|
80
|
+
/**
|
|
81
|
+
* @ignore
|
|
82
|
+
* @private
|
|
83
|
+
* If true, the select is open
|
|
84
|
+
*/
|
|
85
|
+
isOpen: PropTypes.Requireable<boolean>;
|
|
86
|
+
/** Size of an input */
|
|
87
|
+
size: PropTypes.Requireable<string>;
|
|
88
|
+
/** Placeholder string to be displayed in input */
|
|
89
|
+
placeholder: PropTypes.Requireable<string>;
|
|
90
|
+
/** A custom callback for when changes occur */
|
|
91
|
+
onChange: PropTypes.Requireable<(...args: any[]) => any>;
|
|
92
|
+
/** Callback function for when the Select Textbox is clicked. */
|
|
93
|
+
onClick: PropTypes.Requireable<(...args: any[]) => any>;
|
|
94
|
+
/** Callback function for when the Select Textbox is focused. */
|
|
95
|
+
onFocus: PropTypes.Requireable<(...args: any[]) => any>;
|
|
96
|
+
/** Callback function for when the Select Textbox loses it's focus. */
|
|
97
|
+
onBlur: PropTypes.Requireable<(...args: any[]) => any>;
|
|
98
|
+
/** Callback function for when the key is pressed when focused on Select Textbox. */
|
|
99
|
+
onKeyDown: PropTypes.Requireable<(...args: any[]) => any>;
|
|
100
|
+
/** Breakpoint for adaptive label (inline labels change to top aligned). Enables the adaptive behaviour when set */
|
|
101
|
+
adaptiveLabelBreakpoint: PropTypes.Requireable<number>;
|
|
102
|
+
/** Flag to configure component as mandatory */
|
|
103
|
+
required: PropTypes.Requireable<boolean>;
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
export namespace formInputPropTypes {
|
|
107
|
+
const accessibilityLabelId: PropTypes.Requireable<string>;
|
|
108
|
+
const id: PropTypes.Requireable<string>;
|
|
109
|
+
const name: PropTypes.Requireable<string>;
|
|
110
|
+
const readOnly: PropTypes.Requireable<boolean>;
|
|
111
|
+
const disabled: PropTypes.Requireable<boolean>;
|
|
112
|
+
const autoFocus: PropTypes.Requireable<boolean>;
|
|
113
|
+
const labelId: PropTypes.Requireable<string>;
|
|
114
|
+
const label: PropTypes.Requireable<string>;
|
|
115
|
+
const labelHelp: PropTypes.Requireable<PropTypes.ReactNodeLike>;
|
|
116
|
+
const labelInline: PropTypes.Requireable<boolean>;
|
|
117
|
+
const labelWidth: PropTypes.Requireable<number>;
|
|
118
|
+
const inputWidth: PropTypes.Requireable<number>;
|
|
119
|
+
const isOpen: PropTypes.Requireable<boolean>;
|
|
120
|
+
const size: PropTypes.Requireable<string>;
|
|
121
|
+
const placeholder: PropTypes.Requireable<string>;
|
|
122
|
+
const onChange: PropTypes.Requireable<(...args: any[]) => any>;
|
|
123
|
+
const onClick: PropTypes.Requireable<(...args: any[]) => any>;
|
|
124
|
+
const onFocus: PropTypes.Requireable<(...args: any[]) => any>;
|
|
125
|
+
const onBlur: PropTypes.Requireable<(...args: any[]) => any>;
|
|
126
|
+
const onKeyDown: PropTypes.Requireable<(...args: any[]) => any>;
|
|
127
|
+
const adaptiveLabelBreakpoint: PropTypes.Requireable<number>;
|
|
128
|
+
const required: PropTypes.Requireable<boolean>;
|
|
41
129
|
}
|
|
42
|
-
export namespace formInputPropTypes { }
|
|
43
130
|
import PropTypes from "prop-types";
|
|
@@ -5,7 +5,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.formInputPropTypes = exports.default = void 0;
|
|
7
7
|
|
|
8
|
-
var _react =
|
|
8
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
9
9
|
|
|
10
10
|
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
11
11
|
|
|
@@ -13,13 +13,24 @@ var _textbox = _interopRequireDefault(require("../../textbox"));
|
|
|
13
13
|
|
|
14
14
|
var _useLocale = _interopRequireDefault(require("../../../hooks/__internal__/useLocale"));
|
|
15
15
|
|
|
16
|
+
var _selectText = _interopRequireDefault(require("../__internal__/select-text/select-text.component"));
|
|
17
|
+
|
|
18
|
+
var _guid = _interopRequireDefault(require("../../../__internal__/utils/helpers/guid/guid"));
|
|
19
|
+
|
|
16
20
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
17
21
|
|
|
22
|
+
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
|
|
23
|
+
|
|
24
|
+
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
25
|
+
|
|
18
26
|
function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
19
27
|
|
|
20
28
|
const SelectTextbox = ({
|
|
29
|
+
accessibilityLabelId = "",
|
|
30
|
+
"aria-controls": ariaControls,
|
|
21
31
|
value,
|
|
22
32
|
disabled,
|
|
33
|
+
isOpen,
|
|
23
34
|
readOnly,
|
|
24
35
|
placeholder,
|
|
25
36
|
labelId,
|
|
@@ -27,11 +38,16 @@ const SelectTextbox = ({
|
|
|
27
38
|
onClick,
|
|
28
39
|
onFocus,
|
|
29
40
|
onBlur,
|
|
41
|
+
onChange,
|
|
30
42
|
selectedValue,
|
|
31
43
|
required,
|
|
44
|
+
hasTextCursor,
|
|
45
|
+
transparent,
|
|
46
|
+
activeDescendantId,
|
|
32
47
|
...restProps
|
|
33
48
|
}) => {
|
|
34
49
|
const l = (0, _useLocale.default)();
|
|
50
|
+
const textId = (0, _react.useRef)((0, _guid.default)());
|
|
35
51
|
|
|
36
52
|
function handleTextboxClick(event) {
|
|
37
53
|
if (disabled || readOnly) {
|
|
@@ -59,7 +75,7 @@ const SelectTextbox = ({
|
|
|
59
75
|
|
|
60
76
|
function getTextboxProps() {
|
|
61
77
|
return {
|
|
62
|
-
placeholder: placeholder || l.select.placeholder(),
|
|
78
|
+
placeholder: hasTextCursor ? placeholder || l.select.placeholder() : undefined,
|
|
63
79
|
disabled,
|
|
64
80
|
readOnly,
|
|
65
81
|
required,
|
|
@@ -67,20 +83,63 @@ const SelectTextbox = ({
|
|
|
67
83
|
onFocus: handleTextboxFocus,
|
|
68
84
|
onBlur: handleTextboxBlur,
|
|
69
85
|
labelId,
|
|
86
|
+
type: "text",
|
|
70
87
|
...restProps
|
|
71
88
|
};
|
|
72
89
|
}
|
|
73
90
|
|
|
91
|
+
function getInputAriaAttributes() {
|
|
92
|
+
return {
|
|
93
|
+
"aria-expanded": isOpen,
|
|
94
|
+
"aria-labelledby": hasTextCursor ? `${labelId} ${accessibilityLabelId}` : `${labelId} ${textId.current}`,
|
|
95
|
+
"aria-activedescendant": activeDescendantId,
|
|
96
|
+
"aria-controls": ariaControls,
|
|
97
|
+
"aria-autocomplete": hasTextCursor ? "both" : undefined,
|
|
98
|
+
role: readOnly ? undefined : "combobox"
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
function renderSelectText() {
|
|
103
|
+
if (hasTextCursor) {
|
|
104
|
+
return null;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
return /*#__PURE__*/_react.default.createElement(_selectText.default, _extends({
|
|
108
|
+
textId: textId.current,
|
|
109
|
+
transparent: transparent,
|
|
110
|
+
onKeyDown: handleSelectTextKeydown
|
|
111
|
+
}, getTextboxProps()));
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
function handleSelectTextKeydown(event) {
|
|
115
|
+
if (event.key.length === 1) {
|
|
116
|
+
onChange({
|
|
117
|
+
target: {
|
|
118
|
+
value: event.key
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
74
124
|
return /*#__PURE__*/_react.default.createElement(_textbox.default, _extends({
|
|
75
125
|
"data-element": "select-input",
|
|
76
126
|
inputIcon: "dropdown",
|
|
77
127
|
autoComplete: "off",
|
|
78
128
|
size: size,
|
|
129
|
+
onChange: onChange,
|
|
79
130
|
value: selectedValue
|
|
80
|
-
}, getTextboxProps()));
|
|
131
|
+
}, getInputAriaAttributes(), getTextboxProps()), renderSelectText());
|
|
81
132
|
};
|
|
82
133
|
|
|
83
134
|
const formInputPropTypes = {
|
|
135
|
+
/**
|
|
136
|
+
* Id of the element containing the currently displayed value
|
|
137
|
+
* to be read by voice readers
|
|
138
|
+
* @private
|
|
139
|
+
* @ignore
|
|
140
|
+
*/
|
|
141
|
+
accessibilityLabelId: _propTypes.default.string,
|
|
142
|
+
|
|
84
143
|
/** Id attribute of the input element */
|
|
85
144
|
id: _propTypes.default.string,
|
|
86
145
|
|
|
@@ -119,6 +178,13 @@ const formInputPropTypes = {
|
|
|
119
178
|
/** Width of an input in percentage. Works only when labelInline is true */
|
|
120
179
|
inputWidth: _propTypes.default.number,
|
|
121
180
|
|
|
181
|
+
/**
|
|
182
|
+
* @ignore
|
|
183
|
+
* @private
|
|
184
|
+
* If true, the select is open
|
|
185
|
+
*/
|
|
186
|
+
isOpen: _propTypes.default.bool,
|
|
187
|
+
|
|
122
188
|
/** Size of an input */
|
|
123
189
|
size: _propTypes.default.oneOf(["small", "medium", "large"]),
|
|
124
190
|
|
|
@@ -149,12 +215,25 @@ const formInputPropTypes = {
|
|
|
149
215
|
exports.formInputPropTypes = formInputPropTypes;
|
|
150
216
|
SelectTextbox.propTypes = { ...formInputPropTypes,
|
|
151
217
|
|
|
218
|
+
/**
|
|
219
|
+
* @ignore
|
|
220
|
+
* @private
|
|
221
|
+
* Id attribute of the select list
|
|
222
|
+
*/
|
|
223
|
+
"aria-controls": _propTypes.default.string,
|
|
224
|
+
|
|
152
225
|
/**
|
|
153
226
|
* @private
|
|
154
227
|
* @ignore
|
|
155
228
|
* Value to be displayed in the Textbox */
|
|
156
229
|
formattedValue: _propTypes.default.string,
|
|
157
230
|
|
|
231
|
+
/**
|
|
232
|
+
* @private
|
|
233
|
+
* @ignore
|
|
234
|
+
* If true, the input will be displayed */
|
|
235
|
+
hasTextCursor: _propTypes.default.bool,
|
|
236
|
+
|
|
158
237
|
/**
|
|
159
238
|
* @private
|
|
160
239
|
* @ignore
|
|
@@ -47,10 +47,16 @@ export interface FormInputPropTypes
|
|
|
47
47
|
}
|
|
48
48
|
|
|
49
49
|
export interface SelectTextboxProps extends FormInputPropTypes {
|
|
50
|
+
/** Id attribute of the select list */
|
|
51
|
+
"aria-controls"?: string;
|
|
50
52
|
/** Value to be displayed in the Textbox */
|
|
51
|
-
formattedValue
|
|
53
|
+
formattedValue?: string;
|
|
54
|
+
/** If true, the input will be displayed */
|
|
55
|
+
hasTextCursor?: boolean;
|
|
56
|
+
/** If true, the list is displayed */
|
|
57
|
+
isOpen?: boolean;
|
|
52
58
|
/** Value of the Select Input */
|
|
53
|
-
selectedValue
|
|
59
|
+
selectedValue?:
|
|
54
60
|
| string
|
|
55
61
|
| Record<string, unknown>
|
|
56
62
|
| string[]
|
|
@@ -35,7 +35,7 @@ const StyledSelect = _styledComponents.default.div`
|
|
|
35
35
|
position: relative;
|
|
36
36
|
|
|
37
37
|
${_input.default} {
|
|
38
|
-
cursor:
|
|
38
|
+
cursor: "text";
|
|
39
39
|
|
|
40
40
|
${disabled && (0, _styledComponents.css)`
|
|
41
41
|
cursor: not-allowed;
|
|
@@ -44,7 +44,7 @@ const StyledSelect = _styledComponents.default.div`
|
|
|
44
44
|
`}
|
|
45
45
|
|
|
46
46
|
${readOnly && (0, _styledComponents.css)`
|
|
47
|
-
cursor:
|
|
47
|
+
cursor: "text";
|
|
48
48
|
color: var(--colorsYin065);
|
|
49
49
|
text-shadow: none;
|
|
50
50
|
`}
|
|
@@ -73,15 +73,18 @@ const StyledSelect = _styledComponents.default.div`
|
|
|
73
73
|
border: none;
|
|
74
74
|
}
|
|
75
75
|
|
|
76
|
-
${_input.default} {
|
|
77
|
-
font-weight: 900;
|
|
78
|
-
text-align: right;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
76
|
${_inputIconToggle.default} {
|
|
82
77
|
margin-left: 0;
|
|
83
78
|
}
|
|
84
79
|
`}
|
|
80
|
+
|
|
81
|
+
${!hasTextCursor && (0, _styledComponents.css)`
|
|
82
|
+
${_input.default} {
|
|
83
|
+
position: absolute;
|
|
84
|
+
width: auto;
|
|
85
|
+
opacity: 0;
|
|
86
|
+
}
|
|
87
|
+
`}
|
|
85
88
|
`}
|
|
86
89
|
`;
|
|
87
90
|
StyledSelect.defaultProps = {
|