carbon-react 104.10.1 → 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/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/package.json +1 -1
|
@@ -15,6 +15,8 @@ var _inputIconToggle = _interopRequireDefault(require("../../__internal__/input-
|
|
|
15
15
|
|
|
16
16
|
var _base = _interopRequireDefault(require("../../style/themes/base"));
|
|
17
17
|
|
|
18
|
+
var _selectText = _interopRequireDefault(require("../select/__internal__/select-text/select-text.style"));
|
|
19
|
+
|
|
18
20
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
19
21
|
|
|
20
22
|
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
|
|
@@ -108,7 +110,7 @@ const StyledPagerSizeOptions = _styledComponents.default.div`
|
|
|
108
110
|
min-width: 10px;
|
|
109
111
|
margin: 0px 4px;
|
|
110
112
|
|
|
111
|
-
${
|
|
113
|
+
${_selectText.default} {
|
|
112
114
|
font-size: 14px;
|
|
113
115
|
padding-right: 0px;
|
|
114
116
|
padding-left: 8px;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
|
|
8
|
+
var _react = _interopRequireDefault(require("react"));
|
|
9
|
+
|
|
10
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
|
+
|
|
12
|
+
const SelectListContext = /*#__PURE__*/_react.default.createContext({});
|
|
13
|
+
|
|
14
|
+
var _default = SelectListContext;
|
|
15
|
+
exports.default = _default;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
export default SelectText;
|
|
2
|
+
declare function SelectText({ disabled, formattedValue, onClick, onKeyDown, onFocus, onBlur, onMouseDown, placeholder, readOnly, textId, transparent, }: {
|
|
3
|
+
disabled: any;
|
|
4
|
+
formattedValue: any;
|
|
5
|
+
onClick: any;
|
|
6
|
+
onKeyDown: any;
|
|
7
|
+
onFocus: any;
|
|
8
|
+
onBlur: any;
|
|
9
|
+
onMouseDown: any;
|
|
10
|
+
placeholder: any;
|
|
11
|
+
readOnly: any;
|
|
12
|
+
textId: any;
|
|
13
|
+
transparent: any;
|
|
14
|
+
}): JSX.Element;
|
|
15
|
+
declare namespace SelectText {
|
|
16
|
+
namespace propTypes {
|
|
17
|
+
const disabled: PropTypes.Requireable<boolean>;
|
|
18
|
+
const formattedValue: PropTypes.Requireable<string>;
|
|
19
|
+
const onBlur: PropTypes.Requireable<(...args: any[]) => any>;
|
|
20
|
+
const onClick: PropTypes.Requireable<(...args: any[]) => any>;
|
|
21
|
+
const onFocus: PropTypes.Requireable<(...args: any[]) => any>;
|
|
22
|
+
const onKeyDown: PropTypes.Requireable<(...args: any[]) => any>;
|
|
23
|
+
const onMouseDown: PropTypes.Requireable<(...args: any[]) => any>;
|
|
24
|
+
const placeholder: PropTypes.Requireable<string>;
|
|
25
|
+
const readOnly: PropTypes.Requireable<boolean>;
|
|
26
|
+
const transparent: PropTypes.Requireable<boolean>;
|
|
27
|
+
const textId: PropTypes.Requireable<string>;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
import PropTypes from "prop-types";
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
|
|
8
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
9
|
+
|
|
10
|
+
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
11
|
+
|
|
12
|
+
var _selectText = _interopRequireDefault(require("./select-text.style"));
|
|
13
|
+
|
|
14
|
+
var _useLocale = _interopRequireDefault(require("../../../../hooks/__internal__/useLocale"));
|
|
15
|
+
|
|
16
|
+
var _inputBehaviour = require("../../../../__internal__/input-behaviour");
|
|
17
|
+
|
|
18
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
19
|
+
|
|
20
|
+
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
|
|
21
|
+
|
|
22
|
+
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; }
|
|
23
|
+
|
|
24
|
+
const SelectText = ({
|
|
25
|
+
disabled,
|
|
26
|
+
formattedValue,
|
|
27
|
+
onClick,
|
|
28
|
+
onKeyDown,
|
|
29
|
+
onFocus,
|
|
30
|
+
onBlur,
|
|
31
|
+
onMouseDown,
|
|
32
|
+
placeholder,
|
|
33
|
+
readOnly,
|
|
34
|
+
textId,
|
|
35
|
+
transparent
|
|
36
|
+
}) => {
|
|
37
|
+
const l = (0, _useLocale.default)();
|
|
38
|
+
const inputContext = (0, _react.useContext)(_inputBehaviour.InputContext);
|
|
39
|
+
const hasPlaceholder = !disabled && !readOnly && !formattedValue;
|
|
40
|
+
const placeholderText = hasPlaceholder ? placeholder || l.select.placeholder() : "";
|
|
41
|
+
|
|
42
|
+
function handleFocus(event) {
|
|
43
|
+
inputContext.onFocus(event);
|
|
44
|
+
|
|
45
|
+
if (onFocus) {
|
|
46
|
+
onFocus(event);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function handleBlur(event) {
|
|
51
|
+
inputContext.onBlur(event);
|
|
52
|
+
|
|
53
|
+
if (onBlur) {
|
|
54
|
+
onBlur(event);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
return /*#__PURE__*/_react.default.createElement(_selectText.default, {
|
|
59
|
+
"aria-hidden": true,
|
|
60
|
+
"data-element": "select-text",
|
|
61
|
+
disabled: disabled,
|
|
62
|
+
hasPlaceholder: hasPlaceholder,
|
|
63
|
+
id: textId,
|
|
64
|
+
onBlur: handleBlur,
|
|
65
|
+
onClick: onClick,
|
|
66
|
+
onFocus: handleFocus,
|
|
67
|
+
onKeyDown: onKeyDown,
|
|
68
|
+
onMouseDown: onMouseDown,
|
|
69
|
+
readOnly: readOnly,
|
|
70
|
+
role: "button",
|
|
71
|
+
tabIndex: "-1",
|
|
72
|
+
transparent: transparent
|
|
73
|
+
}, formattedValue || placeholderText);
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
SelectText.propTypes = {
|
|
77
|
+
/** If true the Component will be disabled */
|
|
78
|
+
disabled: _propTypes.default.bool,
|
|
79
|
+
|
|
80
|
+
/** Value to be displayed */
|
|
81
|
+
formattedValue: _propTypes.default.string,
|
|
82
|
+
|
|
83
|
+
/** Callback function for when the Select Textbox loses it's focus. */
|
|
84
|
+
onBlur: _propTypes.default.func,
|
|
85
|
+
|
|
86
|
+
/** Callback function for when the component is clicked. */
|
|
87
|
+
onClick: _propTypes.default.func,
|
|
88
|
+
|
|
89
|
+
/** Callback function for when the Select Textbox is focused. */
|
|
90
|
+
onFocus: _propTypes.default.func,
|
|
91
|
+
|
|
92
|
+
/** Callback function for when the key is pressed when focused on Select Text. */
|
|
93
|
+
onKeyDown: _propTypes.default.func,
|
|
94
|
+
|
|
95
|
+
/** Callback function for when the left mouse key is pressed when focused on Select Text. */
|
|
96
|
+
onMouseDown: _propTypes.default.func,
|
|
97
|
+
|
|
98
|
+
/** Placeholder string to be displayed when formattedValue is empty */
|
|
99
|
+
placeholder: _propTypes.default.string,
|
|
100
|
+
|
|
101
|
+
/** If true the Component will be read-only */
|
|
102
|
+
readOnly: _propTypes.default.bool,
|
|
103
|
+
|
|
104
|
+
/** If true the component has no border and a transparent background */
|
|
105
|
+
transparent: _propTypes.default.bool,
|
|
106
|
+
|
|
107
|
+
/** Id of the Select Text element */
|
|
108
|
+
textId: _propTypes.default.string
|
|
109
|
+
};
|
|
110
|
+
var _default = SelectText;
|
|
111
|
+
exports.default = _default;
|
|
@@ -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 = {
|
|
@@ -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 = {
|
|
@@ -76,6 +76,7 @@ const SimpleSelect = /*#__PURE__*/_react.default.forwardRef(({
|
|
|
76
76
|
const filterText = (0, _react.useRef)();
|
|
77
77
|
const [textboxRef, setTextboxRef] = (0, _react.useState)();
|
|
78
78
|
const [isOpen, setOpenState] = (0, _react.useState)(false);
|
|
79
|
+
const [activeDescendantId, setActiveDescendantId] = (0, _react.useState)();
|
|
79
80
|
const [textValue, setTextValue] = (0, _react.useState)("");
|
|
80
81
|
const [selectedValue, setSelectedValue] = (0, _react.useState)(value || defaultValue || "");
|
|
81
82
|
const childOptions = (0, _react.useMemo)(() => _react.default.Children.toArray(children), [children]);
|
|
@@ -113,15 +114,7 @@ const SimpleSelect = /*#__PURE__*/_react.default.forwardRef(({
|
|
|
113
114
|
return match.props.value;
|
|
114
115
|
});
|
|
115
116
|
}, [childOptions, createCustomEvent, onChange]);
|
|
116
|
-
const
|
|
117
|
-
const newValue = event.target.value;
|
|
118
|
-
const newCharacter = newValue.slice(-1);
|
|
119
|
-
const isDeleteEvent = event.nativeEvent.inputType === "deleteContentBackward" || event.nativeEvent.inputType === "deleteContentForward" || event.nativeEvent.inputType === "delete";
|
|
120
|
-
|
|
121
|
-
if (isDeleteEvent) {
|
|
122
|
-
return;
|
|
123
|
-
}
|
|
124
|
-
|
|
117
|
+
const triggerFilterChange = (0, _react.useCallback)(newCharacter => {
|
|
125
118
|
if (isTimerCounting.current) {
|
|
126
119
|
const newVal = filterText.current + newCharacter;
|
|
127
120
|
filterText.current = newVal;
|
|
@@ -161,8 +154,10 @@ const SimpleSelect = /*#__PURE__*/_react.default.forwardRef(({
|
|
|
161
154
|
|
|
162
155
|
return true;
|
|
163
156
|
});
|
|
157
|
+
} else if (key.length === 1) {
|
|
158
|
+
triggerFilterChange(key);
|
|
164
159
|
}
|
|
165
|
-
}, [onKeyDown, onOpen, readOnly]);
|
|
160
|
+
}, [triggerFilterChange, onKeyDown, onOpen, readOnly]);
|
|
166
161
|
const handleGlobalClick = (0, _react.useCallback)(event => {
|
|
167
162
|
const notInContainer = containerRef.current && !containerRef.current.contains(event.target);
|
|
168
163
|
const notInList = listboxRef.current && !listboxRef.current.contains(event.target);
|
|
@@ -170,7 +165,6 @@ const SimpleSelect = /*#__PURE__*/_react.default.forwardRef(({
|
|
|
170
165
|
|
|
171
166
|
if (notInContainer && notInList && !isClickTriggeredBySelect.current) {
|
|
172
167
|
setOpenState(false);
|
|
173
|
-
filterText.current = "";
|
|
174
168
|
}
|
|
175
169
|
|
|
176
170
|
isClickTriggeredBySelect.current = false;
|
|
@@ -283,14 +277,15 @@ const SimpleSelect = /*#__PURE__*/_react.default.forwardRef(({
|
|
|
283
277
|
const {
|
|
284
278
|
text,
|
|
285
279
|
value: newValue,
|
|
286
|
-
selectionType
|
|
280
|
+
selectionType,
|
|
281
|
+
id: selectedOptionId
|
|
287
282
|
} = optionData;
|
|
288
283
|
const isClickTriggered = selectionType === "click";
|
|
289
284
|
updateValue(newValue, text);
|
|
285
|
+
setActiveDescendantId(selectedOptionId);
|
|
290
286
|
|
|
291
287
|
if (selectionType !== "navigationKey") {
|
|
292
288
|
setOpenState(false);
|
|
293
|
-
filterText.current = text;
|
|
294
289
|
}
|
|
295
290
|
|
|
296
291
|
if (isClickTriggered) {
|
|
@@ -312,7 +307,6 @@ const SimpleSelect = /*#__PURE__*/_react.default.forwardRef(({
|
|
|
312
307
|
|
|
313
308
|
function onSelectListClose() {
|
|
314
309
|
setOpenState(false);
|
|
315
|
-
filterText.current = "";
|
|
316
310
|
}
|
|
317
311
|
|
|
318
312
|
function isNavigationKey(key) {
|
|
@@ -341,9 +335,9 @@ const SimpleSelect = /*#__PURE__*/_react.default.forwardRef(({
|
|
|
341
335
|
onMouseDown: handleTextboxMouseDown,
|
|
342
336
|
onFocus: handleTextboxFocus,
|
|
343
337
|
onKeyDown: handleTextboxKeydown,
|
|
344
|
-
onChange: handleTextboxChange,
|
|
345
338
|
onBlur: handleTextboxBlur,
|
|
346
339
|
tooltipPosition,
|
|
340
|
+
transparent,
|
|
347
341
|
...(0, _utils.filterOutStyledSystemSpacingProps)(props)
|
|
348
342
|
};
|
|
349
343
|
}
|
|
@@ -371,16 +365,15 @@ const SimpleSelect = /*#__PURE__*/_react.default.forwardRef(({
|
|
|
371
365
|
transparent: transparent,
|
|
372
366
|
disabled: disabled,
|
|
373
367
|
readOnly: readOnly,
|
|
374
|
-
"aria-expanded": isOpen,
|
|
375
|
-
"aria-haspopup": "listbox",
|
|
376
368
|
ref: containerRef,
|
|
377
369
|
"data-component": dataComponent,
|
|
378
370
|
"data-role": dataRole,
|
|
379
371
|
"data-element": dataElement
|
|
380
372
|
}, (0, _utils.filterStyledSystemMarginProps)(props)), /*#__PURE__*/_react.default.createElement(_selectTextbox.default, _extends({
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
373
|
+
isOpen: isOpen,
|
|
374
|
+
labelId: labelId.current,
|
|
375
|
+
activeDescendantId: activeDescendantId,
|
|
376
|
+
"aria-controls": isOpen ? selectListId.current : undefined
|
|
384
377
|
}, getTextboxProps(), {
|
|
385
378
|
positionedChildren: disablePortal && isOpen && selectList
|
|
386
379
|
})), !disablePortal && isOpen && selectList);
|