@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.
Files changed (87) hide show
  1. package/dist/eui-icons.json +37 -37
  2. package/es/components/combo_box/combo_box_options_list/combo_box_options_list.js +8 -2
  3. package/es/components/datagrid/body/cell/data_grid_cell.js +8 -5
  4. package/es/components/datagrid/body/cell/data_grid_cell.styles.js +1 -1
  5. package/es/components/datagrid/body/cell/data_grid_cell_wrapper.js +4 -2
  6. package/es/components/datagrid/body/footer/data_grid_footer_row.js +4 -0
  7. package/es/components/datagrid/body/header/column_resizer.js +74 -87
  8. package/es/components/datagrid/body/header/data_grid_control_header_cell.js +2 -1
  9. package/es/components/datagrid/body/header/data_grid_header_cell.js +1 -0
  10. package/es/components/datagrid/body/header/data_grid_header_cell_wrapper.js +9 -3
  11. package/es/components/datagrid/body/header/data_grid_header_cell_wrapper.styles.js +1 -1
  12. package/es/components/datagrid/controls/keyboard_shortcuts.js +17 -1
  13. package/es/components/datagrid/data_grid.js +2 -0
  14. package/es/components/datagrid/utils/copy_focused_cell.js +34 -0
  15. package/es/components/filter_group/filter_group.a11y.js +1 -1
  16. package/es/components/form/super_select/super_select.js +247 -351
  17. package/es/components/list_item_layout/_list_item_layout.js +12 -0
  18. package/es/components/selectable/selectable_list/selectable_list_item.js +9 -7
  19. package/eui.d.ts +69 -95
  20. package/i18ntokens.json +608 -554
  21. package/lib/components/combo_box/combo_box_options_list/combo_box_options_list.js +8 -2
  22. package/lib/components/datagrid/body/cell/data_grid_cell.js +8 -5
  23. package/lib/components/datagrid/body/cell/data_grid_cell.styles.js +1 -1
  24. package/lib/components/datagrid/body/cell/data_grid_cell_wrapper.js +4 -2
  25. package/lib/components/datagrid/body/footer/data_grid_footer_row.js +4 -0
  26. package/lib/components/datagrid/body/header/column_resizer.js +73 -85
  27. package/lib/components/datagrid/body/header/data_grid_control_header_cell.js +2 -1
  28. package/lib/components/datagrid/body/header/data_grid_header_cell.js +1 -0
  29. package/lib/components/datagrid/body/header/data_grid_header_cell_wrapper.js +9 -3
  30. package/lib/components/datagrid/body/header/data_grid_header_cell_wrapper.styles.js +1 -1
  31. package/lib/components/datagrid/controls/keyboard_shortcuts.js +17 -1
  32. package/lib/components/datagrid/data_grid.js +2 -0
  33. package/lib/components/datagrid/utils/copy_focused_cell.js +39 -0
  34. package/lib/components/filter_group/filter_group.a11y.js +1 -1
  35. package/lib/components/form/super_select/super_select.js +253 -355
  36. package/lib/components/list_item_layout/_list_item_layout.js +12 -0
  37. package/lib/components/selectable/selectable_list/selectable_list_item.js +9 -7
  38. package/optimize/es/components/combo_box/combo_box_options_list/combo_box_options_list.js +8 -2
  39. package/optimize/es/components/datagrid/body/cell/data_grid_cell.js +5 -4
  40. package/optimize/es/components/datagrid/body/cell/data_grid_cell.styles.js +1 -1
  41. package/optimize/es/components/datagrid/body/cell/data_grid_cell_wrapper.js +4 -2
  42. package/optimize/es/components/datagrid/body/footer/data_grid_footer_row.js +4 -0
  43. package/optimize/es/components/datagrid/body/header/column_resizer.js +69 -81
  44. package/optimize/es/components/datagrid/body/header/data_grid_control_header_cell.js +2 -1
  45. package/optimize/es/components/datagrid/body/header/data_grid_header_cell.js +1 -0
  46. package/optimize/es/components/datagrid/body/header/data_grid_header_cell_wrapper.js +7 -3
  47. package/optimize/es/components/datagrid/body/header/data_grid_header_cell_wrapper.styles.js +1 -1
  48. package/optimize/es/components/datagrid/controls/keyboard_shortcuts.js +17 -1
  49. package/optimize/es/components/datagrid/data_grid.js +2 -0
  50. package/optimize/es/components/datagrid/utils/copy_focused_cell.js +34 -0
  51. package/optimize/es/components/filter_group/filter_group.a11y.js +1 -1
  52. package/optimize/es/components/form/super_select/super_select.js +242 -265
  53. package/optimize/es/components/selectable/selectable_list/selectable_list_item.js +9 -7
  54. package/optimize/lib/components/combo_box/combo_box_options_list/combo_box_options_list.js +8 -2
  55. package/optimize/lib/components/datagrid/body/cell/data_grid_cell.js +5 -4
  56. package/optimize/lib/components/datagrid/body/cell/data_grid_cell.styles.js +1 -1
  57. package/optimize/lib/components/datagrid/body/cell/data_grid_cell_wrapper.js +4 -2
  58. package/optimize/lib/components/datagrid/body/footer/data_grid_footer_row.js +4 -0
  59. package/optimize/lib/components/datagrid/body/header/column_resizer.js +69 -79
  60. package/optimize/lib/components/datagrid/body/header/data_grid_control_header_cell.js +2 -1
  61. package/optimize/lib/components/datagrid/body/header/data_grid_header_cell.js +1 -0
  62. package/optimize/lib/components/datagrid/body/header/data_grid_header_cell_wrapper.js +7 -3
  63. package/optimize/lib/components/datagrid/body/header/data_grid_header_cell_wrapper.styles.js +1 -1
  64. package/optimize/lib/components/datagrid/controls/keyboard_shortcuts.js +17 -1
  65. package/optimize/lib/components/datagrid/data_grid.js +2 -0
  66. package/optimize/lib/components/datagrid/utils/copy_focused_cell.js +39 -0
  67. package/optimize/lib/components/filter_group/filter_group.a11y.js +1 -1
  68. package/optimize/lib/components/form/super_select/super_select.js +243 -265
  69. package/optimize/lib/components/selectable/selectable_list/selectable_list_item.js +9 -7
  70. package/package.json +2 -2
  71. package/test-env/components/combo_box/combo_box_options_list/combo_box_options_list.js +8 -2
  72. package/test-env/components/datagrid/body/cell/data_grid_cell.js +8 -5
  73. package/test-env/components/datagrid/body/cell/data_grid_cell.styles.js +1 -1
  74. package/test-env/components/datagrid/body/cell/data_grid_cell_wrapper.js +4 -2
  75. package/test-env/components/datagrid/body/footer/data_grid_footer_row.js +4 -0
  76. package/test-env/components/datagrid/body/header/column_resizer.js +69 -79
  77. package/test-env/components/datagrid/body/header/data_grid_control_header_cell.js +2 -1
  78. package/test-env/components/datagrid/body/header/data_grid_header_cell.js +1 -0
  79. package/test-env/components/datagrid/body/header/data_grid_header_cell_wrapper.js +9 -3
  80. package/test-env/components/datagrid/body/header/data_grid_header_cell_wrapper.styles.js +1 -1
  81. package/test-env/components/datagrid/controls/keyboard_shortcuts.js +17 -1
  82. package/test-env/components/datagrid/data_grid.js +2 -0
  83. package/test-env/components/datagrid/utils/copy_focused_cell.js +16 -0
  84. package/test-env/components/filter_group/filter_group.a11y.js +1 -1
  85. package/test-env/components/form/super_select/super_select.js +243 -345
  86. package/test-env/components/list_item_layout/_list_item_layout.js +12 -0
  87. package/test-env/components/selectable/selectable_list/selectable_list_item.js +9 -7
