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