@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,11 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
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); }
|
|
3
4
|
Object.defineProperty(exports, "__esModule", {
|
|
4
5
|
value: true
|
|
5
6
|
});
|
|
6
7
|
exports.EuiSuperSelect = void 0;
|
|
7
8
|
var _react = _interopRequireWildcard(require("react"));
|
|
8
|
-
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
9
9
|
var _classnames = _interopRequireDefault(require("classnames"));
|
|
10
10
|
var _services = require("../../../services");
|
|
11
11
|
var _i18n = require("../../i18n");
|
|
@@ -15,383 +15,281 @@ var _super_select_control = require("./super_select_control");
|
|
|
15
15
|
var _super_select_item = require("./super_select_item");
|
|
16
16
|
var _super_select = require("./super_select.styles");
|
|
17
17
|
var _react2 = require("@emotion/react");
|
|
18
|
-
var _excluded = ["className", "options", "valueOfSelected", "placeholder", "onChange", "isOpen", "isInvalid", "itemClassName", "fullWidth", "popoverProps", "compressed"],
|
|
18
|
+
var _excluded = ["className", "options", "valueOfSelected", "placeholder", "onChange", "onFocus", "onBlur", "isOpen", "isInvalid", "itemClassName", "fullWidth", "popoverProps", "compressed", "isLoading"],
|
|
19
19
|
_excluded2 = ["value", "dropdownDisplay", "inputDisplay", "disabled"];
|
|
20
|
-
|
|
21
|
-
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
|
|
22
|
-
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
23
|
-
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); }
|
|
24
|
-
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); }
|
|
25
|
-
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; }
|
|
26
|
-
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; }
|
|
27
|
-
function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
|
|
28
|
-
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); } }
|
|
29
|
-
function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
|
|
30
|
-
function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
|
|
31
|
-
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); }
|
|
32
|
-
function _assertThisInitialized(e) { if (void 0 === e) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); return e; }
|
|
33
|
-
function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
|
|
34
|
-
function _getPrototypeOf(t) { return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) { return t.__proto__ || Object.getPrototypeOf(t); }, _getPrototypeOf(t); }
|
|
35
|
-
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); }
|
|
36
|
-
function _setPrototypeOf(t, e) { return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) { return t.__proto__ = e, t; }, _setPrototypeOf(t, e); }
|
|
37
|
-
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; }
|
|
38
|
-
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
|
|
39
|
-
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
|
+
/*
|
|
40
21
|
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
|
41
22
|
* or more contributor license agreements. Licensed under the Elastic License
|
|
42
23
|
* 2.0 and the Server Side Public License, v 1; you may not use this file except
|
|
43
24
|
* in compliance with, at your election, the Elastic License 2.0 or the Server
|
|
44
25
|
* Side Public License, v 1.
|
|
45
26
|
*/
|
|
27
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
28
|
+
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
|
|
29
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
30
|
+
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); }
|
|
31
|
+
function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
|
|
32
|
+
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."); }
|
|
33
|
+
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; } }
|
|
34
|
+
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; }
|
|
35
|
+
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; } }
|
|
36
|
+
function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
|
|
37
|
+
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; }
|
|
38
|
+
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; }
|
|
46
39
|
var ShiftDirection = /*#__PURE__*/function (ShiftDirection) {
|
|
47
40
|
ShiftDirection["BACK"] = "back";
|
|
48
41
|
ShiftDirection["FORWARD"] = "forward";
|
|
49
42
|
return ShiftDirection;
|
|
50
|
-
}(ShiftDirection || {});
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
43
|
+
}(ShiftDirection || {}); // Runs synchronously on the client before paint, so the mount flag is always
|
|
44
|
+
// set before an interaction can schedule the deferred focus in `openPopover`.
|
|
45
|
+
var useMountEffect = typeof document === 'undefined' ? _react.useEffect : _react.useLayoutEffect;
|
|
46
|
+
var EuiSuperSelectInner = function EuiSuperSelectInner(_ref, ref) {
|
|
47
|
+
var _options$currentIndex;
|
|
48
|
+
var className = _ref.className,
|
|
49
|
+
options = _ref.options,
|
|
50
|
+
valueOfSelected = _ref.valueOfSelected,
|
|
51
|
+
placeholder = _ref.placeholder,
|
|
52
|
+
onChange = _ref.onChange,
|
|
53
|
+
onFocus = _ref.onFocus,
|
|
54
|
+
onBlur = _ref.onBlur,
|
|
55
|
+
isOpen = _ref.isOpen,
|
|
56
|
+
_ref$isInvalid = _ref.isInvalid,
|
|
57
|
+
isInvalid = _ref$isInvalid === void 0 ? false : _ref$isInvalid,
|
|
58
|
+
itemClassName = _ref.itemClassName,
|
|
59
|
+
_ref$fullWidth = _ref.fullWidth,
|
|
60
|
+
fullWidth = _ref$fullWidth === void 0 ? false : _ref$fullWidth,
|
|
61
|
+
popoverProps = _ref.popoverProps,
|
|
62
|
+
_ref$compressed = _ref.compressed,
|
|
63
|
+
compressed = _ref$compressed === void 0 ? false : _ref$compressed,
|
|
64
|
+
_ref$isLoading = _ref.isLoading,
|
|
65
|
+
isLoading = _ref$isLoading === void 0 ? false : _ref$isLoading,
|
|
66
|
+
rest = _objectWithoutProperties(_ref, _excluded);
|
|
67
|
+
var styles = (0, _services.useEuiMemoizedStyles)(_super_select.euiSuperSelectStyles);
|
|
68
|
+
var itemNodes = (0, _react.useRef)([]);
|
|
69
|
+
var isMounted = (0, _react.useRef)(false);
|
|
70
|
+
var controlButtonRef = (0, _react.useRef)(null);
|
|
71
|
+
var _useState = (0, _react.useState)(function () {
|
|
72
|
+
return (0, _services.htmlIdGenerator)('euiSuperSelect_')('_screenreaderDescribeId');
|
|
73
|
+
}),
|
|
74
|
+
_useState2 = _slicedToArray(_useState, 1),
|
|
75
|
+
describedById = _useState2[0];
|
|
76
|
+
var _useState3 = (0, _react.useState)(isOpen || false),
|
|
77
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
78
|
+
isPopoverOpen = _useState4[0],
|
|
79
|
+
setIsPopoverOpen = _useState4[1];
|
|
80
|
+
var _useState5 = (0, _react.useState)(0),
|
|
81
|
+
_useState6 = _slicedToArray(_useState5, 2),
|
|
82
|
+
currentIndex = _useState6[0],
|
|
83
|
+
setCurrentIndex = _useState6[1];
|
|
84
|
+
var setItemNode = function setItemNode(node, index) {
|
|
85
|
+
itemNodes.current[index] = node;
|
|
86
|
+
};
|
|
87
|
+
var focusItemAt = (0, _react.useCallback)(function (index) {
|
|
88
|
+
var _itemNodes$current$in;
|
|
89
|
+
(_itemNodes$current$in = itemNodes.current[index]) === null || _itemNodes$current$in === void 0 || _itemNodes$current$in.focus();
|
|
90
|
+
}, []);
|
|
91
|
+
var openPopover = (0, _react.useCallback)(function () {
|
|
92
|
+
var indexOfSelected = options.findIndex(function (option) {
|
|
93
|
+
return (option === null || option === void 0 ? void 0 : option.value) === valueOfSelected;
|
|
69
94
|
});
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
options = _this$props.options,
|
|
73
|
-
valueOfSelected = _this$props.valueOfSelected;
|
|
74
|
-
var indexOfSelected = options.findIndex(function (option) {
|
|
75
|
-
return (option === null || option === void 0 ? void 0 : option.value) === valueOfSelected;
|
|
76
|
-
});
|
|
77
|
-
var candidateIndex = valueOfSelected != null && indexOfSelected >= 0 ? indexOfSelected : 0;
|
|
78
|
-
var initialIndex = candidateIndex;
|
|
95
|
+
var candidateIndex = valueOfSelected != null && indexOfSelected >= 0 ? indexOfSelected : 0;
|
|
96
|
+
var initialIndex = candidateIndex;
|
|
79
97
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
});
|
|
98
|
+
// If the item is disabled, find the first focusable item going forward
|
|
99
|
+
while (initialIndex < options.length && (_options$initialIndex = options[initialIndex]) !== null && _options$initialIndex !== void 0 && _options$initialIndex.disabled) {
|
|
100
|
+
var _options$initialIndex;
|
|
101
|
+
initialIndex++;
|
|
102
|
+
}
|
|
103
|
+
if (initialIndex >= options.length) {
|
|
104
|
+
initialIndex = candidateIndex;
|
|
105
|
+
}
|
|
106
|
+
setIsPopoverOpen(options.length > 0);
|
|
107
|
+
setCurrentIndex(initialIndex);
|
|
108
|
+
requestAnimationFrame(function () {
|
|
92
109
|
requestAnimationFrame(function () {
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
}
|
|
101
|
-
});
|
|
110
|
+
if (!isMounted.current) {
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
focusItemAt(initialIndex);
|
|
114
|
+
if (onFocus) {
|
|
115
|
+
onFocus();
|
|
116
|
+
}
|
|
102
117
|
});
|
|
103
118
|
});
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
});
|
|
119
|
+
}, [options, valueOfSelected, onFocus, focusItemAt]);
|
|
120
|
+
var closePopover = (0, _react.useCallback)(function () {
|
|
121
|
+
setIsPopoverOpen(false);
|
|
122
|
+
setCurrentIndex(-1);
|
|
109
123
|
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
});
|
|
115
|
-
if (_this.props.onBlur) {
|
|
116
|
-
_this.props.onBlur();
|
|
117
|
-
}
|
|
118
|
-
});
|
|
119
|
-
_defineProperty(_this, "itemClicked", function (value) {
|
|
120
|
-
_this.closePopover();
|
|
121
|
-
if (_this.props.onChange) {
|
|
122
|
-
_this.props.onChange(value);
|
|
123
|
-
}
|
|
124
|
+
// Refocus back to the toggling control button on popover close
|
|
125
|
+
requestAnimationFrame(function () {
|
|
126
|
+
var _controlButtonRef$cur;
|
|
127
|
+
(_controlButtonRef$cur = controlButtonRef.current) === null || _controlButtonRef$cur === void 0 || _controlButtonRef$cur.focus();
|
|
124
128
|
});
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
129
|
+
if (onBlur) {
|
|
130
|
+
onBlur();
|
|
131
|
+
}
|
|
132
|
+
}, [onBlur]);
|
|
133
|
+
(0, _react.useImperativeHandle)(ref, function () {
|
|
134
|
+
return {
|
|
135
|
+
openPopover: openPopover,
|
|
136
|
+
closePopover: closePopover
|
|
137
|
+
};
|
|
138
|
+
}, [openPopover, closePopover]);
|
|
139
|
+
var itemClicked = function itemClicked(value) {
|
|
140
|
+
closePopover();
|
|
141
|
+
if (onChange) {
|
|
142
|
+
onChange(value);
|
|
143
|
+
}
|
|
144
|
+
};
|
|
145
|
+
var onSelectKeyDown = function onSelectKeyDown(event) {
|
|
146
|
+
// Mimic the ways native `<select>`s can be opened via keypress
|
|
147
|
+
if (event.key === _services.keys.ARROW_UP || event.key === _services.keys.ARROW_DOWN || event.key === _services.keys.SPACE) {
|
|
148
|
+
event.preventDefault();
|
|
149
|
+
event.stopPropagation();
|
|
150
|
+
openPopover();
|
|
151
|
+
}
|
|
152
|
+
};
|
|
153
|
+
var onItemKeyDown = function onItemKeyDown(event) {
|
|
154
|
+
switch (event.key) {
|
|
155
|
+
case _services.keys.ESCAPE:
|
|
156
|
+
// close the popover and prevent ancestors from handling
|
|
128
157
|
event.preventDefault();
|
|
129
158
|
event.stopPropagation();
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
event.preventDefault();
|
|
149
|
-
event.stopPropagation();
|
|
150
|
-
_this.shiftFocus(ShiftDirection.BACK);
|
|
151
|
-
break;
|
|
152
|
-
case _services.keys.ARROW_DOWN:
|
|
153
|
-
event.preventDefault();
|
|
154
|
-
event.stopPropagation();
|
|
155
|
-
_this.shiftFocus(ShiftDirection.FORWARD);
|
|
156
|
-
break;
|
|
157
|
-
}
|
|
158
|
-
});
|
|
159
|
-
return _this;
|
|
160
|
-
}
|
|
161
|
-
_inherits(EuiSuperSelect, _Component);
|
|
162
|
-
return _createClass(EuiSuperSelect, [{
|
|
163
|
-
key: "componentDidMount",
|
|
164
|
-
value: function componentDidMount() {
|
|
165
|
-
this._isMounted = true;
|
|
166
|
-
if (this.props.isOpen) {
|
|
167
|
-
this.openPopover();
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
}, {
|
|
171
|
-
key: "componentWillUnmount",
|
|
172
|
-
value: function componentWillUnmount() {
|
|
173
|
-
this._isMounted = false;
|
|
159
|
+
closePopover();
|
|
160
|
+
break;
|
|
161
|
+
case _services.keys.TAB:
|
|
162
|
+
// Mimic native `<select>` behavior, which selects an item on tab press
|
|
163
|
+
event.preventDefault();
|
|
164
|
+
event.stopPropagation();
|
|
165
|
+
event.target.click();
|
|
166
|
+
break;
|
|
167
|
+
case _services.keys.ARROW_UP:
|
|
168
|
+
event.preventDefault();
|
|
169
|
+
event.stopPropagation();
|
|
170
|
+
shiftFocus(ShiftDirection.BACK);
|
|
171
|
+
break;
|
|
172
|
+
case _services.keys.ARROW_DOWN:
|
|
173
|
+
event.preventDefault();
|
|
174
|
+
event.stopPropagation();
|
|
175
|
+
shiftFocus(ShiftDirection.FORWARD);
|
|
176
|
+
break;
|
|
174
177
|
}
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
(
|
|
178
|
+
};
|
|
179
|
+
var shiftFocus = function shiftFocus(direction) {
|
|
180
|
+
if (currentIndex === -1) {
|
|
181
|
+
// somehow the select options has lost focus
|
|
182
|
+
focusItemAt(0);
|
|
183
|
+
setCurrentIndex(0);
|
|
184
|
+
return;
|
|
180
185
|
}
|
|
181
|
-
}, {
|
|
182
|
-
key: "shiftFocus",
|
|
183
|
-
value: function shiftFocus(direction) {
|
|
184
|
-
var options = this.props.options;
|
|
185
|
-
var currentIndex = this.state.currentIndex;
|
|
186
|
-
if (currentIndex === -1) {
|
|
187
|
-
// somehow the select options has lost focus
|
|
188
|
-
this.focusItemAt(0);
|
|
189
|
-
this.setState({
|
|
190
|
-
currentIndex: 0
|
|
191
|
-
});
|
|
192
|
-
return;
|
|
193
|
-
}
|
|
194
186
|
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
});
|
|
206
|
-
return;
|
|
207
|
-
}
|
|
208
|
-
nextIndex += step;
|
|
187
|
+
// Note: this component purposely does not cycle arrow key navigation
|
|
188
|
+
// to match native <select> elements
|
|
189
|
+
var step = direction === ShiftDirection.BACK ? -1 : 1;
|
|
190
|
+
var nextIndex = currentIndex + step;
|
|
191
|
+
while (nextIndex >= 0 && nextIndex < options.length) {
|
|
192
|
+
var _options$nextIndex;
|
|
193
|
+
if (!((_options$nextIndex = options[nextIndex]) !== null && _options$nextIndex !== void 0 && _options$nextIndex.disabled)) {
|
|
194
|
+
focusItemAt(nextIndex);
|
|
195
|
+
setCurrentIndex(nextIndex);
|
|
196
|
+
return;
|
|
209
197
|
}
|
|
198
|
+
nextIndex += step;
|
|
210
199
|
}
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
var _this$props2 = this.props,
|
|
217
|
-
className = _this$props2.className,
|
|
218
|
-
options = _this$props2.options,
|
|
219
|
-
valueOfSelected = _this$props2.valueOfSelected,
|
|
220
|
-
placeholder = _this$props2.placeholder,
|
|
221
|
-
onChange = _this$props2.onChange,
|
|
222
|
-
isOpen = _this$props2.isOpen,
|
|
223
|
-
isInvalid = _this$props2.isInvalid,
|
|
224
|
-
itemClassName = _this$props2.itemClassName,
|
|
225
|
-
fullWidth = _this$props2.fullWidth,
|
|
226
|
-
popoverProps = _this$props2.popoverProps,
|
|
227
|
-
compressed = _this$props2.compressed,
|
|
228
|
-
rest = _objectWithoutProperties(_this$props2, _excluded);
|
|
229
|
-
var popoverClasses = (0, _classnames.default)('euiSuperSelect', popoverProps === null || popoverProps === void 0 ? void 0 : popoverProps.className);
|
|
230
|
-
var button = (0, _react2.jsx)(_super_select_control.EuiSuperSelectControl, _extends({
|
|
231
|
-
options: options,
|
|
232
|
-
value: valueOfSelected,
|
|
233
|
-
placeholder: placeholder,
|
|
234
|
-
onClick: this.state.isPopoverOpen ? this.closePopover : this.openPopover,
|
|
235
|
-
onKeyDown: this.onSelectKeyDown,
|
|
236
|
-
className: className,
|
|
237
|
-
fullWidth: fullWidth,
|
|
238
|
-
isInvalid: isInvalid,
|
|
239
|
-
compressed: compressed
|
|
240
|
-
}, rest, {
|
|
241
|
-
buttonRef: this.controlButtonRef,
|
|
242
|
-
isDropdownOpen: this.state.isPopoverOpen
|
|
243
|
-
}));
|
|
244
|
-
var items = options.map(function (option, index) {
|
|
245
|
-
var value = option.value,
|
|
246
|
-
dropdownDisplay = option.dropdownDisplay,
|
|
247
|
-
inputDisplay = option.inputDisplay,
|
|
248
|
-
disabled = option.disabled,
|
|
249
|
-
optionRest = _objectWithoutProperties(option, _excluded2);
|
|
250
|
-
if (value == null) return;
|
|
251
|
-
return (0, _react2.jsx)(_super_select_item.EuiSuperSelectItem, _extends({
|
|
252
|
-
key: index
|
|
253
|
-
/* NOTE: This should rather use "li" to align select-like behavior. But the current
|
|
254
|
-
implementation relies on the interactive and focusable item for the navigation.
|
|
255
|
-
This will require additional refactoring to adjust but we might want to decide first
|
|
256
|
-
if the effort is worth it, considering the unification plans for selection components
|
|
257
|
-
as part of OneSelect (https://github.com/elastic/eui/issues/8808).
|
|
258
|
-
*/,
|
|
259
|
-
element: "button",
|
|
260
|
-
id: String(value),
|
|
261
|
-
className: itemClassName,
|
|
262
|
-
checked: valueOfSelected === value ? 'on' : undefined,
|
|
263
|
-
isSelected: valueOfSelected === value,
|
|
264
|
-
isFocused: _this2.state.currentIndex === index,
|
|
265
|
-
isSingleSelection: true,
|
|
266
|
-
isDisabled: disabled,
|
|
267
|
-
textWrap: "wrap",
|
|
268
|
-
onClick: function onClick() {
|
|
269
|
-
return _this2.itemClicked(value);
|
|
270
|
-
},
|
|
271
|
-
onKeyDown: _this2.onItemKeyDown,
|
|
272
|
-
ref: function ref(node) {
|
|
273
|
-
return _this2.setItemNode(node, index);
|
|
274
|
-
},
|
|
275
|
-
"aria-selected": valueOfSelected === value
|
|
276
|
-
}, optionRest), dropdownDisplay || inputDisplay);
|
|
277
|
-
});
|
|
278
|
-
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;
|
|
279
|
-
return (0, _react2.jsx)(_services.RenderWithEuiStylesMemoizer, null, function (stylesMemoizer) {
|
|
280
|
-
var styles = stylesMemoizer(_super_select.euiSuperSelectStyles);
|
|
281
|
-
return (0, _react2.jsx)(_popover.EuiInputPopover, _extends({
|
|
282
|
-
closePopover: _this2.closePopover,
|
|
283
|
-
panelPaddingSize: "none"
|
|
284
|
-
}, popoverProps, {
|
|
285
|
-
className: popoverClasses,
|
|
286
|
-
isOpen: isOpen || _this2.state.isPopoverOpen,
|
|
287
|
-
input: button,
|
|
288
|
-
fullWidth: fullWidth,
|
|
289
|
-
disableFocusTrap: true // This component handles its own focus manually
|
|
290
|
-
}), (0, _react2.jsx)(_accessibility.EuiScreenReaderOnly, null, (0, _react2.jsx)("p", {
|
|
291
|
-
id: _this2.describedById
|
|
292
|
-
}, (0, _react2.jsx)(_i18n.EuiI18n, {
|
|
293
|
-
token: "euiSuperSelect.screenReaderAnnouncement",
|
|
294
|
-
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."
|
|
295
|
-
}))), (0, _react2.jsx)(_i18n.EuiI18n, {
|
|
296
|
-
token: "euiSuperSelect.ariaLabel",
|
|
297
|
-
default: "Select listbox"
|
|
298
|
-
}, function (ariaLabel) {
|
|
299
|
-
return (0, _react2.jsx)("div", {
|
|
300
|
-
"aria-label": ariaLabel,
|
|
301
|
-
"aria-describedby": _this2.describedById,
|
|
302
|
-
css: styles.euiSuperSelect__listbox,
|
|
303
|
-
className: "euiSuperSelect__listbox eui-scrollBar",
|
|
304
|
-
role: "listbox",
|
|
305
|
-
"aria-activedescendant": ariaActiveDescendant,
|
|
306
|
-
tabIndex: 0
|
|
307
|
-
}, items);
|
|
308
|
-
}));
|
|
309
|
-
});
|
|
200
|
+
};
|
|
201
|
+
useMountEffect(function () {
|
|
202
|
+
isMounted.current = true;
|
|
203
|
+
if (isOpen) {
|
|
204
|
+
openPopover();
|
|
310
205
|
}
|
|
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
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
};
|
|
206
|
+
return function () {
|
|
207
|
+
isMounted.current = false;
|
|
208
|
+
};
|
|
209
|
+
// The class lifecycle this replaces only ran when the component mounted.
|
|
210
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
211
|
+
}, []);
|
|
212
|
+
var popoverClasses = (0, _classnames.default)('euiSuperSelect', popoverProps === null || popoverProps === void 0 ? void 0 : popoverProps.className);
|
|
213
|
+
var button = (0, _react2.jsx)(_super_select_control.EuiSuperSelectControl, _extends({
|
|
214
|
+
options: options,
|
|
215
|
+
value: valueOfSelected,
|
|
216
|
+
placeholder: placeholder,
|
|
217
|
+
onClick: isPopoverOpen ? closePopover : openPopover,
|
|
218
|
+
onKeyDown: onSelectKeyDown,
|
|
219
|
+
onFocus: onFocus,
|
|
220
|
+
onBlur: onBlur,
|
|
221
|
+
className: className,
|
|
222
|
+
fullWidth: fullWidth,
|
|
223
|
+
isInvalid: isInvalid,
|
|
224
|
+
compressed: compressed,
|
|
225
|
+
isLoading: isLoading
|
|
226
|
+
}, rest, {
|
|
227
|
+
buttonRef: controlButtonRef,
|
|
228
|
+
isDropdownOpen: isPopoverOpen
|
|
229
|
+
}));
|
|
230
|
+
var items = options.map(function (option, index) {
|
|
231
|
+
var value = option.value,
|
|
232
|
+
dropdownDisplay = option.dropdownDisplay,
|
|
233
|
+
inputDisplay = option.inputDisplay,
|
|
234
|
+
disabled = option.disabled,
|
|
235
|
+
optionRest = _objectWithoutProperties(option, _excluded2);
|
|
236
|
+
if (value == null) return;
|
|
237
|
+
return (0, _react2.jsx)(_super_select_item.EuiSuperSelectItem, _extends({
|
|
238
|
+
key: index
|
|
239
|
+
/* NOTE: This should rather use "li" to align select-like behavior. But the current
|
|
240
|
+
implementation relies on the interactive and focusable item for the navigation.
|
|
241
|
+
This will require additional refactoring to adjust but we might want to decide first
|
|
242
|
+
if the effort is worth it, considering the unification plans for selection components
|
|
243
|
+
as part of OneSelect (https://github.com/elastic/eui/issues/8808).
|
|
244
|
+
*/,
|
|
245
|
+
element: "button",
|
|
246
|
+
id: String(value),
|
|
247
|
+
className: itemClassName,
|
|
248
|
+
checked: valueOfSelected === value ? 'on' : undefined,
|
|
249
|
+
isSelected: valueOfSelected === value,
|
|
250
|
+
isFocused: currentIndex === index,
|
|
251
|
+
isSingleSelection: true,
|
|
252
|
+
isDisabled: disabled,
|
|
253
|
+
textWrap: "wrap",
|
|
254
|
+
onClick: function onClick() {
|
|
255
|
+
return itemClicked(value);
|
|
256
|
+
},
|
|
257
|
+
onKeyDown: onItemKeyDown,
|
|
258
|
+
ref: function ref(node) {
|
|
259
|
+
return setItemNode(node, index);
|
|
260
|
+
},
|
|
261
|
+
"aria-selected": valueOfSelected === value
|
|
262
|
+
}, optionRest), dropdownDisplay || inputDisplay);
|
|
263
|
+
});
|
|
264
|
+
var ariaActiveDescendant = ((_options$currentIndex = options[currentIndex]) === null || _options$currentIndex === void 0 ? void 0 : _options$currentIndex.value) != null ? String(options[currentIndex].value) : undefined;
|
|
265
|
+
return (0, _react2.jsx)(_popover.EuiInputPopover, _extends({
|
|
266
|
+
closePopover: closePopover,
|
|
267
|
+
panelPaddingSize: "none"
|
|
268
|
+
}, popoverProps, {
|
|
269
|
+
className: popoverClasses,
|
|
270
|
+
isOpen: isOpen || isPopoverOpen,
|
|
271
|
+
input: button,
|
|
272
|
+
fullWidth: fullWidth,
|
|
273
|
+
disableFocusTrap: true // This component handles its own focus manually
|
|
274
|
+
}), (0, _react2.jsx)(_accessibility.EuiScreenReaderOnly, null, (0, _react2.jsx)("p", {
|
|
275
|
+
id: describedById
|
|
276
|
+
}, (0, _react2.jsx)(_i18n.EuiI18n, {
|
|
277
|
+
token: "euiSuperSelect.screenReaderAnnouncement",
|
|
278
|
+
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."
|
|
279
|
+
}))), (0, _react2.jsx)(_i18n.EuiI18n, {
|
|
280
|
+
token: "euiSuperSelect.ariaLabel",
|
|
281
|
+
default: "Select listbox"
|
|
282
|
+
}, function (ariaLabel) {
|
|
283
|
+
return (0, _react2.jsx)("div", {
|
|
284
|
+
"aria-label": ariaLabel,
|
|
285
|
+
"aria-describedby": describedById,
|
|
286
|
+
css: styles.euiSuperSelect__listbox,
|
|
287
|
+
className: "euiSuperSelect__listbox eui-scrollBar",
|
|
288
|
+
role: "listbox",
|
|
289
|
+
"aria-activedescendant": ariaActiveDescendant,
|
|
290
|
+
tabIndex: 0
|
|
291
|
+
}, items);
|
|
292
|
+
}));
|
|
293
|
+
};
|
|
294
|
+
var EuiSuperSelect = exports.EuiSuperSelect = /*#__PURE__*/(0, _react.forwardRef)(EuiSuperSelectInner);
|
|
295
|
+
EuiSuperSelect.displayName = 'EuiSuperSelect';
|