carbon-react 104.8.0 → 104.10.2
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/advanced-color-picker/advanced-color-picker.style.d.ts +7 -1
- package/lib/components/anchor-navigation/anchor-navigation-item/anchor-navigation-item.style.js +14 -32
- package/lib/components/anchor-navigation/anchor-navigation.style.js +1 -15
- package/lib/components/anchor-navigation/anchor-section-divider/anchor-section-divider.style.js +1 -8
- package/lib/components/dialog/dialog.component.d.ts +9 -2
- package/lib/components/dialog/dialog.component.js +12 -4
- package/lib/components/dialog/dialog.config.d.ts +3 -0
- package/lib/components/dialog/dialog.config.js +8 -2
- package/lib/components/dialog/dialog.d.ts +11 -1
- package/lib/components/dialog/dialog.style.d.ts +4 -1
- package/lib/components/dialog/dialog.style.js +66 -19
- package/lib/components/icon/icon.component.js +1 -1
- package/lib/components/pager/pager.style.js +3 -1
- 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/lib/style/themes/base/base-theme.config.d.ts +7 -0
- package/lib/style/themes/sage/index.d.ts +7 -0
- package/package.json +2 -2
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
|
|
3
|
+
export interface SelectTextProps {
|
|
4
|
+
/** If true the Component will be disabled */
|
|
5
|
+
disabled?: boolean;
|
|
6
|
+
/** Value to be displayed */
|
|
7
|
+
formattedValue?: string;
|
|
8
|
+
/** Label id passed from Select component */
|
|
9
|
+
labelId?: string;
|
|
10
|
+
/** If true, the list is displayed */
|
|
11
|
+
isOpen?: boolean;
|
|
12
|
+
/** Callback function for when the Select Textbox loses it's focus. */
|
|
13
|
+
onBlur?: (ev: React.FocusEvent<HTMLElement>) => void;
|
|
14
|
+
/** Callback function for when the component is clicked. */
|
|
15
|
+
onClick?: (ev: React.MouseEvent<HTMLElement>) => void;
|
|
16
|
+
/** Callback function for when the Select Textbox is focused. */
|
|
17
|
+
onFocus?: (ev: React.FocusEvent<HTMLElement>) => void;
|
|
18
|
+
/** Callback function for when the key is pressed when focused on Select Text. */
|
|
19
|
+
onKeyDown?: (ev: React.KeyboardEvent<HTMLElement>) => void;
|
|
20
|
+
/** Callback function for when the left mouse key is pressed when focused on Select Text. */
|
|
21
|
+
onMouseDown?: (ev: React.MouseEvent<HTMLElement>) => void;
|
|
22
|
+
/** Placeholder string to be displayed when formattedValue is empty */
|
|
23
|
+
placeholder?: string;
|
|
24
|
+
/** If true the Component will be read-only */
|
|
25
|
+
readOnly?: boolean;
|
|
26
|
+
/** If true the component has no border and a transparent background */
|
|
27
|
+
transparent?: boolean;
|
|
28
|
+
/** Id of the Select Text element */
|
|
29
|
+
textId?: string;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
declare function SelectText(props: SelectTextProps): JSX.Element;
|
|
33
|
+
|
|
34
|
+
export default SelectText;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
|
|
8
|
+
var _styledComponents = _interopRequireWildcard(require("styled-components"));
|
|
9
|
+
|
|
10
|
+
var _themes = require("../../../../style/themes");
|
|
11
|
+
|
|
12
|
+
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
|
|
13
|
+
|
|
14
|
+
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; }
|
|
15
|
+
|
|
16
|
+
const StyledSelectText = _styledComponents.default.span`
|
|
17
|
+
${({
|
|
18
|
+
disabled,
|
|
19
|
+
hasPlaceholder,
|
|
20
|
+
readOnly,
|
|
21
|
+
theme,
|
|
22
|
+
transparent
|
|
23
|
+
}) => (0, _styledComponents.css)`
|
|
24
|
+
align-items: center;
|
|
25
|
+
display: inline-flex;
|
|
26
|
+
flex-grow: 1;
|
|
27
|
+
font-size: 14px;
|
|
28
|
+
height: auto;
|
|
29
|
+
overflow: hidden;
|
|
30
|
+
outline: none;
|
|
31
|
+
text-overflow: ellipsis;
|
|
32
|
+
white-space: nowrap;
|
|
33
|
+
width: 30px;
|
|
34
|
+
z-index: 1;
|
|
35
|
+
|
|
36
|
+
${transparent && (0, _styledComponents.css)`
|
|
37
|
+
font-weight: 900;
|
|
38
|
+
text-align: right;
|
|
39
|
+
flex-direction: row-reverse;
|
|
40
|
+
`}
|
|
41
|
+
|
|
42
|
+
${hasPlaceholder && (0, _styledComponents.css)`
|
|
43
|
+
color: ${theme.text.placeholder};
|
|
44
|
+
font-weight: normal;
|
|
45
|
+
user-select: none;
|
|
46
|
+
`}
|
|
47
|
+
|
|
48
|
+
${disabled && (0, _styledComponents.css)`
|
|
49
|
+
cursor: not-allowed;
|
|
50
|
+
color: var(--colorsUtilityYin030);
|
|
51
|
+
text-shadow: none;
|
|
52
|
+
`}
|
|
53
|
+
|
|
54
|
+
${readOnly && (0, _styledComponents.css)`
|
|
55
|
+
cursor: default;
|
|
56
|
+
color: var(--colorsYin065);
|
|
57
|
+
text-shadow: none;
|
|
58
|
+
`}
|
|
59
|
+
`}
|
|
60
|
+
`;
|
|
61
|
+
StyledSelectText.defaultProps = {
|
|
62
|
+
theme: _themes.baseTheme
|
|
63
|
+
};
|
|
64
|
+
var _default = StyledSelectText;
|
|
65
|
+
exports.default = _default;
|
|
@@ -67,6 +67,7 @@ const FilterableSelect = /*#__PURE__*/_react.default.forwardRef(({
|
|
|
67
67
|
flipEnabled = true,
|
|
68
68
|
...textboxProps
|
|
69
69
|
}, inputRef) => {
|
|
70
|
+
const [activeDescendantId, setActiveDescendantId] = (0, _react.useState)();
|
|
70
71
|
const selectListId = (0, _react.useRef)((0, _guid.default)());
|
|
71
72
|
const labelId = (0, _react.useRef)((0, _guid.default)());
|
|
72
73
|
const containerRef = (0, _react.useRef)();
|
|
@@ -255,6 +256,7 @@ const FilterableSelect = /*#__PURE__*/_react.default.forwardRef(({
|
|
|
255
256
|
}, [textValue, filterText, textboxRef, disabled, readOnly]);
|
|
256
257
|
const onSelectOption = (0, _react.useCallback)(optionData => {
|
|
257
258
|
const {
|
|
259
|
+
id: selectedOptionId,
|
|
258
260
|
text,
|
|
259
261
|
value: newValue,
|
|
260
262
|
selectionType
|
|
@@ -273,6 +275,7 @@ const FilterableSelect = /*#__PURE__*/_react.default.forwardRef(({
|
|
|
273
275
|
|
|
274
276
|
setTextValue(text);
|
|
275
277
|
triggerChange(newValue);
|
|
278
|
+
setActiveDescendantId(selectedOptionId);
|
|
276
279
|
|
|
277
280
|
if (selectionType !== "navigationKey") {
|
|
278
281
|
setOpen(false);
|
|
@@ -434,8 +437,6 @@ const FilterableSelect = /*#__PURE__*/_react.default.forwardRef(({
|
|
|
434
437
|
}, children);
|
|
435
438
|
|
|
436
439
|
return /*#__PURE__*/_react.default.createElement(_select.default, _extends({
|
|
437
|
-
"aria-expanded": isOpen,
|
|
438
|
-
"aria-haspopup": "listbox",
|
|
439
440
|
ref: containerRef,
|
|
440
441
|
hasTextCursor: true,
|
|
441
442
|
readOnly: readOnly,
|
|
@@ -444,8 +445,10 @@ const FilterableSelect = /*#__PURE__*/_react.default.forwardRef(({
|
|
|
444
445
|
"data-role": dataRole,
|
|
445
446
|
"data-element": dataElement
|
|
446
447
|
}, (0, _utils.filterStyledSystemMarginProps)(textboxProps)), /*#__PURE__*/_react.default.createElement(_selectTextbox.default, _extends({
|
|
447
|
-
|
|
448
|
-
|
|
448
|
+
activeDescendantId: activeDescendantId,
|
|
449
|
+
"aria-controls": isOpen ? selectListId.current : undefined,
|
|
450
|
+
isOpen: isOpen,
|
|
451
|
+
hasTextCursor: true,
|
|
449
452
|
labelId: labelId.current,
|
|
450
453
|
positionedChildren: disablePortal && isOpen && selectList
|
|
451
454
|
}, getTextboxProps())), !disablePortal && isOpen && selectList);
|
|
@@ -70,7 +70,9 @@ const MultiSelect = /*#__PURE__*/_react.default.forwardRef(({
|
|
|
70
70
|
flipEnabled = true,
|
|
71
71
|
...textboxProps
|
|
72
72
|
}, inputRef) => {
|
|
73
|
+
const [activeDescendantId, setActiveDescendantId] = (0, _react.useState)();
|
|
73
74
|
const selectListId = (0, _react.useRef)((0, _guid.default)());
|
|
75
|
+
const accessibilityLabelId = (0, _react.useRef)((0, _guid.default)());
|
|
74
76
|
const labelId = (0, _react.useRef)((0, _guid.default)());
|
|
75
77
|
const containerRef = (0, _react.useRef)();
|
|
76
78
|
const listboxRef = (0, _react.useRef)();
|
|
@@ -163,6 +165,13 @@ const MultiSelect = /*#__PURE__*/_react.default.forwardRef(({
|
|
|
163
165
|
} // eslint-disable-next-line react-hooks/exhaustive-deps
|
|
164
166
|
|
|
165
167
|
}, [onKeyDown, readOnly, filterText, textValue, setOpen, removeSelectedValue]);
|
|
168
|
+
const accessibilityLabel = (0, _react.useMemo)(() => {
|
|
169
|
+
return selectedValue && selectedValue.length ? _react.default.Children.map(children, child => {
|
|
170
|
+
return selectedValue.includes(child.props.value) ? child.props.text : false;
|
|
171
|
+
}).filter(child => child).reduce((acc, item) => {
|
|
172
|
+
return acc ? `${acc}, ${item}` : item;
|
|
173
|
+
}, "") : null;
|
|
174
|
+
}, [children, selectedValue]);
|
|
166
175
|
const handleGlobalClick = (0, _react.useCallback)(event => {
|
|
167
176
|
isMouseDownReported.current = false;
|
|
168
177
|
|
|
@@ -340,11 +349,13 @@ const MultiSelect = /*#__PURE__*/_react.default.forwardRef(({
|
|
|
340
349
|
const onSelectOption = (0, _react.useCallback)(optionData => {
|
|
341
350
|
const {
|
|
342
351
|
value: newValue,
|
|
343
|
-
selectionType
|
|
352
|
+
selectionType,
|
|
353
|
+
id: selectedOptionId
|
|
344
354
|
} = optionData;
|
|
345
355
|
|
|
346
356
|
if (selectionType === "navigationKey") {
|
|
347
357
|
setHighlightedValue(newValue);
|
|
358
|
+
setActiveDescendantId(selectedOptionId);
|
|
348
359
|
return;
|
|
349
360
|
}
|
|
350
361
|
|
|
@@ -440,12 +451,11 @@ const MultiSelect = /*#__PURE__*/_react.default.forwardRef(({
|
|
|
440
451
|
multiColumn: multiColumn,
|
|
441
452
|
listPlacement: listPlacement,
|
|
442
453
|
flipEnabled: flipEnabled,
|
|
443
|
-
loaderDataRole: "multi-select-list-loader"
|
|
454
|
+
loaderDataRole: "multi-select-list-loader",
|
|
455
|
+
multiselectValues: selectedValue
|
|
444
456
|
}, children);
|
|
445
457
|
|
|
446
458
|
return /*#__PURE__*/_react.default.createElement(_multiSelect.StyledSelectMultiSelect, _extends({
|
|
447
|
-
"aria-expanded": isOpen,
|
|
448
|
-
"aria-haspopup": "listbox",
|
|
449
459
|
ref: containerRef,
|
|
450
460
|
disabled: disabled,
|
|
451
461
|
readOnly: readOnly,
|
|
@@ -454,9 +464,15 @@ const MultiSelect = /*#__PURE__*/_react.default.forwardRef(({
|
|
|
454
464
|
"data-component": dataComponent,
|
|
455
465
|
"data-role": dataRole,
|
|
456
466
|
"data-element": dataElement
|
|
457
|
-
}, (0, _utils.filterStyledSystemMarginProps)(textboxProps)), /*#__PURE__*/_react.default.createElement(
|
|
458
|
-
"
|
|
459
|
-
|
|
467
|
+
}, (0, _utils.filterStyledSystemMarginProps)(textboxProps)), /*#__PURE__*/_react.default.createElement(_multiSelect.StyledAccessibilityLabelContainer, {
|
|
468
|
+
"data-element": "accessibility-label",
|
|
469
|
+
id: accessibilityLabelId.current
|
|
470
|
+
}, accessibilityLabel), /*#__PURE__*/_react.default.createElement(_selectTextbox.default, _extends({
|
|
471
|
+
accessibilityLabelId: accessibilityLabelId.current,
|
|
472
|
+
activeDescendantId: activeDescendantId,
|
|
473
|
+
"aria-controls": isOpen ? selectListId.current : undefined,
|
|
474
|
+
hasTextCursor: true,
|
|
475
|
+
isOpen: isOpen,
|
|
460
476
|
labelId: labelId.current,
|
|
461
477
|
positionedChildren: disablePortal && isOpen && selectList
|
|
462
478
|
}, getTextboxProps())), !disablePortal && isOpen && selectList);
|
|
@@ -1,2 +1,3 @@
|
|
|
1
1
|
export const StyledSelectPillContainer: import("styled-components").StyledComponent<"div", any, {}, never>;
|
|
2
2
|
export const StyledSelectMultiSelect: import("styled-components").StyledComponent<"div", any, {}, never>;
|
|
3
|
+
export const StyledAccessibilityLabelContainer: import("styled-components").StyledComponent<"div", any, {}, never>;
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.StyledSelectMultiSelect = exports.StyledSelectPillContainer = void 0;
|
|
6
|
+
exports.StyledAccessibilityLabelContainer = exports.StyledSelectMultiSelect = exports.StyledSelectPillContainer = void 0;
|
|
7
7
|
|
|
8
8
|
var _styledComponents = _interopRequireDefault(require("styled-components"));
|
|
9
9
|
|
|
@@ -47,6 +47,10 @@ const StyledSelectMultiSelect = (0, _styledComponents.default)(_select.default)`
|
|
|
47
47
|
}
|
|
48
48
|
`;
|
|
49
49
|
exports.StyledSelectMultiSelect = StyledSelectMultiSelect;
|
|
50
|
+
const StyledAccessibilityLabelContainer = _styledComponents.default.div`
|
|
51
|
+
display: none;
|
|
52
|
+
`;
|
|
53
|
+
exports.StyledAccessibilityLabelContainer = StyledAccessibilityLabelContainer;
|
|
50
54
|
StyledSelectPillContainer.defaultProps = {
|
|
51
55
|
theme: _themes.baseTheme
|
|
52
56
|
};
|
|
@@ -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 = {
|