@elastic/eui 121.0.0 → 122.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/eui-icons.json +37 -37
- package/es/components/combo_box/combo_box_options_list/combo_box_options_list.js +8 -2
- package/es/components/datagrid/body/cell/data_grid_cell.js +8 -5
- package/es/components/datagrid/body/cell/data_grid_cell.styles.js +1 -1
- package/es/components/datagrid/body/cell/data_grid_cell_wrapper.js +4 -2
- package/es/components/datagrid/body/footer/data_grid_footer_row.js +4 -0
- package/es/components/datagrid/body/header/column_resizer.js +74 -87
- package/es/components/datagrid/body/header/data_grid_control_header_cell.js +2 -1
- package/es/components/datagrid/body/header/data_grid_header_cell.js +1 -0
- package/es/components/datagrid/body/header/data_grid_header_cell_wrapper.js +9 -3
- package/es/components/datagrid/body/header/data_grid_header_cell_wrapper.styles.js +1 -1
- package/es/components/datagrid/controls/keyboard_shortcuts.js +17 -1
- package/es/components/datagrid/data_grid.js +2 -0
- package/es/components/datagrid/utils/copy_focused_cell.js +34 -0
- package/es/components/filter_group/filter_group.a11y.js +1 -1
- package/es/components/form/super_select/super_select.js +247 -351
- package/es/components/list_item_layout/_list_item_layout.js +12 -0
- package/es/components/selectable/selectable_list/selectable_list_item.js +9 -7
- package/eui.d.ts +69 -95
- package/i18ntokens.json +608 -554
- package/lib/components/combo_box/combo_box_options_list/combo_box_options_list.js +8 -2
- package/lib/components/datagrid/body/cell/data_grid_cell.js +8 -5
- package/lib/components/datagrid/body/cell/data_grid_cell.styles.js +1 -1
- package/lib/components/datagrid/body/cell/data_grid_cell_wrapper.js +4 -2
- package/lib/components/datagrid/body/footer/data_grid_footer_row.js +4 -0
- package/lib/components/datagrid/body/header/column_resizer.js +73 -85
- package/lib/components/datagrid/body/header/data_grid_control_header_cell.js +2 -1
- package/lib/components/datagrid/body/header/data_grid_header_cell.js +1 -0
- package/lib/components/datagrid/body/header/data_grid_header_cell_wrapper.js +9 -3
- package/lib/components/datagrid/body/header/data_grid_header_cell_wrapper.styles.js +1 -1
- package/lib/components/datagrid/controls/keyboard_shortcuts.js +17 -1
- package/lib/components/datagrid/data_grid.js +2 -0
- package/lib/components/datagrid/utils/copy_focused_cell.js +39 -0
- package/lib/components/filter_group/filter_group.a11y.js +1 -1
- package/lib/components/form/super_select/super_select.js +253 -355
- package/lib/components/list_item_layout/_list_item_layout.js +12 -0
- package/lib/components/selectable/selectable_list/selectable_list_item.js +9 -7
- package/optimize/es/components/combo_box/combo_box_options_list/combo_box_options_list.js +8 -2
- package/optimize/es/components/datagrid/body/cell/data_grid_cell.js +5 -4
- package/optimize/es/components/datagrid/body/cell/data_grid_cell.styles.js +1 -1
- package/optimize/es/components/datagrid/body/cell/data_grid_cell_wrapper.js +4 -2
- package/optimize/es/components/datagrid/body/footer/data_grid_footer_row.js +4 -0
- package/optimize/es/components/datagrid/body/header/column_resizer.js +69 -81
- package/optimize/es/components/datagrid/body/header/data_grid_control_header_cell.js +2 -1
- package/optimize/es/components/datagrid/body/header/data_grid_header_cell.js +1 -0
- package/optimize/es/components/datagrid/body/header/data_grid_header_cell_wrapper.js +7 -3
- package/optimize/es/components/datagrid/body/header/data_grid_header_cell_wrapper.styles.js +1 -1
- package/optimize/es/components/datagrid/controls/keyboard_shortcuts.js +17 -1
- package/optimize/es/components/datagrid/data_grid.js +2 -0
- package/optimize/es/components/datagrid/utils/copy_focused_cell.js +34 -0
- package/optimize/es/components/filter_group/filter_group.a11y.js +1 -1
- package/optimize/es/components/form/super_select/super_select.js +242 -265
- package/optimize/es/components/selectable/selectable_list/selectable_list_item.js +9 -7
- package/optimize/lib/components/combo_box/combo_box_options_list/combo_box_options_list.js +8 -2
- package/optimize/lib/components/datagrid/body/cell/data_grid_cell.js +5 -4
- package/optimize/lib/components/datagrid/body/cell/data_grid_cell.styles.js +1 -1
- package/optimize/lib/components/datagrid/body/cell/data_grid_cell_wrapper.js +4 -2
- package/optimize/lib/components/datagrid/body/footer/data_grid_footer_row.js +4 -0
- package/optimize/lib/components/datagrid/body/header/column_resizer.js +69 -79
- package/optimize/lib/components/datagrid/body/header/data_grid_control_header_cell.js +2 -1
- package/optimize/lib/components/datagrid/body/header/data_grid_header_cell.js +1 -0
- package/optimize/lib/components/datagrid/body/header/data_grid_header_cell_wrapper.js +7 -3
- package/optimize/lib/components/datagrid/body/header/data_grid_header_cell_wrapper.styles.js +1 -1
- package/optimize/lib/components/datagrid/controls/keyboard_shortcuts.js +17 -1
- package/optimize/lib/components/datagrid/data_grid.js +2 -0
- package/optimize/lib/components/datagrid/utils/copy_focused_cell.js +39 -0
- package/optimize/lib/components/filter_group/filter_group.a11y.js +1 -1
- package/optimize/lib/components/form/super_select/super_select.js +243 -265
- package/optimize/lib/components/selectable/selectable_list/selectable_list_item.js +9 -7
- package/package.json +2 -2
- package/test-env/components/combo_box/combo_box_options_list/combo_box_options_list.js +8 -2
- package/test-env/components/datagrid/body/cell/data_grid_cell.js +8 -5
- package/test-env/components/datagrid/body/cell/data_grid_cell.styles.js +1 -1
- package/test-env/components/datagrid/body/cell/data_grid_cell_wrapper.js +4 -2
- package/test-env/components/datagrid/body/footer/data_grid_footer_row.js +4 -0
- package/test-env/components/datagrid/body/header/column_resizer.js +69 -79
- package/test-env/components/datagrid/body/header/data_grid_control_header_cell.js +2 -1
- package/test-env/components/datagrid/body/header/data_grid_header_cell.js +1 -0
- package/test-env/components/datagrid/body/header/data_grid_header_cell_wrapper.js +9 -3
- package/test-env/components/datagrid/body/header/data_grid_header_cell_wrapper.styles.js +1 -1
- package/test-env/components/datagrid/controls/keyboard_shortcuts.js +17 -1
- package/test-env/components/datagrid/data_grid.js +2 -0
- package/test-env/components/datagrid/utils/copy_focused_cell.js +16 -0
- package/test-env/components/filter_group/filter_group.a11y.js +1 -1
- package/test-env/components/form/super_select/super_select.js +243 -345
- package/test-env/components/list_item_layout/_list_item_layout.js +12 -0
- package/test-env/components/selectable/selectable_list/selectable_list_item.js +9 -7
|
@@ -1,22 +1,14 @@
|
|
|
1
|
-
var _excluded = ["className", "options", "valueOfSelected", "placeholder", "onChange", "isOpen", "isInvalid", "itemClassName", "fullWidth", "popoverProps", "compressed"],
|
|
1
|
+
var _excluded = ["className", "options", "valueOfSelected", "placeholder", "onChange", "onFocus", "onBlur", "isOpen", "isInvalid", "itemClassName", "fullWidth", "popoverProps", "compressed", "isLoading"],
|
|
2
2
|
_excluded2 = ["value", "dropdownDisplay", "inputDisplay", "disabled"];
|
|
3
|
-
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
4
3
|
function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
|
|
4
|
+
function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
|
|
5
|
+
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
6
|
+
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
|
|
7
|
+
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
|
|
8
|
+
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
|
9
|
+
function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
|
|
5
10
|
function _objectWithoutProperties(e, t) { if (null == e) return {}; var o, r, i = _objectWithoutPropertiesLoose(e, t); if (Object.getOwnPropertySymbols) { var n = Object.getOwnPropertySymbols(e); for (r = 0; r < n.length; r++) o = n[r], t.indexOf(o) >= 0 || {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]); } return i; }
|
|
6
11
|
function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (e.indexOf(n) >= 0) continue; t[n] = r[n]; } return t; }
|
|
7
|
-
function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
|
|
8
|
-
function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } }
|
|
9
|
-
function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
|
|
10
|
-
function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
|
|
11
|
-
function _possibleConstructorReturn(t, e) { if (e && ("object" == _typeof(e) || "function" == typeof e)) return e; if (void 0 !== e) throw new TypeError("Derived constructors may only return object or undefined"); return _assertThisInitialized(t); }
|
|
12
|
-
function _assertThisInitialized(e) { if (void 0 === e) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); return e; }
|
|
13
|
-
function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
|
|
14
|
-
function _getPrototypeOf(t) { return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) { return t.__proto__ || Object.getPrototypeOf(t); }, _getPrototypeOf(t); }
|
|
15
|
-
function _inherits(t, e) { if ("function" != typeof e && null !== e) throw new TypeError("Super expression must either be null or a function"); t.prototype = Object.create(e && e.prototype, { constructor: { value: t, writable: !0, configurable: !0 } }), Object.defineProperty(t, "prototype", { writable: !1 }), e && _setPrototypeOf(t, e); }
|
|
16
|
-
function _setPrototypeOf(t, e) { return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) { return t.__proto__ = e, t; }, _setPrototypeOf(t, e); }
|
|
17
|
-
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
|
18
|
-
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
|
|
19
|
-
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
20
12
|
/*
|
|
21
13
|
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
|
22
14
|
* or more contributor license agreements. Licensed under the Elastic License
|
|
@@ -25,10 +17,9 @@ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e
|
|
|
25
17
|
* Side Public License, v 1.
|
|
26
18
|
*/
|
|
27
19
|
|
|
28
|
-
import React, {
|
|
29
|
-
import PropTypes from "prop-types";
|
|
20
|
+
import React, { forwardRef, useCallback, useEffect, useImperativeHandle, useLayoutEffect, useRef, useState } from 'react';
|
|
30
21
|
import classNames from 'classnames';
|
|
31
|
-
import { htmlIdGenerator, keys,
|
|
22
|
+
import { htmlIdGenerator, keys, useEuiMemoizedStyles } from '../../../services';
|
|
32
23
|
import { EuiI18n } from '../../i18n';
|
|
33
24
|
import { EuiScreenReaderOnly } from '../../accessibility';
|
|
34
25
|
import { EuiInputPopover } from '../../popover';
|
|
@@ -40,351 +31,256 @@ var ShiftDirection = /*#__PURE__*/function (ShiftDirection) {
|
|
|
40
31
|
ShiftDirection["BACK"] = "back";
|
|
41
32
|
ShiftDirection["FORWARD"] = "forward";
|
|
42
33
|
return ShiftDirection;
|
|
43
|
-
}(ShiftDirection || {});
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
34
|
+
}(ShiftDirection || {}); // Runs synchronously on the client before paint, so the mount flag is always
|
|
35
|
+
// set before an interaction can schedule the deferred focus in `openPopover`.
|
|
36
|
+
var useMountEffect = typeof document === 'undefined' ? useEffect : useLayoutEffect;
|
|
37
|
+
var EuiSuperSelectInner = function EuiSuperSelectInner(_ref, ref) {
|
|
38
|
+
var _options$currentIndex;
|
|
39
|
+
var className = _ref.className,
|
|
40
|
+
options = _ref.options,
|
|
41
|
+
valueOfSelected = _ref.valueOfSelected,
|
|
42
|
+
placeholder = _ref.placeholder,
|
|
43
|
+
onChange = _ref.onChange,
|
|
44
|
+
onFocus = _ref.onFocus,
|
|
45
|
+
onBlur = _ref.onBlur,
|
|
46
|
+
isOpen = _ref.isOpen,
|
|
47
|
+
_ref$isInvalid = _ref.isInvalid,
|
|
48
|
+
isInvalid = _ref$isInvalid === void 0 ? false : _ref$isInvalid,
|
|
49
|
+
itemClassName = _ref.itemClassName,
|
|
50
|
+
_ref$fullWidth = _ref.fullWidth,
|
|
51
|
+
fullWidth = _ref$fullWidth === void 0 ? false : _ref$fullWidth,
|
|
52
|
+
popoverProps = _ref.popoverProps,
|
|
53
|
+
_ref$compressed = _ref.compressed,
|
|
54
|
+
compressed = _ref$compressed === void 0 ? false : _ref$compressed,
|
|
55
|
+
_ref$isLoading = _ref.isLoading,
|
|
56
|
+
isLoading = _ref$isLoading === void 0 ? false : _ref$isLoading,
|
|
57
|
+
rest = _objectWithoutProperties(_ref, _excluded);
|
|
58
|
+
var styles = useEuiMemoizedStyles(euiSuperSelectStyles);
|
|
59
|
+
var itemNodes = useRef([]);
|
|
60
|
+
var isMounted = useRef(false);
|
|
61
|
+
var controlButtonRef = useRef(null);
|
|
62
|
+
var _useState = useState(function () {
|
|
63
|
+
return htmlIdGenerator('euiSuperSelect_')('_screenreaderDescribeId');
|
|
64
|
+
}),
|
|
65
|
+
_useState2 = _slicedToArray(_useState, 1),
|
|
66
|
+
describedById = _useState2[0];
|
|
67
|
+
var _useState3 = useState(isOpen || false),
|
|
68
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
69
|
+
isPopoverOpen = _useState4[0],
|
|
70
|
+
setIsPopoverOpen = _useState4[1];
|
|
71
|
+
var _useState5 = useState(0),
|
|
72
|
+
_useState6 = _slicedToArray(_useState5, 2),
|
|
73
|
+
currentIndex = _useState6[0],
|
|
74
|
+
setCurrentIndex = _useState6[1];
|
|
75
|
+
var setItemNode = function setItemNode(node, index) {
|
|
76
|
+
itemNodes.current[index] = node;
|
|
77
|
+
};
|
|
78
|
+
var focusItemAt = useCallback(function (index) {
|
|
79
|
+
var _itemNodes$current$in;
|
|
80
|
+
(_itemNodes$current$in = itemNodes.current[index]) === null || _itemNodes$current$in === void 0 || _itemNodes$current$in.focus();
|
|
81
|
+
}, []);
|
|
82
|
+
var openPopover = useCallback(function () {
|
|
83
|
+
var indexOfSelected = options.findIndex(function (option) {
|
|
84
|
+
return (option === null || option === void 0 ? void 0 : option.value) === valueOfSelected;
|
|
62
85
|
});
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
options = _this$props.options,
|
|
66
|
-
valueOfSelected = _this$props.valueOfSelected;
|
|
67
|
-
var indexOfSelected = options.findIndex(function (option) {
|
|
68
|
-
return (option === null || option === void 0 ? void 0 : option.value) === valueOfSelected;
|
|
69
|
-
});
|
|
70
|
-
var candidateIndex = valueOfSelected != null && indexOfSelected >= 0 ? indexOfSelected : 0;
|
|
71
|
-
var initialIndex = candidateIndex;
|
|
86
|
+
var candidateIndex = valueOfSelected != null && indexOfSelected >= 0 ? indexOfSelected : 0;
|
|
87
|
+
var initialIndex = candidateIndex;
|
|
72
88
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
});
|
|
89
|
+
// If the item is disabled, find the first focusable item going forward
|
|
90
|
+
while (initialIndex < options.length && (_options$initialIndex = options[initialIndex]) !== null && _options$initialIndex !== void 0 && _options$initialIndex.disabled) {
|
|
91
|
+
var _options$initialIndex;
|
|
92
|
+
initialIndex++;
|
|
93
|
+
}
|
|
94
|
+
if (initialIndex >= options.length) {
|
|
95
|
+
initialIndex = candidateIndex;
|
|
96
|
+
}
|
|
97
|
+
setIsPopoverOpen(options.length > 0);
|
|
98
|
+
setCurrentIndex(initialIndex);
|
|
99
|
+
requestAnimationFrame(function () {
|
|
85
100
|
requestAnimationFrame(function () {
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
}
|
|
94
|
-
});
|
|
101
|
+
if (!isMounted.current) {
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
focusItemAt(initialIndex);
|
|
105
|
+
if (onFocus) {
|
|
106
|
+
onFocus();
|
|
107
|
+
}
|
|
95
108
|
});
|
|
96
109
|
});
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
});
|
|
110
|
+
}, [options, valueOfSelected, onFocus, focusItemAt]);
|
|
111
|
+
var closePopover = useCallback(function () {
|
|
112
|
+
setIsPopoverOpen(false);
|
|
113
|
+
setCurrentIndex(-1);
|
|
102
114
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
});
|
|
108
|
-
if (_this.props.onBlur) {
|
|
109
|
-
_this.props.onBlur();
|
|
110
|
-
}
|
|
115
|
+
// Refocus back to the toggling control button on popover close
|
|
116
|
+
requestAnimationFrame(function () {
|
|
117
|
+
var _controlButtonRef$cur;
|
|
118
|
+
(_controlButtonRef$cur = controlButtonRef.current) === null || _controlButtonRef$cur === void 0 || _controlButtonRef$cur.focus();
|
|
111
119
|
});
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
120
|
+
if (onBlur) {
|
|
121
|
+
onBlur();
|
|
122
|
+
}
|
|
123
|
+
}, [onBlur]);
|
|
124
|
+
useImperativeHandle(ref, function () {
|
|
125
|
+
return {
|
|
126
|
+
openPopover: openPopover,
|
|
127
|
+
closePopover: closePopover
|
|
128
|
+
};
|
|
129
|
+
}, [openPopover, closePopover]);
|
|
130
|
+
var itemClicked = function itemClicked(value) {
|
|
131
|
+
closePopover();
|
|
132
|
+
if (onChange) {
|
|
133
|
+
onChange(value);
|
|
134
|
+
}
|
|
135
|
+
};
|
|
136
|
+
var onSelectKeyDown = function onSelectKeyDown(event) {
|
|
137
|
+
// Mimic the ways native `<select>`s can be opened via keypress
|
|
138
|
+
if (event.key === keys.ARROW_UP || event.key === keys.ARROW_DOWN || event.key === keys.SPACE) {
|
|
139
|
+
event.preventDefault();
|
|
140
|
+
event.stopPropagation();
|
|
141
|
+
openPopover();
|
|
142
|
+
}
|
|
143
|
+
};
|
|
144
|
+
var onItemKeyDown = function onItemKeyDown(event) {
|
|
145
|
+
switch (event.key) {
|
|
146
|
+
case keys.ESCAPE:
|
|
147
|
+
// close the popover and prevent ancestors from handling
|
|
121
148
|
event.preventDefault();
|
|
122
149
|
event.stopPropagation();
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
event.preventDefault();
|
|
142
|
-
event.stopPropagation();
|
|
143
|
-
_this.shiftFocus(ShiftDirection.BACK);
|
|
144
|
-
break;
|
|
145
|
-
case keys.ARROW_DOWN:
|
|
146
|
-
event.preventDefault();
|
|
147
|
-
event.stopPropagation();
|
|
148
|
-
_this.shiftFocus(ShiftDirection.FORWARD);
|
|
149
|
-
break;
|
|
150
|
-
}
|
|
151
|
-
});
|
|
152
|
-
return _this;
|
|
153
|
-
}
|
|
154
|
-
_inherits(EuiSuperSelect, _Component);
|
|
155
|
-
return _createClass(EuiSuperSelect, [{
|
|
156
|
-
key: "componentDidMount",
|
|
157
|
-
value: function componentDidMount() {
|
|
158
|
-
this._isMounted = true;
|
|
159
|
-
if (this.props.isOpen) {
|
|
160
|
-
this.openPopover();
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
}, {
|
|
164
|
-
key: "componentWillUnmount",
|
|
165
|
-
value: function componentWillUnmount() {
|
|
166
|
-
this._isMounted = false;
|
|
150
|
+
closePopover();
|
|
151
|
+
break;
|
|
152
|
+
case keys.TAB:
|
|
153
|
+
// Mimic native `<select>` behavior, which selects an item on tab press
|
|
154
|
+
event.preventDefault();
|
|
155
|
+
event.stopPropagation();
|
|
156
|
+
event.target.click();
|
|
157
|
+
break;
|
|
158
|
+
case keys.ARROW_UP:
|
|
159
|
+
event.preventDefault();
|
|
160
|
+
event.stopPropagation();
|
|
161
|
+
shiftFocus(ShiftDirection.BACK);
|
|
162
|
+
break;
|
|
163
|
+
case keys.ARROW_DOWN:
|
|
164
|
+
event.preventDefault();
|
|
165
|
+
event.stopPropagation();
|
|
166
|
+
shiftFocus(ShiftDirection.FORWARD);
|
|
167
|
+
break;
|
|
167
168
|
}
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
(
|
|
169
|
+
};
|
|
170
|
+
var shiftFocus = function shiftFocus(direction) {
|
|
171
|
+
if (currentIndex === -1) {
|
|
172
|
+
// somehow the select options has lost focus
|
|
173
|
+
focusItemAt(0);
|
|
174
|
+
setCurrentIndex(0);
|
|
175
|
+
return;
|
|
173
176
|
}
|
|
174
|
-
}, {
|
|
175
|
-
key: "shiftFocus",
|
|
176
|
-
value: function shiftFocus(direction) {
|
|
177
|
-
var options = this.props.options;
|
|
178
|
-
var currentIndex = this.state.currentIndex;
|
|
179
|
-
if (currentIndex === -1) {
|
|
180
|
-
// somehow the select options has lost focus
|
|
181
|
-
this.focusItemAt(0);
|
|
182
|
-
this.setState({
|
|
183
|
-
currentIndex: 0
|
|
184
|
-
});
|
|
185
|
-
return;
|
|
186
|
-
}
|
|
187
177
|
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
});
|
|
199
|
-
return;
|
|
200
|
-
}
|
|
201
|
-
nextIndex += step;
|
|
178
|
+
// Note: this component purposely does not cycle arrow key navigation
|
|
179
|
+
// to match native <select> elements
|
|
180
|
+
var step = direction === ShiftDirection.BACK ? -1 : 1;
|
|
181
|
+
var nextIndex = currentIndex + step;
|
|
182
|
+
while (nextIndex >= 0 && nextIndex < options.length) {
|
|
183
|
+
var _options$nextIndex;
|
|
184
|
+
if (!((_options$nextIndex = options[nextIndex]) !== null && _options$nextIndex !== void 0 && _options$nextIndex.disabled)) {
|
|
185
|
+
focusItemAt(nextIndex);
|
|
186
|
+
setCurrentIndex(nextIndex);
|
|
187
|
+
return;
|
|
202
188
|
}
|
|
189
|
+
nextIndex += step;
|
|
203
190
|
}
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
var _this$props2 = this.props,
|
|
210
|
-
className = _this$props2.className,
|
|
211
|
-
options = _this$props2.options,
|
|
212
|
-
valueOfSelected = _this$props2.valueOfSelected,
|
|
213
|
-
placeholder = _this$props2.placeholder,
|
|
214
|
-
onChange = _this$props2.onChange,
|
|
215
|
-
isOpen = _this$props2.isOpen,
|
|
216
|
-
isInvalid = _this$props2.isInvalid,
|
|
217
|
-
itemClassName = _this$props2.itemClassName,
|
|
218
|
-
fullWidth = _this$props2.fullWidth,
|
|
219
|
-
popoverProps = _this$props2.popoverProps,
|
|
220
|
-
compressed = _this$props2.compressed,
|
|
221
|
-
rest = _objectWithoutProperties(_this$props2, _excluded);
|
|
222
|
-
var popoverClasses = classNames('euiSuperSelect', popoverProps === null || popoverProps === void 0 ? void 0 : popoverProps.className);
|
|
223
|
-
var button = ___EmotionJSX(EuiSuperSelectControl, _extends({
|
|
224
|
-
options: options,
|
|
225
|
-
value: valueOfSelected,
|
|
226
|
-
placeholder: placeholder,
|
|
227
|
-
onClick: this.state.isPopoverOpen ? this.closePopover : this.openPopover,
|
|
228
|
-
onKeyDown: this.onSelectKeyDown,
|
|
229
|
-
className: className,
|
|
230
|
-
fullWidth: fullWidth,
|
|
231
|
-
isInvalid: isInvalid,
|
|
232
|
-
compressed: compressed
|
|
233
|
-
}, rest, {
|
|
234
|
-
buttonRef: this.controlButtonRef,
|
|
235
|
-
isDropdownOpen: this.state.isPopoverOpen
|
|
236
|
-
}));
|
|
237
|
-
var items = options.map(function (option, index) {
|
|
238
|
-
var value = option.value,
|
|
239
|
-
dropdownDisplay = option.dropdownDisplay,
|
|
240
|
-
inputDisplay = option.inputDisplay,
|
|
241
|
-
disabled = option.disabled,
|
|
242
|
-
optionRest = _objectWithoutProperties(option, _excluded2);
|
|
243
|
-
if (value == null) return;
|
|
244
|
-
return ___EmotionJSX(EuiSuperSelectItem, _extends({
|
|
245
|
-
key: index
|
|
246
|
-
/* NOTE: This should rather use "li" to align select-like behavior. But the current
|
|
247
|
-
implementation relies on the interactive and focusable item for the navigation.
|
|
248
|
-
This will require additional refactoring to adjust but we might want to decide first
|
|
249
|
-
if the effort is worth it, considering the unification plans for selection components
|
|
250
|
-
as part of OneSelect (https://github.com/elastic/eui/issues/8808).
|
|
251
|
-
*/,
|
|
252
|
-
element: "button",
|
|
253
|
-
id: String(value),
|
|
254
|
-
className: itemClassName,
|
|
255
|
-
checked: valueOfSelected === value ? 'on' : undefined,
|
|
256
|
-
isSelected: valueOfSelected === value,
|
|
257
|
-
isFocused: _this2.state.currentIndex === index,
|
|
258
|
-
isSingleSelection: true,
|
|
259
|
-
isDisabled: disabled,
|
|
260
|
-
textWrap: "wrap",
|
|
261
|
-
onClick: function onClick() {
|
|
262
|
-
return _this2.itemClicked(value);
|
|
263
|
-
},
|
|
264
|
-
onKeyDown: _this2.onItemKeyDown,
|
|
265
|
-
ref: function ref(node) {
|
|
266
|
-
return _this2.setItemNode(node, index);
|
|
267
|
-
},
|
|
268
|
-
"aria-selected": valueOfSelected === value
|
|
269
|
-
}, optionRest), dropdownDisplay || inputDisplay);
|
|
270
|
-
});
|
|
271
|
-
var ariaActiveDescendant = ((_options$this$state$c = options[this.state.currentIndex]) === null || _options$this$state$c === void 0 ? void 0 : _options$this$state$c.value) != null ? String(options[this.state.currentIndex].value) : undefined;
|
|
272
|
-
return ___EmotionJSX(RenderWithEuiStylesMemoizer, null, function (stylesMemoizer) {
|
|
273
|
-
var styles = stylesMemoizer(euiSuperSelectStyles);
|
|
274
|
-
return ___EmotionJSX(EuiInputPopover, _extends({
|
|
275
|
-
closePopover: _this2.closePopover,
|
|
276
|
-
panelPaddingSize: "none"
|
|
277
|
-
}, popoverProps, {
|
|
278
|
-
className: popoverClasses,
|
|
279
|
-
isOpen: isOpen || _this2.state.isPopoverOpen,
|
|
280
|
-
input: button,
|
|
281
|
-
fullWidth: fullWidth,
|
|
282
|
-
disableFocusTrap: true // This component handles its own focus manually
|
|
283
|
-
}), ___EmotionJSX(EuiScreenReaderOnly, null, ___EmotionJSX("p", {
|
|
284
|
-
id: _this2.describedById
|
|
285
|
-
}, ___EmotionJSX(EuiI18n, {
|
|
286
|
-
token: "euiSuperSelect.screenReaderAnnouncement",
|
|
287
|
-
default: "You are in a form selector and must select a single option. Use the Up and Down arrow keys to navigate or Escape to close."
|
|
288
|
-
}))), ___EmotionJSX(EuiI18n, {
|
|
289
|
-
token: "euiSuperSelect.ariaLabel",
|
|
290
|
-
default: "Select listbox"
|
|
291
|
-
}, function (ariaLabel) {
|
|
292
|
-
return ___EmotionJSX("div", {
|
|
293
|
-
"aria-label": ariaLabel,
|
|
294
|
-
"aria-describedby": _this2.describedById,
|
|
295
|
-
css: styles.euiSuperSelect__listbox,
|
|
296
|
-
className: "euiSuperSelect__listbox eui-scrollBar",
|
|
297
|
-
role: "listbox",
|
|
298
|
-
"aria-activedescendant": ariaActiveDescendant,
|
|
299
|
-
tabIndex: 0
|
|
300
|
-
}, items);
|
|
301
|
-
}));
|
|
302
|
-
});
|
|
191
|
+
};
|
|
192
|
+
useMountEffect(function () {
|
|
193
|
+
isMounted.current = true;
|
|
194
|
+
if (isOpen) {
|
|
195
|
+
openPopover();
|
|
303
196
|
}
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
};
|
|
197
|
+
return function () {
|
|
198
|
+
isMounted.current = false;
|
|
199
|
+
};
|
|
200
|
+
// The class lifecycle this replaces only ran when the component mounted.
|
|
201
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
202
|
+
}, []);
|
|
203
|
+
var popoverClasses = classNames('euiSuperSelect', popoverProps === null || popoverProps === void 0 ? void 0 : popoverProps.className);
|
|
204
|
+
var button = ___EmotionJSX(EuiSuperSelectControl, _extends({
|
|
205
|
+
options: options,
|
|
206
|
+
value: valueOfSelected,
|
|
207
|
+
placeholder: placeholder,
|
|
208
|
+
onClick: isPopoverOpen ? closePopover : openPopover,
|
|
209
|
+
onKeyDown: onSelectKeyDown,
|
|
210
|
+
onFocus: onFocus,
|
|
211
|
+
onBlur: onBlur,
|
|
212
|
+
className: className,
|
|
213
|
+
fullWidth: fullWidth,
|
|
214
|
+
isInvalid: isInvalid,
|
|
215
|
+
compressed: compressed,
|
|
216
|
+
isLoading: isLoading
|
|
217
|
+
}, rest, {
|
|
218
|
+
buttonRef: controlButtonRef,
|
|
219
|
+
isDropdownOpen: isPopoverOpen
|
|
220
|
+
}));
|
|
221
|
+
var items = options.map(function (option, index) {
|
|
222
|
+
var value = option.value,
|
|
223
|
+
dropdownDisplay = option.dropdownDisplay,
|
|
224
|
+
inputDisplay = option.inputDisplay,
|
|
225
|
+
disabled = option.disabled,
|
|
226
|
+
optionRest = _objectWithoutProperties(option, _excluded2);
|
|
227
|
+
if (value == null) return;
|
|
228
|
+
return ___EmotionJSX(EuiSuperSelectItem, _extends({
|
|
229
|
+
key: index
|
|
230
|
+
/* NOTE: This should rather use "li" to align select-like behavior. But the current
|
|
231
|
+
implementation relies on the interactive and focusable item for the navigation.
|
|
232
|
+
This will require additional refactoring to adjust but we might want to decide first
|
|
233
|
+
if the effort is worth it, considering the unification plans for selection components
|
|
234
|
+
as part of OneSelect (https://github.com/elastic/eui/issues/8808).
|
|
235
|
+
*/,
|
|
236
|
+
element: "button",
|
|
237
|
+
id: String(value),
|
|
238
|
+
className: itemClassName,
|
|
239
|
+
checked: valueOfSelected === value ? 'on' : undefined,
|
|
240
|
+
isSelected: valueOfSelected === value,
|
|
241
|
+
isFocused: currentIndex === index,
|
|
242
|
+
isSingleSelection: true,
|
|
243
|
+
isDisabled: disabled,
|
|
244
|
+
textWrap: "wrap",
|
|
245
|
+
onClick: function onClick() {
|
|
246
|
+
return itemClicked(value);
|
|
247
|
+
},
|
|
248
|
+
onKeyDown: onItemKeyDown,
|
|
249
|
+
ref: function ref(node) {
|
|
250
|
+
return setItemNode(node, index);
|
|
251
|
+
},
|
|
252
|
+
"aria-selected": valueOfSelected === value
|
|
253
|
+
}, optionRest), dropdownDisplay || inputDisplay);
|
|
254
|
+
});
|
|
255
|
+
var ariaActiveDescendant = ((_options$currentIndex = options[currentIndex]) === null || _options$currentIndex === void 0 ? void 0 : _options$currentIndex.value) != null ? String(options[currentIndex].value) : undefined;
|
|
256
|
+
return ___EmotionJSX(EuiInputPopover, _extends({
|
|
257
|
+
closePopover: closePopover,
|
|
258
|
+
panelPaddingSize: "none"
|
|
259
|
+
}, popoverProps, {
|
|
260
|
+
className: popoverClasses,
|
|
261
|
+
isOpen: isOpen || isPopoverOpen,
|
|
262
|
+
input: button,
|
|
263
|
+
fullWidth: fullWidth,
|
|
264
|
+
disableFocusTrap: true // This component handles its own focus manually
|
|
265
|
+
}), ___EmotionJSX(EuiScreenReaderOnly, null, ___EmotionJSX("p", {
|
|
266
|
+
id: describedById
|
|
267
|
+
}, ___EmotionJSX(EuiI18n, {
|
|
268
|
+
token: "euiSuperSelect.screenReaderAnnouncement",
|
|
269
|
+
default: "You are in a form selector and must select a single option. Use the Up and Down arrow keys to navigate or Escape to close."
|
|
270
|
+
}))), ___EmotionJSX(EuiI18n, {
|
|
271
|
+
token: "euiSuperSelect.ariaLabel",
|
|
272
|
+
default: "Select listbox"
|
|
273
|
+
}, function (ariaLabel) {
|
|
274
|
+
return ___EmotionJSX("div", {
|
|
275
|
+
"aria-label": ariaLabel,
|
|
276
|
+
"aria-describedby": describedById,
|
|
277
|
+
css: styles.euiSuperSelect__listbox,
|
|
278
|
+
className: "euiSuperSelect__listbox eui-scrollBar",
|
|
279
|
+
role: "listbox",
|
|
280
|
+
"aria-activedescendant": ariaActiveDescendant,
|
|
281
|
+
tabIndex: 0
|
|
282
|
+
}, items);
|
|
283
|
+
}));
|
|
284
|
+
};
|
|
285
|
+
export var EuiSuperSelect = /*#__PURE__*/forwardRef(EuiSuperSelectInner);
|
|
286
|
+
EuiSuperSelect.displayName = 'EuiSuperSelect';
|