@elastic/eui 121.0.0-snapshot.1788869799640 → 121.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 +10 -10
- package/es/components/datagrid/body/cell/data_grid_cell.js +5 -8
- package/es/components/datagrid/body/cell/data_grid_cell.styles.js +1 -1
- package/es/components/datagrid/body/cell/data_grid_cell_wrapper.js +2 -4
- package/es/components/datagrid/body/footer/data_grid_footer_row.js +0 -4
- package/es/components/datagrid/body/header/column_resizer.js +87 -74
- package/es/components/datagrid/body/header/data_grid_control_header_cell.js +1 -2
- package/es/components/datagrid/body/header/data_grid_header_cell.js +0 -1
- package/es/components/datagrid/body/header/data_grid_header_cell_wrapper.js +3 -9
- package/es/components/datagrid/body/header/data_grid_header_cell_wrapper.styles.js +1 -1
- package/es/components/datagrid/controls/keyboard_shortcuts.js +1 -17
- package/es/components/datagrid/data_grid.js +0 -2
- package/es/components/form/super_select/super_select.js +351 -247
- package/eui.d.ts +55 -30
- package/i18ntokens.json +205 -277
- package/lib/components/datagrid/body/cell/data_grid_cell.js +5 -8
- package/lib/components/datagrid/body/cell/data_grid_cell.styles.js +1 -1
- package/lib/components/datagrid/body/cell/data_grid_cell_wrapper.js +2 -4
- package/lib/components/datagrid/body/footer/data_grid_footer_row.js +0 -4
- package/lib/components/datagrid/body/header/column_resizer.js +85 -73
- package/lib/components/datagrid/body/header/data_grid_control_header_cell.js +1 -2
- package/lib/components/datagrid/body/header/data_grid_header_cell.js +0 -1
- package/lib/components/datagrid/body/header/data_grid_header_cell_wrapper.js +3 -9
- package/lib/components/datagrid/body/header/data_grid_header_cell_wrapper.styles.js +1 -1
- package/lib/components/datagrid/controls/keyboard_shortcuts.js +1 -17
- package/lib/components/datagrid/data_grid.js +0 -2
- package/lib/components/form/super_select/super_select.js +355 -253
- package/optimize/es/components/datagrid/body/cell/data_grid_cell.js +4 -5
- 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 +2 -4
- package/optimize/es/components/datagrid/body/footer/data_grid_footer_row.js +0 -4
- package/optimize/es/components/datagrid/body/header/column_resizer.js +81 -69
- package/optimize/es/components/datagrid/body/header/data_grid_control_header_cell.js +1 -2
- package/optimize/es/components/datagrid/body/header/data_grid_header_cell.js +0 -1
- package/optimize/es/components/datagrid/body/header/data_grid_header_cell_wrapper.js +3 -7
- 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 +1 -17
- package/optimize/es/components/datagrid/data_grid.js +0 -2
- package/optimize/es/components/form/super_select/super_select.js +265 -242
- package/optimize/lib/components/datagrid/body/cell/data_grid_cell.js +4 -5
- 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 +2 -4
- package/optimize/lib/components/datagrid/body/footer/data_grid_footer_row.js +0 -4
- package/optimize/lib/components/datagrid/body/header/column_resizer.js +79 -69
- package/optimize/lib/components/datagrid/body/header/data_grid_control_header_cell.js +1 -2
- package/optimize/lib/components/datagrid/body/header/data_grid_header_cell.js +0 -1
- package/optimize/lib/components/datagrid/body/header/data_grid_header_cell_wrapper.js +3 -7
- 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 +1 -17
- package/optimize/lib/components/datagrid/data_grid.js +0 -2
- package/optimize/lib/components/form/super_select/super_select.js +265 -243
- package/package.json +7 -8
- package/test-env/components/datagrid/body/cell/data_grid_cell.js +5 -8
- 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 +2 -4
- package/test-env/components/datagrid/body/footer/data_grid_footer_row.js +0 -4
- package/test-env/components/datagrid/body/header/column_resizer.js +79 -69
- package/test-env/components/datagrid/body/header/data_grid_control_header_cell.js +1 -2
- package/test-env/components/datagrid/body/header/data_grid_header_cell.js +0 -1
- package/test-env/components/datagrid/body/header/data_grid_header_cell_wrapper.js +3 -9
- 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 +1 -17
- package/test-env/components/datagrid/data_grid.js +0 -2
- package/test-env/components/form/super_select/super_select.js +345 -243
- package/es/components/datagrid/utils/copy_focused_cell.js +0 -34
- package/lib/components/datagrid/utils/copy_focused_cell.js +0 -39
- package/optimize/es/components/datagrid/utils/copy_focused_cell.js +0 -34
- package/optimize/lib/components/datagrid/utils/copy_focused_cell.js +0 -39
- package/test-env/components/datagrid/utils/copy_focused_cell.js +0 -16
|
@@ -1,14 +1,22 @@
|
|
|
1
|
-
var _excluded = ["className", "options", "valueOfSelected", "placeholder", "onChange", "
|
|
1
|
+
var _excluded = ["className", "options", "valueOfSelected", "placeholder", "onChange", "isOpen", "isInvalid", "itemClassName", "fullWidth", "popoverProps", "compressed"],
|
|
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); }
|
|
3
4
|
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; }
|
|
10
5
|
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; }
|
|
11
6
|
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); }
|
|
12
20
|
/*
|
|
13
21
|
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
|
14
22
|
* or more contributor license agreements. Licensed under the Elastic License
|
|
@@ -17,9 +25,10 @@ function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t =
|
|
|
17
25
|
* Side Public License, v 1.
|
|
18
26
|
*/
|
|
19
27
|
|
|
20
|
-
import React, {
|
|
28
|
+
import React, { Component, createRef } from 'react';
|
|
29
|
+
import PropTypes from "prop-types";
|
|
21
30
|
import classNames from 'classnames';
|
|
22
|
-
import { htmlIdGenerator, keys,
|
|
31
|
+
import { htmlIdGenerator, keys, RenderWithEuiStylesMemoizer } from '../../../services';
|
|
23
32
|
import { EuiI18n } from '../../i18n';
|
|
24
33
|
import { EuiScreenReaderOnly } from '../../accessibility';
|
|
25
34
|
import { EuiInputPopover } from '../../popover';
|
|
@@ -31,256 +40,351 @@ var ShiftDirection = /*#__PURE__*/function (ShiftDirection) {
|
|
|
31
40
|
ShiftDirection["BACK"] = "back";
|
|
32
41
|
ShiftDirection["FORWARD"] = "forward";
|
|
33
42
|
return ShiftDirection;
|
|
34
|
-
}(ShiftDirection || {});
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
var
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
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;
|
|
43
|
+
}(ShiftDirection || {});
|
|
44
|
+
export var EuiSuperSelect = /*#__PURE__*/function (_Component) {
|
|
45
|
+
function EuiSuperSelect() {
|
|
46
|
+
var _this;
|
|
47
|
+
_classCallCheck(this, EuiSuperSelect);
|
|
48
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
49
|
+
args[_key] = arguments[_key];
|
|
50
|
+
}
|
|
51
|
+
_this = _callSuper(this, EuiSuperSelect, [].concat(args));
|
|
52
|
+
_defineProperty(_this, "itemNodes", []);
|
|
53
|
+
_defineProperty(_this, "_isMounted", false);
|
|
54
|
+
_defineProperty(_this, "controlButtonRef", /*#__PURE__*/createRef());
|
|
55
|
+
_defineProperty(_this, "describedById", htmlIdGenerator('euiSuperSelect_')('_screenreaderDescribeId'));
|
|
56
|
+
_defineProperty(_this, "state", {
|
|
57
|
+
isPopoverOpen: _this.props.isOpen || false,
|
|
58
|
+
currentIndex: 0
|
|
59
|
+
});
|
|
60
|
+
_defineProperty(_this, "setItemNode", function (node, index) {
|
|
61
|
+
_this.itemNodes[index] = node;
|
|
85
62
|
});
|
|
86
|
-
|
|
87
|
-
|
|
63
|
+
_defineProperty(_this, "openPopover", function () {
|
|
64
|
+
var _this$props = _this.props,
|
|
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;
|
|
88
72
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
73
|
+
// If the item is disabled, find the first focusable item going forward
|
|
74
|
+
while (initialIndex < options.length && (_options$initialIndex = options[initialIndex]) !== null && _options$initialIndex !== void 0 && _options$initialIndex.disabled) {
|
|
75
|
+
var _options$initialIndex;
|
|
76
|
+
initialIndex++;
|
|
77
|
+
}
|
|
78
|
+
if (initialIndex >= options.length) {
|
|
79
|
+
initialIndex = candidateIndex;
|
|
80
|
+
}
|
|
81
|
+
_this.setState({
|
|
82
|
+
isPopoverOpen: options.length > 0,
|
|
83
|
+
currentIndex: initialIndex
|
|
84
|
+
});
|
|
100
85
|
requestAnimationFrame(function () {
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
onFocus
|
|
107
|
-
|
|
86
|
+
requestAnimationFrame(function () {
|
|
87
|
+
if (!_this._isMounted) {
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
_this.focusItemAt(initialIndex);
|
|
91
|
+
if (_this.props.onFocus) {
|
|
92
|
+
_this.props.onFocus();
|
|
93
|
+
}
|
|
94
|
+
});
|
|
108
95
|
});
|
|
109
96
|
});
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
97
|
+
_defineProperty(_this, "closePopover", function () {
|
|
98
|
+
_this.setState({
|
|
99
|
+
isPopoverOpen: false,
|
|
100
|
+
currentIndex: -1
|
|
101
|
+
});
|
|
114
102
|
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
103
|
+
// Refocus back to the toggling control button on popover close
|
|
104
|
+
requestAnimationFrame(function () {
|
|
105
|
+
var _this$controlButtonRe;
|
|
106
|
+
(_this$controlButtonRe = _this.controlButtonRef.current) === null || _this$controlButtonRe === void 0 || _this$controlButtonRe.focus();
|
|
107
|
+
});
|
|
108
|
+
if (_this.props.onBlur) {
|
|
109
|
+
_this.props.onBlur();
|
|
110
|
+
}
|
|
119
111
|
});
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
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
|
|
148
|
-
event.preventDefault();
|
|
149
|
-
event.stopPropagation();
|
|
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:
|
|
112
|
+
_defineProperty(_this, "itemClicked", function (value) {
|
|
113
|
+
_this.closePopover();
|
|
114
|
+
if (_this.props.onChange) {
|
|
115
|
+
_this.props.onChange(value);
|
|
116
|
+
}
|
|
117
|
+
});
|
|
118
|
+
_defineProperty(_this, "onSelectKeyDown", function (event) {
|
|
119
|
+
// Mimic the ways native `<select>`s can be opened via keypress
|
|
120
|
+
if (event.key === keys.ARROW_UP || event.key === keys.ARROW_DOWN || event.key === keys.SPACE) {
|
|
164
121
|
event.preventDefault();
|
|
165
122
|
event.stopPropagation();
|
|
166
|
-
|
|
167
|
-
|
|
123
|
+
_this.openPopover();
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
_defineProperty(_this, "onItemKeyDown", function (event) {
|
|
127
|
+
switch (event.key) {
|
|
128
|
+
case keys.ESCAPE:
|
|
129
|
+
// close the popover and prevent ancestors from handling
|
|
130
|
+
event.preventDefault();
|
|
131
|
+
event.stopPropagation();
|
|
132
|
+
_this.closePopover();
|
|
133
|
+
break;
|
|
134
|
+
case keys.TAB:
|
|
135
|
+
// Mimic native `<select>` behavior, which selects an item on tab press
|
|
136
|
+
event.preventDefault();
|
|
137
|
+
event.stopPropagation();
|
|
138
|
+
event.target.click();
|
|
139
|
+
break;
|
|
140
|
+
case keys.ARROW_UP:
|
|
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
|
+
}
|
|
168
162
|
}
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
focusItemAt(0);
|
|
174
|
-
setCurrentIndex(0);
|
|
175
|
-
return;
|
|
163
|
+
}, {
|
|
164
|
+
key: "componentWillUnmount",
|
|
165
|
+
value: function componentWillUnmount() {
|
|
166
|
+
this._isMounted = false;
|
|
176
167
|
}
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
168
|
+
}, {
|
|
169
|
+
key: "focusItemAt",
|
|
170
|
+
value: function focusItemAt(index) {
|
|
171
|
+
var _this$itemNodes$index;
|
|
172
|
+
(_this$itemNodes$index = this.itemNodes[index]) === null || _this$itemNodes$index === void 0 || _this$itemNodes$index.focus();
|
|
173
|
+
}
|
|
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
|
+
});
|
|
187
185
|
return;
|
|
188
186
|
}
|
|
189
|
-
|
|
187
|
+
|
|
188
|
+
// Note: this component purposely does not cycle arrow key navigation
|
|
189
|
+
// to match native <select> elements
|
|
190
|
+
var step = direction === ShiftDirection.BACK ? -1 : 1;
|
|
191
|
+
var nextIndex = currentIndex + step;
|
|
192
|
+
while (nextIndex >= 0 && nextIndex < options.length) {
|
|
193
|
+
var _options$nextIndex;
|
|
194
|
+
if (!((_options$nextIndex = options[nextIndex]) !== null && _options$nextIndex !== void 0 && _options$nextIndex.disabled)) {
|
|
195
|
+
this.focusItemAt(nextIndex);
|
|
196
|
+
this.setState({
|
|
197
|
+
currentIndex: nextIndex
|
|
198
|
+
});
|
|
199
|
+
return;
|
|
200
|
+
}
|
|
201
|
+
nextIndex += step;
|
|
202
|
+
}
|
|
190
203
|
}
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
204
|
+
}, {
|
|
205
|
+
key: "render",
|
|
206
|
+
value: function render() {
|
|
207
|
+
var _this2 = this,
|
|
208
|
+
_options$this$state$c;
|
|
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
|
+
});
|
|
196
303
|
}
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
};
|
|
285
|
-
export var EuiSuperSelect = /*#__PURE__*/forwardRef(EuiSuperSelectInner);
|
|
286
|
-
EuiSuperSelect.displayName = 'EuiSuperSelect';
|
|
304
|
+
}]);
|
|
305
|
+
}(Component);
|
|
306
|
+
_defineProperty(EuiSuperSelect, "defaultProps", {
|
|
307
|
+
fullWidth: false,
|
|
308
|
+
compressed: false,
|
|
309
|
+
isInvalid: false,
|
|
310
|
+
isLoading: false
|
|
311
|
+
});
|
|
312
|
+
EuiSuperSelect.propTypes = {
|
|
313
|
+
className: PropTypes.string,
|
|
314
|
+
"aria-label": PropTypes.string,
|
|
315
|
+
"data-test-subj": PropTypes.string,
|
|
316
|
+
css: PropTypes.any,
|
|
317
|
+
buttonRef: PropTypes.any,
|
|
318
|
+
/**
|
|
319
|
+
* @default false
|
|
320
|
+
*/
|
|
321
|
+
compressed: PropTypes.bool,
|
|
322
|
+
/**
|
|
323
|
+
* Expand to fill 100% of the parent.
|
|
324
|
+
* Defaults to `fullWidth` prop of `<EuiForm>`.
|
|
325
|
+
* @default false
|
|
326
|
+
*/
|
|
327
|
+
fullWidth: PropTypes.bool,
|
|
328
|
+
/**
|
|
329
|
+
* @default false
|
|
330
|
+
*/
|
|
331
|
+
isInvalid: PropTypes.bool,
|
|
332
|
+
/**
|
|
333
|
+
* @default false
|
|
334
|
+
*/
|
|
335
|
+
isLoading: PropTypes.bool,
|
|
336
|
+
readOnly: PropTypes.bool,
|
|
337
|
+
name: PropTypes.string,
|
|
338
|
+
/**
|
|
339
|
+
* Placeholder to display when the current selected value is empty.
|
|
340
|
+
*/
|
|
341
|
+
placeholder: PropTypes.node,
|
|
342
|
+
/**
|
|
343
|
+
* Creates an input group with element(s) coming before input.
|
|
344
|
+
* `string` | `ReactElement` or an array of these
|
|
345
|
+
*/
|
|
346
|
+
prepend: PropTypes.oneOfType([PropTypes.oneOfType([PropTypes.string.isRequired, PropTypes.element.isRequired]).isRequired, PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.string.isRequired, PropTypes.element.isRequired]).isRequired).isRequired]),
|
|
347
|
+
/**
|
|
348
|
+
* Creates an input group with element(s) coming after input.
|
|
349
|
+
* `string` | `ReactElement` or an array of these
|
|
350
|
+
*/
|
|
351
|
+
append: PropTypes.oneOfType([PropTypes.oneOfType([PropTypes.string.isRequired, PropTypes.element.isRequired]).isRequired, PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.string.isRequired, PropTypes.element.isRequired]).isRequired).isRequired]),
|
|
352
|
+
/**
|
|
353
|
+
* Pass an array of options that must at least include:
|
|
354
|
+
* `value`: storing unique value of item,
|
|
355
|
+
* `inputDisplay`: what shows inside the form input when selected
|
|
356
|
+
* `dropdownDisplay` (optional): what shows for the item in the dropdown
|
|
357
|
+
*/
|
|
358
|
+
options: PropTypes.arrayOf(PropTypes.shape({
|
|
359
|
+
value: PropTypes.any.isRequired,
|
|
360
|
+
inputDisplay: PropTypes.node,
|
|
361
|
+
dropdownDisplay: PropTypes.node,
|
|
362
|
+
disabled: PropTypes.bool,
|
|
363
|
+
"data-test-subj": PropTypes.string
|
|
364
|
+
}).isRequired).isRequired,
|
|
365
|
+
valueOfSelected: PropTypes.any,
|
|
366
|
+
/**
|
|
367
|
+
* Classes for the context menu item
|
|
368
|
+
*/
|
|
369
|
+
itemClassName: PropTypes.string,
|
|
370
|
+
/**
|
|
371
|
+
* You must pass an `onChange` function to handle the update of the value
|
|
372
|
+
*/
|
|
373
|
+
onChange: PropTypes.func,
|
|
374
|
+
onFocus: PropTypes.func,
|
|
375
|
+
onBlur: PropTypes.func,
|
|
376
|
+
/**
|
|
377
|
+
* Controls whether the options are shown. Default: false
|
|
378
|
+
*/
|
|
379
|
+
isOpen: PropTypes.bool,
|
|
380
|
+
/**
|
|
381
|
+
* Optional props to pass to the underlying [EuiInputPopover](https://eui.elastic.co/docs/components/containers/popover/).
|
|
382
|
+
* Allows fine-grained control of the popover dropdown menu, including
|
|
383
|
+
* `repositionOnScroll` for EuiSuperSelects used within scrollable containers,
|
|
384
|
+
* and customizing popover panel styling.
|
|
385
|
+
*
|
|
386
|
+
* Does not accept a nested `popoverProps.isOpen` property - use the top level
|
|
387
|
+
* `isOpen` API instead.
|
|
388
|
+
*/
|
|
389
|
+
popoverProps: PropTypes.any
|
|
390
|
+
};
|