@@ -7,15 +7,9 @@ Object.defineProperty(exports, "__esModule", {
7
7
  });
8
8
  exports.EuiSuperSelect = void 0;
9
9
  var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
10
+ var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
10
11
  var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
11
- var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
12
- var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
13
- var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
14
- var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
15
- var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
16
- var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
17
12
  var _react = _interopRequireWildcard(require("react"));
18
- var _propTypes = _interopRequireDefault(require("prop-types"));
19
13
  var _classnames = _interopRequireDefault(require("classnames"));
20
14
  var _services = require("../../../services");
21
15
  var _i18n = require("../../i18n");
@@ -25,367 +19,271 @@ var _super_select_control = require("./super_select_control");
25
19
  var _super_select_item = require("./super_select_item");
26
20
  var _super_select = require("./super_select.styles");
27
21
  var _react2 = require("@emotion/react");
28
- var _excluded = ["className", "options", "valueOfSelected", "placeholder", "onChange", "isOpen", "isInvalid", "itemClassName", "fullWidth", "popoverProps", "compressed"],
22
+ var _excluded = ["className", "options", "valueOfSelected", "placeholder", "onChange", "onFocus", "onBlur", "isOpen", "isInvalid", "itemClassName", "fullWidth", "popoverProps", "compressed", "isLoading"],
29
23
  _excluded2 = ["value", "dropdownDisplay", "inputDisplay", "disabled"];
30
- 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); }
31
- 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; }
32
- function _callSuper(t, o, e) { return o = (0, _getPrototypeOf2.default)(o), (0, _possibleConstructorReturn2.default)(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], (0, _getPrototypeOf2.default)(t).constructor) : o.apply(t, e)); }
33
- function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); } /*
24
+ /*
34
25
  * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
35
26
  * or more contributor license agreements. Licensed under the Elastic License
36
27
  * 2.0 and the Server Side Public License, v 1; you may not use this file except
37
28
  * in compliance with, at your election, the Elastic License 2.0 or the Server
38
29
  * Side Public License, v 1.
39
30
  */
31
+ 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); }
32
+ 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; }
40
33
  var ShiftDirection = /*#__PURE__*/function (ShiftDirection) {
41
34
  ShiftDirection["BACK"] = "back";
42
35
  ShiftDirection["FORWARD"] = "forward";
43
36
  return ShiftDirection;
44
- }(ShiftDirection || {});
45
- var EuiSuperSelect = exports.EuiSuperSelect = /*#__PURE__*/function (_Component) {
46
- function EuiSuperSelect() {
47
- var _this;
48
- (0, _classCallCheck2.default)(this, EuiSuperSelect);
49
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
50
- args[_key] = arguments[_key];
51
- }
52
- _this = _callSuper(this, EuiSuperSelect, [].concat(args));
53
- (0, _defineProperty2.default)(_this, "itemNodes", []);
54
- (0, _defineProperty2.default)(_this, "_isMounted", false);
55
- (0, _defineProperty2.default)(_this, "controlButtonRef", /*#__PURE__*/(0, _react.createRef)());
56
- (0, _defineProperty2.default)(_this, "describedById", (0, _services.htmlIdGenerator)('euiSuperSelect_')('_screenreaderDescribeId'));
57
- (0, _defineProperty2.default)(_this, "state", {
58
- isPopoverOpen: _this.props.isOpen || false,
59
- currentIndex: 0
60
- });
61
- (0, _defineProperty2.default)(_this, "setItemNode", function (node, index) {
62
- _this.itemNodes[index] = node;
37
+ }(ShiftDirection || {}); // Runs synchronously on the client before paint, so the mount flag is always
38
+ // set before an interaction can schedule the deferred focus in `openPopover`.
39
+ var useMountEffect = typeof document === 'undefined' ? _react.useEffect : _react.useLayoutEffect;
40
+ var EuiSuperSelectInner = function EuiSuperSelectInner(_ref, ref) {
41
+ var _options$currentIndex;
42
+ var className = _ref.className,
43
+ options = _ref.options,
44
+ valueOfSelected = _ref.valueOfSelected,
45
+ placeholder = _ref.placeholder,
46
+ onChange = _ref.onChange,
47
+ onFocus = _ref.onFocus,
48
+ onBlur = _ref.onBlur,
49
+ isOpen = _ref.isOpen,
50
+ _ref$isInvalid = _ref.isInvalid,
51
+ isInvalid = _ref$isInvalid === void 0 ? false : _ref$isInvalid,
52
+ itemClassName = _ref.itemClassName,
53
+ _ref$fullWidth = _ref.fullWidth,
54
+ fullWidth = _ref$fullWidth === void 0 ? false : _ref$fullWidth,
55
+ popoverProps = _ref.popoverProps,
56
+ _ref$compressed = _ref.compressed,
57
+ compressed = _ref$compressed === void 0 ? false : _ref$compressed,
58
+ _ref$isLoading = _ref.isLoading,
59
+ isLoading = _ref$isLoading === void 0 ? false : _ref$isLoading,
60
+ rest = (0, _objectWithoutProperties2.default)(_ref, _excluded);
61
+ var styles = (0, _services.useEuiMemoizedStyles)(_super_select.euiSuperSelectStyles);
62
+ var itemNodes = (0, _react.useRef)([]);
63
+ var isMounted = (0, _react.useRef)(false);
64
+ var controlButtonRef = (0, _react.useRef)(null);
65
+ var _useState = (0, _react.useState)(function () {
66
+ return (0, _services.htmlIdGenerator)('euiSuperSelect_')('_screenreaderDescribeId');
67
+ }),
68
+ _useState2 = (0, _slicedToArray2.default)(_useState, 1),
69
+ describedById = _useState2[0];
70
+ var _useState3 = (0, _react.useState)(isOpen || false),
71
+ _useState4 = (0, _slicedToArray2.default)(_useState3, 2),
72
+ isPopoverOpen = _useState4[0],
73
+ setIsPopoverOpen = _useState4[1];
74
+ var _useState5 = (0, _react.useState)(0),
75
+ _useState6 = (0, _slicedToArray2.default)(_useState5, 2),
76
+ currentIndex = _useState6[0],
77
+ setCurrentIndex = _useState6[1];
78
+ var setItemNode = function setItemNode(node, index) {
79
+ itemNodes.current[index] = node;
80
+ };
81
+ var focusItemAt = (0, _react.useCallback)(function (index) {
82
+ var _itemNodes$current$in;
83
+ (_itemNodes$current$in = itemNodes.current[index]) === null || _itemNodes$current$in === void 0 || _itemNodes$current$in.focus();
84
+ }, []);
85
+ var openPopover = (0, _react.useCallback)(function () {
86
+ var indexOfSelected = options.findIndex(function (option) {
87
+ return (option === null || option === void 0 ? void 0 : option.value) === valueOfSelected;
63
88
  });
64
- (0, _defineProperty2.default)(_this, "openPopover", function () {
65
- var _this$props = _this.props,
66
- options = _this$props.options,
67
- valueOfSelected = _this$props.valueOfSelected;
68
- var indexOfSelected = options.findIndex(function (option) {
69
- return (option === null || option === void 0 ? void 0 : option.value) === valueOfSelected;
70
- });
71
- var candidateIndex = valueOfSelected != null && indexOfSelected >= 0 ? indexOfSelected : 0;
72
- var initialIndex = candidateIndex;
89
+ var candidateIndex = valueOfSelected != null && indexOfSelected >= 0 ? indexOfSelected : 0;
90
+ var initialIndex = candidateIndex;
73
91
 
74
- // If the item is disabled, find the first focusable item going forward
75
- while (initialIndex < options.length && (_options$initialIndex = options[initialIndex]) !== null && _options$initialIndex !== void 0 && _options$initialIndex.disabled) {
76
- var _options$initialIndex;
77
- initialIndex++;
78
- }
79
- if (initialIndex >= options.length) {
80
- initialIndex = candidateIndex;
81
- }
82
- _this.setState({
83
- isPopoverOpen: options.length > 0,
84
- currentIndex: initialIndex
85
- });
92
+ // If the item is disabled, find the first focusable item going forward
93
+ while (initialIndex < options.length && (_options$initialIndex = options[initialIndex]) !== null && _options$initialIndex !== void 0 && _options$initialIndex.disabled) {
94
+ var _options$initialIndex;
95
+ initialIndex++;
96
+ }
97
+ if (initialIndex >= options.length) {
98
+ initialIndex = candidateIndex;
99
+ }
100
+ setIsPopoverOpen(options.length > 0);
101
+ setCurrentIndex(initialIndex);
102
+ requestAnimationFrame(function () {
86
103
  requestAnimationFrame(function () {
87
- requestAnimationFrame(function () {
88
- if (!_this._isMounted) {
89
- return;
90
- }
91
- _this.focusItemAt(initialIndex);
92
- if (_this.props.onFocus) {
93
- _this.props.onFocus();
94
- }
95
- });
104
+ if (!isMounted.current) {
105
+ return;
106
+ }
107
+ focusItemAt(initialIndex);
108
+ if (onFocus) {
109
+ onFocus();
110
+ }
96
111
  });
97
112
  });
98
- (0, _defineProperty2.default)(_this, "closePopover", function () {
99
- _this.setState({
100
- isPopoverOpen: false,
101
- currentIndex: -1
102
- });
113
+ }, [options, valueOfSelected, onFocus, focusItemAt]);
114
+ var closePopover = (0, _react.useCallback)(function () {
115
+ setIsPopoverOpen(false);
116
+ setCurrentIndex(-1);
103
117
 
104
- // Refocus back to the toggling control button on popover close
105
- requestAnimationFrame(function () {
106
- var _this$controlButtonRe;
107
- (_this$controlButtonRe = _this.controlButtonRef.current) === null || _this$controlButtonRe === void 0 || _this$controlButtonRe.focus();
108
- });
109
- if (_this.props.onBlur) {
110
- _this.props.onBlur();
111
- }
118
+ // Refocus back to the toggling control button on popover close
119
+ requestAnimationFrame(function () {
120
+ var _controlButtonRef$cur;
121
+ (_controlButtonRef$cur = controlButtonRef.current) === null || _controlButtonRef$cur === void 0 || _controlButtonRef$cur.focus();
112
122
  });
113
- (0, _defineProperty2.default)(_this, "itemClicked", function (value) {
114
- _this.closePopover();
115
- if (_this.props.onChange) {
116
- _this.props.onChange(value);
117
- }
118
- });
119
- (0, _defineProperty2.default)(_this, "onSelectKeyDown", function (event) {
120
- // Mimic the ways native `<select>`s can be opened via keypress
121
- if (event.key === _services.keys.ARROW_UP || event.key === _services.keys.ARROW_DOWN || event.key === _services.keys.SPACE) {
123
+ if (onBlur) {
124
+ onBlur();
125
+ }
126
+ }, [onBlur]);
127
+ (0, _react.useImperativeHandle)(ref, function () {
128
+ return {
129
+ openPopover: openPopover,
130
+ closePopover: closePopover
131
+ };
132
+ }, [openPopover, closePopover]);
133
+ var itemClicked = function itemClicked(value) {
134
+ closePopover();
135
+ if (onChange) {
136
+ onChange(value);
137
+ }
138
+ };
139
+ var onSelectKeyDown = function onSelectKeyDown(event) {
140
+ // Mimic the ways native `<select>`s can be opened via keypress
141
+ if (event.key === _services.keys.ARROW_UP || event.key === _services.keys.ARROW_DOWN || event.key === _services.keys.SPACE) {
142
+ event.preventDefault();
143
+ event.stopPropagation();
144
+ openPopover();
145
+ }
146
+ };
147
+ var onItemKeyDown = function onItemKeyDown(event) {
148
+ switch (event.key) {
149
+ case _services.keys.ESCAPE:
150
+ // close the popover and prevent ancestors from handling
122
151
  event.preventDefault();
123
152
  event.stopPropagation();
124
- _this.openPopover();
125
- }
126
- });
127
- (0, _defineProperty2.default)(_this, "onItemKeyDown", function (event) {
128
- switch (event.key) {
129
- case _services.keys.ESCAPE:
130
- // close the popover and prevent ancestors from handling
131
- event.preventDefault();
132
- event.stopPropagation();
133
- _this.closePopover();
134
- break;
135
- case _services.keys.TAB:
136
- // Mimic native `<select>` behavior, which selects an item on tab press
137
- event.preventDefault();
138
- event.stopPropagation();
139
- event.target.click();
140
- break;
141
- case _services.keys.ARROW_UP:
142
- event.preventDefault();
143
- event.stopPropagation();
144
- _this.shiftFocus(ShiftDirection.BACK);
145
- break;
146
- case _services.keys.ARROW_DOWN:
147
- event.preventDefault();
148
- event.stopPropagation();
149
- _this.shiftFocus(ShiftDirection.FORWARD);
150
- break;
151
- }
152
- });
153
- return _this;
154
- }
155
- (0, _inherits2.default)(EuiSuperSelect, _Component);
156
- return (0, _createClass2.default)(EuiSuperSelect, [{
157
- key: "componentDidMount",
158
- value: function componentDidMount() {
159
- this._isMounted = true;
160
- if (this.props.isOpen) {
161
- this.openPopover();
162
- }
163
- }
164
- }, {
165
- key: "componentWillUnmount",
166
- value: function componentWillUnmount() {
167
- this._isMounted = false;
153
+ closePopover();
154
+ break;
155
+ case _services.keys.TAB:
156
+ // Mimic native `<select>` behavior, which selects an item on tab press
157
+ event.preventDefault();
158
+ event.stopPropagation();
159
+ event.target.click();
160
+ break;
161
+ case _services.keys.ARROW_UP:
162
+ event.preventDefault();
163
+ event.stopPropagation();
164
+ shiftFocus(ShiftDirection.BACK);
165
+ break;
166
+ case _services.keys.ARROW_DOWN:
167
+ event.preventDefault();
168
+ event.stopPropagation();
169
+ shiftFocus(ShiftDirection.FORWARD);
170
+ break;
168
171
  }
169
- }, {
170
- key: "focusItemAt",
171
- value: function focusItemAt(index) {
172
- var _this$itemNodes$index;
173
- (_this$itemNodes$index = this.itemNodes[index]) === null || _this$itemNodes$index === void 0 || _this$itemNodes$index.focus();
172
+ };
173
+ var shiftFocus = function shiftFocus(direction) {
174
+ if (currentIndex === -1) {
175
+ // somehow the select options has lost focus
176
+ focusItemAt(0);
177
+ setCurrentIndex(0);
178
+ return;
174
179
  }
175
- }, {
176
- key: "shiftFocus",
177
- value: function shiftFocus(direction) {
178
- var options = this.props.options;
179
- var currentIndex = this.state.currentIndex;
180
- if (currentIndex === -1) {
181
- // somehow the select options has lost focus
182
- this.focusItemAt(0);
183
- this.setState({
184
- currentIndex: 0
185
- });
186
- return;
187
- }
188
180
 
189
- // Note: this component purposely does not cycle arrow key navigation
190
- // to match native <select> elements
191
- var step = direction === ShiftDirection.BACK ? -1 : 1;
192
- var nextIndex = currentIndex + step;
193
- while (nextIndex >= 0 && nextIndex < options.length) {
194
- var _options$nextIndex;
195
- if (!((_options$nextIndex = options[nextIndex]) !== null && _options$nextIndex !== void 0 && _options$nextIndex.disabled)) {
196
- this.focusItemAt(nextIndex);
197
- this.setState({
198
- currentIndex: nextIndex
199
- });
200
- return;
201
- }
202
- nextIndex += step;
181
+ // Note: this component purposely does not cycle arrow key navigation
182
+ // to match native <select> elements
183
+ var step = direction === ShiftDirection.BACK ? -1 : 1;
184
+ var nextIndex = currentIndex + step;
185
+ while (nextIndex >= 0 && nextIndex < options.length) {
186
+ var _options$nextIndex;
187
+ if (!((_options$nextIndex = options[nextIndex]) !== null && _options$nextIndex !== void 0 && _options$nextIndex.disabled)) {
188
+ focusItemAt(nextIndex);
189
+ setCurrentIndex(nextIndex);
190
+ return;
203
191
  }
192
+ nextIndex += step;
204
193
  }
205
- }, {
206
- key: "render",
207
- value: function render() {
208
- var _this2 = this,
209
- _options$this$state$c;
210
- var _this$props2 = this.props,
211
- className = _this$props2.className,
212
- options = _this$props2.options,
213
- valueOfSelected = _this$props2.valueOfSelected,
214
- placeholder = _this$props2.placeholder,
215
- onChange = _this$props2.onChange,
216
- isOpen = _this$props2.isOpen,
217
- isInvalid = _this$props2.isInvalid,
218
- itemClassName = _this$props2.itemClassName,
219
- fullWidth = _this$props2.fullWidth,
220
- popoverProps = _this$props2.popoverProps,
221
- compressed = _this$props2.compressed,
222
- rest = (0, _objectWithoutProperties2.default)(_this$props2, _excluded);
223
- var popoverClasses = (0, _classnames.default)('euiSuperSelect', popoverProps === null || popoverProps === void 0 ? void 0 : popoverProps.className);
224
- var button = (0, _react2.jsx)(_super_select_control.EuiSuperSelectControl, (0, _extends2.default)({
225
- options: options,
226
- value: valueOfSelected,
227
- placeholder: placeholder,
228
- onClick: this.state.isPopoverOpen ? this.closePopover : this.openPopover,
229
- onKeyDown: this.onSelectKeyDown,
230
- className: className,
231
- fullWidth: fullWidth,
232
- isInvalid: isInvalid,
233
- compressed: compressed
234
- }, rest, {
235
- buttonRef: this.controlButtonRef,
236
- isDropdownOpen: this.state.isPopoverOpen
237
- }));
238
- var items = options.map(function (option, index) {
239
- var value = option.value,
240
- dropdownDisplay = option.dropdownDisplay,
241
- inputDisplay = option.inputDisplay,
242
- disabled = option.disabled,
243
- optionRest = (0, _objectWithoutProperties2.default)(option, _excluded2);
244
- if (value == null) return;
245
- return (0, _react2.jsx)(_super_select_item.EuiSuperSelectItem, (0, _extends2.default)({
246
- key: index
247
- /* NOTE: This should rather use "li" to align select-like behavior. But the current
248
- implementation relies on the interactive and focusable item for the navigation.
249
- This will require additional refactoring to adjust but we might want to decide first
250
- if the effort is worth it, considering the unification plans for selection components
251
- as part of OneSelect (https://github.com/elastic/eui/issues/8808).
252
- */,
253
- element: "button",
254
- id: String(value),
255
- className: itemClassName,
256
- checked: valueOfSelected === value ? 'on' : undefined,
257
- isSelected: valueOfSelected === value,
258
- isFocused: _this2.state.currentIndex === index,
259
- isSingleSelection: true,
260
- isDisabled: disabled,
261
- textWrap: "wrap",
262
- onClick: function onClick() {
263
- return _this2.itemClicked(value);
264
- },
265
- onKeyDown: _this2.onItemKeyDown,
266
- ref: function ref(node) {
267
- return _this2.setItemNode(node, index);
268
- },
269
- "aria-selected": valueOfSelected === value
270
- }, optionRest), dropdownDisplay || inputDisplay);
271
- });
272
- 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;
273
- return (0, _react2.jsx)(_services.RenderWithEuiStylesMemoizer, null, function (stylesMemoizer) {
274
- var styles = stylesMemoizer(_super_select.euiSuperSelectStyles);
275
- return (0, _react2.jsx)(_popover.EuiInputPopover, (0, _extends2.default)({
276
- closePopover: _this2.closePopover,
277
- panelPaddingSize: "none"
278
- }, popoverProps, {
279
- className: popoverClasses,
280
- isOpen: isOpen || _this2.state.isPopoverOpen,
281
- input: button,
282
- fullWidth: fullWidth,
283
- disableFocusTrap: true // This component handles its own focus manually
284
- }), (0, _react2.jsx)(_accessibility.EuiScreenReaderOnly, null, (0, _react2.jsx)("p", {
285
- id: _this2.describedById
286
- }, (0, _react2.jsx)(_i18n.EuiI18n, {
287
- token: "euiSuperSelect.screenReaderAnnouncement",
288
- 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."
289
- }))), (0, _react2.jsx)(_i18n.EuiI18n, {
290
- token: "euiSuperSelect.ariaLabel",
291
- default: "Select listbox"
292
- }, function (ariaLabel) {
293
- return (0, _react2.jsx)("div", {
294
- "aria-label": ariaLabel,
295
- "aria-describedby": _this2.describedById,
296
- css: styles.euiSuperSelect__listbox,
297
- className: "euiSuperSelect__listbox eui-scrollBar",
298
- role: "listbox",
299
- "aria-activedescendant": ariaActiveDescendant,
300
- tabIndex: 0
301
- }, items);
302
- }));
303
- });
194
+ };
195
+ useMountEffect(function () {
196
+ isMounted.current = true;
197
+ if (isOpen) {
198
+ openPopover();
304
199
  }
305
- }]);
306
- }(_react.Component);
307
- (0, _defineProperty2.default)(EuiSuperSelect, "defaultProps", {
308
- fullWidth: false,
309
- compressed: false,
310
- isInvalid: false,
311
- isLoading: false
312
- });
313
- EuiSuperSelect.propTypes = {
314
- className: _propTypes.default.string,
315
- "aria-label": _propTypes.default.string,
316
- "data-test-subj": _propTypes.default.string,
317
- css: _propTypes.default.any,
318
- buttonRef: _propTypes.default.any,
319
- /**
320
- * @default false
321
- */
322
- compressed: _propTypes.default.bool,
323
- /**
324
- * Expand to fill 100% of the parent.
325
- * Defaults to `fullWidth` prop of `<EuiForm>`.
326
- * @default false
327
- */
328
- fullWidth: _propTypes.default.bool,
329
- /**
330
- * @default false
331
- */
332
- isInvalid: _propTypes.default.bool,
333
- /**
334
- * @default false
335
- */
336
- isLoading: _propTypes.default.bool,
337
- readOnly: _propTypes.default.bool,
338
- name: _propTypes.default.string,
339
- /**
340
- * Placeholder to display when the current selected value is empty.
341
- */
342
- placeholder: _propTypes.default.oneOfType([_propTypes.default.node, _propTypes.default.node]),
343
- /**
344
- * Creates an input group with element(s) coming before input.
345
- * `string` | `ReactElement` or an array of these
346
- */
347
- prepend: _propTypes.default.oneOfType([_propTypes.default.oneOfType([_propTypes.default.string.isRequired, _propTypes.default.element.isRequired]).isRequired, _propTypes.default.arrayOf(_propTypes.default.oneOfType([_propTypes.default.string.isRequired, _propTypes.default.element.isRequired]).isRequired).isRequired]),
348
- /**
349
- * Creates an input group with element(s) coming after input.
350
- * `string` | `ReactElement` or an array of these
351
- */
352
- append: _propTypes.default.oneOfType([_propTypes.default.oneOfType([_propTypes.default.string.isRequired, _propTypes.default.element.isRequired]).isRequired, _propTypes.default.arrayOf(_propTypes.default.oneOfType([_propTypes.default.string.isRequired, _propTypes.default.element.isRequired]).isRequired).isRequired]),
353
- /**
354
- * Pass an array of options that must at least include:
355
- * `value`: storing unique value of item,
356
- * `inputDisplay`: what shows inside the form input when selected
357
- * `dropdownDisplay` (optional): what shows for the item in the dropdown
358
- */
359
- options: _propTypes.default.arrayOf(_propTypes.default.shape({
360
- value: _propTypes.default.any.isRequired,
361
- inputDisplay: _propTypes.default.node,
362
- dropdownDisplay: _propTypes.default.node,
363
- disabled: _propTypes.default.bool,
364
- "data-test-subj": _propTypes.default.string
365
- }).isRequired).isRequired,
366
- valueOfSelected: _propTypes.default.any,
367
- /**
368
- * Classes for the context menu item
369
- */
370
- itemClassName: _propTypes.default.string,
371
- /**
372
- * You must pass an `onChange` function to handle the update of the value
373
- */
374
- onChange: _propTypes.default.func,
375
- onFocus: _propTypes.default.func,
376
- onBlur: _propTypes.default.func,
377
- /**
378
- * Controls whether the options are shown. Default: false
379
- */
380
- isOpen: _propTypes.default.bool,
381
- /**
382
- * Optional props to pass to the underlying [EuiInputPopover](https://eui.elastic.co/docs/components/containers/popover/).
383
- * Allows fine-grained control of the popover dropdown menu, including
384
- * `repositionOnScroll` for EuiSuperSelects used within scrollable containers,
385
- * and customizing popover panel styling.
386
- *
387
- * Does not accept a nested `popoverProps.isOpen` property - use the top level
388
- * `isOpen` API instead.
389
- */
390
- popoverProps: _propTypes.default.any
391
- };
200
+ return function () {
201
+ isMounted.current = false;
202
+ };
203
+ // The class lifecycle this replaces only ran when the component mounted.
204
+ // eslint-disable-next-line react-hooks/exhaustive-deps
205
+ }, []);
206
+ var popoverClasses = (0, _classnames.default)('euiSuperSelect', popoverProps === null || popoverProps === void 0 ? void 0 : popoverProps.className);
207
+ var button = (0, _react2.jsx)(_super_select_control.EuiSuperSelectControl, (0, _extends2.default)({
208
+ options: options,
209
+ value: valueOfSelected,
210
+ placeholder: placeholder,
211
+ onClick: isPopoverOpen ? closePopover : openPopover,
212
+ onKeyDown: onSelectKeyDown,
213
+ onFocus: onFocus,
214
+ onBlur: onBlur,
215
+ className: className,
216
+ fullWidth: fullWidth,
217
+ isInvalid: isInvalid,
218
+ compressed: compressed,
219
+ isLoading: isLoading
220
+ }, rest, {
221
+ buttonRef: controlButtonRef,
222
+ isDropdownOpen: isPopoverOpen
223
+ }));
224
+ var items = options.map(function (option, index) {
225
+ var value = option.value,
226
+ dropdownDisplay = option.dropdownDisplay,
227
+ inputDisplay = option.inputDisplay,
228
+ disabled = option.disabled,
229
+ optionRest = (0, _objectWithoutProperties2.default)(option, _excluded2);
230
+ if (value == null) return;
231
+ return (0, _react2.jsx)(_super_select_item.EuiSuperSelectItem, (0, _extends2.default)({
232
+ key: index
233
+ /* NOTE: This should rather use "li" to align select-like behavior. But the current
234
+ implementation relies on the interactive and focusable item for the navigation.
235
+ This will require additional refactoring to adjust but we might want to decide first
236
+ if the effort is worth it, considering the unification plans for selection components
237
+ as part of OneSelect (https://github.com/elastic/eui/issues/8808).
238
+ */,
239
+ element: "button",
240
+ id: String(value),
241
+ className: itemClassName,
242
+ checked: valueOfSelected === value ? 'on' : undefined,
243
+ isSelected: valueOfSelected === value,
244
+ isFocused: currentIndex === index,
245
+ isSingleSelection: true,
246
+ isDisabled: disabled,
247
+ textWrap: "wrap",
248
+ onClick: function onClick() {
249
+ return itemClicked(value);
250
+ },
251
+ onKeyDown: onItemKeyDown,
252
+ ref: function ref(node) {
253
+ return setItemNode(node, index);
254
+ },
255
+ "aria-selected": valueOfSelected === value
256
+ }, optionRest), dropdownDisplay || inputDisplay);
257
+ });
258
+ var ariaActiveDescendant = ((_options$currentIndex = options[currentIndex]) === null || _options$currentIndex === void 0 ? void 0 : _options$currentIndex.value) != null ? String(options[currentIndex].value) : undefined;
259
+ return (0, _react2.jsx)(_popover.EuiInputPopover, (0, _extends2.default)({
260
+ closePopover: closePopover,
261
+ panelPaddingSize: "none"
262
+ }, popoverProps, {
263
+ className: popoverClasses,
264
+ isOpen: isOpen || isPopoverOpen,
265
+ input: button,
266
+ fullWidth: fullWidth,
267
+ disableFocusTrap: true // This component handles its own focus manually
268
+ }), (0, _react2.jsx)(_accessibility.EuiScreenReaderOnly, null, (0, _react2.jsx)("p", {
269
+ id: describedById
270
+ }, (0, _react2.jsx)(_i18n.EuiI18n, {
271
+ token: "euiSuperSelect.screenReaderAnnouncement",
272
+ 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."
273
+ }))), (0, _react2.jsx)(_i18n.EuiI18n, {
274
+ token: "euiSuperSelect.ariaLabel",
275
+ default: "Select listbox"
276
+ }, function (ariaLabel) {
277
+ return (0, _react2.jsx)("div", {
278
+ "aria-label": ariaLabel,
279
+ "aria-describedby": describedById,
280
+ css: styles.euiSuperSelect__listbox,
281
+ className: "euiSuperSelect__listbox eui-scrollBar",
282
+ role: "listbox",
283
+ "aria-activedescendant": ariaActiveDescendant,
284
+ tabIndex: 0
285
+ }, items);
286
+ }));
287
+ };
288
+ var EuiSuperSelect = exports.EuiSuperSelect = /*#__PURE__*/(0, _react.forwardRef)(EuiSuperSelectInner);
289
+ EuiSuperSelect.displayName = 'EuiSuperSelect';
@@ -427,6 +427,18 @@ EuiListItemLayout.propTypes = {
427
427
  "data-test-subj": _propTypes.default.string,
428
428
  css: _propTypes.default.any
429
429
  }),
430
+ /**
431
+ * Props applied to the label text element.
432
+ */
433
+ /**
434
+ * Props applied to the label text element.
435
+ */
436
+ /**
437
+ * Props applied to the label text element.
438
+ */
439
+ /**
440
+ * Props applied to the label text element.
441
+ */
430
442
  textProps: _propTypes.default.shape({
431
443
  className: _propTypes.default.string,
432
444
  "aria-label": _propTypes.default.string,