@elastic/eui 88.5.2 → 88.5.4

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 (23) hide show
  1. package/es/components/collapsible_nav_beta/collapsible_nav_beta.js +12 -2
  2. package/es/components/combo_box/combo_box_input/combo_box_input.js +38 -41
  3. package/es/components/popover/input_popover.js +79 -59
  4. package/es/components/text_truncate/text_truncate.js +5 -2
  5. package/eui.d.ts +64 -65
  6. package/i18ntokens.json +4 -4
  7. package/lib/components/collapsible_nav_beta/collapsible_nav_beta.js +11 -1
  8. package/lib/components/combo_box/combo_box_input/combo_box_input.js +38 -41
  9. package/lib/components/popover/input_popover.js +77 -58
  10. package/lib/components/text_truncate/text_truncate.js +5 -2
  11. package/optimize/es/components/collapsible_nav_beta/collapsible_nav_beta.js +12 -2
  12. package/optimize/es/components/combo_box/combo_box_input/combo_box_input.js +36 -39
  13. package/optimize/es/components/popover/input_popover.js +76 -59
  14. package/optimize/es/components/text_truncate/text_truncate.js +5 -2
  15. package/optimize/lib/components/collapsible_nav_beta/collapsible_nav_beta.js +11 -1
  16. package/optimize/lib/components/combo_box/combo_box_input/combo_box_input.js +36 -39
  17. package/optimize/lib/components/popover/input_popover.js +75 -58
  18. package/optimize/lib/components/text_truncate/text_truncate.js +5 -2
  19. package/package.json +6 -5
  20. package/test-env/components/collapsible_nav_beta/collapsible_nav_beta.js +11 -1
  21. package/test-env/components/combo_box/combo_box_input/combo_box_input.js +38 -41
  22. package/test-env/components/popover/input_popover.js +75 -58
  23. package/test-env/components/text_truncate/text_truncate.js +5 -2
@@ -107,56 +107,51 @@ var EuiComboBoxInput = /*#__PURE__*/function (_Component) {
107
107
  }
108
108
  }
109
109
  });
110
- (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "inputOnChange", function (event) {
111
- var _this$props$onChange, _this$props3;
112
- var value = event.target.value;
113
- _this.updateInputSize(value);
114
- (_this$props$onChange = (_this$props3 = _this.props).onChange) === null || _this$props$onChange === void 0 ? void 0 : _this$props$onChange.call(_this$props3, value);
115
- });
116
110
  return _this;
117
111
  }
118
112
  (0, _createClass2.default)(EuiComboBoxInput, [{
119
113
  key: "componentDidUpdate",
120
114
  value: function componentDidUpdate(prevProps) {
121
- var searchValue = prevProps.searchValue;
115
+ if (prevProps.searchValue !== this.props.searchValue) {
116
+ this.updateInputSize(this.props.searchValue);
122
117
 
123
- // We need to update the position of everything if the user enters enough input to change
124
- // the size of the input.
125
- if (searchValue !== this.props.searchValue) {
118
+ // We need to update the position of everything if the user enters enough input to change
119
+ // the size of the input.
126
120
  this.updatePosition();
127
121
  }
128
122
  }
129
123
  }, {
130
124
  key: "render",
131
125
  value: function render() {
132
- var _this$props4 = this.props,
133
- compressed = _this$props4.compressed,
134
- focusedOptionId = _this$props4.focusedOptionId,
135
- fullWidth = _this$props4.fullWidth,
136
- hasSelectedOptions = _this$props4.hasSelectedOptions,
137
- id = _this$props4.id,
138
- isDisabled = _this$props4.isDisabled,
139
- isListOpen = _this$props4.isListOpen,
140
- noIcon = _this$props4.noIcon,
141
- onClear = _this$props4.onClear,
142
- onClick = _this$props4.onClick,
143
- onCloseListClick = _this$props4.onCloseListClick,
144
- onOpenListClick = _this$props4.onOpenListClick,
145
- onRemoveOption = _this$props4.onRemoveOption,
146
- placeholder = _this$props4.placeholder,
147
- rootId = _this$props4.rootId,
148
- searchValue = _this$props4.searchValue,
149
- selectedOptions = _this$props4.selectedOptions,
150
- singleSelectionProp = _this$props4.singleSelection,
151
- toggleButtonRef = _this$props4.toggleButtonRef,
152
- value = _this$props4.value,
153
- prepend = _this$props4.prepend,
154
- append = _this$props4.append,
155
- isLoading = _this$props4.isLoading,
156
- isInvalid = _this$props4.isInvalid,
157
- autoFocus = _this$props4.autoFocus,
158
- ariaLabel = _this$props4['aria-label'],
159
- ariaLabelledby = _this$props4['aria-labelledby'];
126
+ var _this$props3 = this.props,
127
+ compressed = _this$props3.compressed,
128
+ focusedOptionId = _this$props3.focusedOptionId,
129
+ fullWidth = _this$props3.fullWidth,
130
+ hasSelectedOptions = _this$props3.hasSelectedOptions,
131
+ id = _this$props3.id,
132
+ isDisabled = _this$props3.isDisabled,
133
+ isListOpen = _this$props3.isListOpen,
134
+ noIcon = _this$props3.noIcon,
135
+ _onChange = _this$props3.onChange,
136
+ onClear = _this$props3.onClear,
137
+ onClick = _this$props3.onClick,
138
+ onCloseListClick = _this$props3.onCloseListClick,
139
+ onOpenListClick = _this$props3.onOpenListClick,
140
+ onRemoveOption = _this$props3.onRemoveOption,
141
+ placeholder = _this$props3.placeholder,
142
+ rootId = _this$props3.rootId,
143
+ searchValue = _this$props3.searchValue,
144
+ selectedOptions = _this$props3.selectedOptions,
145
+ singleSelectionProp = _this$props3.singleSelection,
146
+ toggleButtonRef = _this$props3.toggleButtonRef,
147
+ value = _this$props3.value,
148
+ prepend = _this$props3.prepend,
149
+ append = _this$props3.append,
150
+ isLoading = _this$props3.isLoading,
151
+ isInvalid = _this$props3.isInvalid,
152
+ autoFocus = _this$props3.autoFocus,
153
+ ariaLabel = _this$props3['aria-label'],
154
+ ariaLabelledby = _this$props3['aria-labelledby'];
160
155
  var singleSelection = Boolean(singleSelectionProp);
161
156
  var asPlainText = singleSelectionProp && (0, _typeof2.default)(singleSelectionProp) === 'object' && singleSelectionProp.asPlainText || false;
162
157
  var pills = selectedOptions ? selectedOptions.map(function (option) {
@@ -261,7 +256,9 @@ var EuiComboBoxInput = /*#__PURE__*/function (_Component) {
261
256
  disabled: isDisabled,
262
257
  id: id,
263
258
  onBlur: this.onBlur,
264
- onChange: this.inputOnChange,
259
+ onChange: function onChange(event) {
260
+ return _onChange(event.target.value);
261
+ },
265
262
  onFocus: this.onFocus,
266
263
  onKeyDown: this.onKeyDown,
267
264
  ref: this.inputRefCallback,
@@ -288,9 +285,9 @@ EuiComboBoxInput.propTypes = {
288
285
  isListOpen: _propTypes.default.bool.isRequired,
289
286
  noIcon: _propTypes.default.bool.isRequired,
290
287
  onBlur: _propTypes.default.any,
291
- onChange: _propTypes.default.func,
288
+ onChange: _propTypes.default.func.isRequired,
292
289
  onClear: _propTypes.default.func,
293
- onClick: _propTypes.default.func,
290
+ onClick: _propTypes.default.func.isRequired,
294
291
  onCloseListClick: _propTypes.default.func.isRequired,
295
292
  onFocus: _propTypes.default.any.isRequired,
296
293
  onOpenListClick: _propTypes.default.func.isRequired,
@@ -7,20 +7,21 @@ Object.defineProperty(exports, "__esModule", {
7
7
  });
8
8
  exports.EuiInputPopover = void 0;
9
9
  var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
10
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
10
11
  var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
11
12
  var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
12
13
  var _react = _interopRequireWildcard(require("react"));
13
14
  var _propTypes = _interopRequireDefault(require("prop-types"));
15
+ var _react2 = require("@emotion/react");
14
16
  var _classnames = _interopRequireDefault(require("classnames"));
15
17
  var _tabbable = require("tabbable");
16
- var _focus_trap = require("../focus_trap");
17
- var _popover = require("./popover");
18
- var _resize_observer = require("../observer/resize_observer");
18
+ var _global_styling = require("../../global_styling");
19
19
  var _services = require("../../services");
20
+ var _resize_observer = require("../observer/resize_observer");
21
+ var _focus_trap = require("../focus_trap");
20
22
  var _form = require("../form/form.styles");
21
- var _react2 = require("@emotion/react");
22
- var _global_styling = require("../../global_styling");
23
- var _excluded = ["children", "className", "disableFocusTrap", "focusTrapProps", "input", "fullWidth", "panelMinWidth", "onPanelResize", "inputRef", "panelRef"];
23
+ var _popover = require("./popover");
24
+ var _excluded = ["children", "className", "closePopover", "disableFocusTrap", "focusTrapProps", "input", "fullWidth", "panelMinWidth", "onPanelResize", "inputRef", "panelRef"];
24
25
  /*
25
26
  * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
26
27
  * or more contributor license agreements. Licensed under the Elastic License
@@ -30,9 +31,13 @@ var _excluded = ["children", "className", "disableFocusTrap", "focusTrapProps",
30
31
  */
31
32
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
32
33
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
34
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
35
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
33
36
  var EuiInputPopover = function EuiInputPopover(_ref) {
37
+ var _props$panelProps;
34
38
  var children = _ref.children,
35
39
  className = _ref.className,
40
+ closePopover = _ref.closePopover,
36
41
  _ref$disableFocusTrap = _ref.disableFocusTrap,
37
42
  disableFocusTrap = _ref$disableFocusTrap === void 0 ? false : _ref$disableFocusTrap,
38
43
  focusTrapProps = _ref.focusTrapProps,
@@ -45,80 +50,92 @@ var EuiInputPopover = function EuiInputPopover(_ref) {
45
50
  _inputRef = _ref.inputRef,
46
51
  _panelRef = _ref.panelRef,
47
52
  props = (0, _objectWithoutProperties2.default)(_ref, _excluded);
48
- var euiThemeContext = (0, _services.useEuiTheme)();
53
+ var classes = (0, _classnames.default)('euiInputPopover', className);
54
+ var euiTheme = (0, _services.useEuiTheme)();
55
+ var form = (0, _form.euiFormVariables)(euiTheme);
56
+
57
+ /**
58
+ * Ref setup
59
+ */
60
+
61
+ var popoverClassRef = (0, _react.useRef)(null);
62
+ // The inputEl state ensures that width is correctly tracked on initial load
49
63
  var _useState = (0, _react.useState)(null),
50
64
  _useState2 = (0, _slicedToArray2.default)(_useState, 2),
51
65
  inputEl = _useState2[0],
52
66
  setInputEl = _useState2[1];
53
- var _useState3 = (0, _react.useState)(),
67
+ // The panelEl state ensures that width is correctly set every time the popover opens
68
+ var _useState3 = (0, _react.useState)(null),
54
69
  _useState4 = (0, _slicedToArray2.default)(_useState3, 2),
55
- inputElWidth = _useState4[0],
56
- setInputElWidth = _useState4[1];
57
- var _useState5 = (0, _react.useState)(null),
58
- _useState6 = (0, _slicedToArray2.default)(_useState5, 2),
59
- panelEl = _useState6[0],
60
- setPanelEl = _useState6[1];
61
- var popoverClassRef = (0, _react.useRef)(null);
70
+ panelEl = _useState4[0],
71
+ setPanelEl = _useState4[1];
62
72
  var inputRef = (0, _services.useCombinedRefs)([setInputEl, _inputRef]);
63
73
  var panelRef = (0, _services.useCombinedRefs)([setPanelEl, _panelRef]);
64
- var setPanelWidth = (0, _react.useCallback)(function (width) {
65
- if (panelEl && (!!inputElWidth || !!width)) {
66
- var newWidth = !!width ? width : inputElWidth;
67
- var widthToSet = newWidth && newWidth > panelMinWidth ? newWidth : panelMinWidth;
68
- panelEl.style.width = "".concat(widthToSet, "px");
69
- onPanelResize === null || onPanelResize === void 0 ? void 0 : onPanelResize(widthToSet);
74
+
75
+ /**
76
+ * Sizing/width logic
77
+ */
78
+
79
+ var inputWidth = (0, _resize_observer.useResizeObserver)(inputEl, 'width').width;
80
+ var panelWidth = (0, _react.useMemo)(function () {
81
+ return inputWidth < panelMinWidth ? panelMinWidth : inputWidth;
82
+ }, [panelMinWidth, inputWidth]);
83
+ (0, _react.useEffect)(function () {
84
+ if (panelEl) {
85
+ // We have to modify the popover panel DOM node directly instead of using
86
+ // `panelStyle`, as there's some weird positioning bugs on resize otherwise
87
+ panelEl.style.inlineSize = "".concat(panelWidth, "px");
70
88
  }
71
- }, [panelEl, inputElWidth, onPanelResize, panelMinWidth]);
72
- var onResize = (0, _react.useCallback)(function () {
73
- if (inputEl) {
89
+ }, [panelEl, panelWidth]);
90
+ (0, _react.useEffect)(function () {
91
+ // This fires on all input width changes regardless of minimum size, because on
92
+ // right/center anchored popovers, the input width affects the position of the popover
93
+ if (panelEl) {
74
94
  var _popoverClassRef$curr;
75
- var _width = inputEl.getBoundingClientRect().width;
76
- setInputElWidth(_width);
77
- setPanelWidth(_width);
78
95
  (_popoverClassRef$curr = popoverClassRef.current) === null || _popoverClassRef$curr === void 0 ? void 0 : _popoverClassRef$curr.positionPopoverFluid();
79
96
  }
80
- }, [inputEl, setPanelWidth]);
81
- (0, _react.useEffect)(function () {
82
- onResize();
83
- }, [onResize]);
84
- (0, _react.useEffect)(function () {
85
- setPanelWidth();
86
- }, [setPanelWidth]);
87
- var onKeyDown = function onKeyDown(event) {
88
- if (panelEl && event.key === _services.cascadingMenuKeys.TAB) {
89
- var tabbableItems = (0, _tabbable.tabbable)(panelEl).filter(function (el) {
90
- return Array.from(el.attributes).map(function (el) {
91
- return el.name;
92
- }).indexOf('data-focus-guard') < 0;
93
- });
94
- if (disableFocusTrap || tabbableItems.length && tabbableItems[tabbableItems.length - 1] === document.activeElement) {
95
- props.closePopover();
97
+ }, [inputWidth, panelEl]);
98
+
99
+ /**
100
+ * Popover tab to close logic
101
+ */
102
+
103
+ var panelPropsOnKeyDown = (_props$panelProps = props.panelProps) === null || _props$panelProps === void 0 ? void 0 : _props$panelProps.onKeyDown;
104
+ var onKeyDown = (0, _react.useCallback)(function (event) {
105
+ panelPropsOnKeyDown === null || panelPropsOnKeyDown === void 0 ? void 0 : panelPropsOnKeyDown(event);
106
+ if (event.key === _services.keys.TAB) {
107
+ if (disableFocusTrap) {
108
+ closePopover();
109
+ } else {
110
+ var tabbableItems = (0, _tabbable.tabbable)(event.currentTarget).filter(function (el) {
111
+ return !el.hasAttribute('data-focus-guard');
112
+ });
113
+ if (!tabbableItems.length) return;
114
+ var tabbingFromLastItemInPopover = document.activeElement === tabbableItems[tabbableItems.length - 1];
115
+ if (tabbingFromLastItemInPopover) {
116
+ closePopover();
117
+ }
96
118
  }
97
119
  }
98
- };
99
- var classes = (0, _classnames.default)('euiInputPopover', className);
100
- var form = (0, _form.euiFormVariables)(euiThemeContext);
120
+ }, [disableFocusTrap, closePopover, panelPropsOnKeyDown]);
101
121
  return (0, _react2.jsx)(_popover.EuiPopover, (0, _extends2.default)({
102
122
  css: /*#__PURE__*/(0, _react2.css)(fullWidth ? undefined : (0, _global_styling.logicalCSS)('max-width', form.maxWidth), ";label:EuiInputPopover;"),
103
123
  repositionToCrossAxis: false,
104
124
  ownFocus: false,
105
- button: (0, _react2.jsx)(_resize_observer.EuiResizeObserver, {
106
- onResize: onResize
107
- }, function (resizeRef) {
108
- return (0, _react2.jsx)("div", {
109
- ref: resizeRef
110
- }, input);
111
- }),
125
+ button: input,
112
126
  buttonRef: inputRef,
113
127
  panelRef: panelRef,
114
128
  className: classes,
115
- ref: popoverClassRef
116
- }, props), (0, _react2.jsx)(_focus_trap.EuiFocusTrap, (0, _extends2.default)({
129
+ ref: popoverClassRef,
130
+ closePopover: closePopover
131
+ }, props, {
132
+ panelProps: _objectSpread(_objectSpread({}, props.panelProps), {}, {
133
+ onKeyDown: onKeyDown
134
+ })
135
+ }), (0, _react2.jsx)(_focus_trap.EuiFocusTrap, (0, _extends2.default)({
117
136
  clickOutsideDisables: true,
118
137
  disabled: disableFocusTrap
119
- }, focusTrapProps), (0, _react2.jsx)("div", {
120
- onKeyDown: onKeyDown
121
- }, children)));
138
+ }, focusTrapProps), children));
122
139
  };
123
140
  exports.EuiInputPopover = EuiInputPopover;
124
141
  EuiInputPopover.propTypes = {
@@ -17,7 +17,7 @@ var _resize_observer = require("../observer/resize_observer");
17
17
  var _utils = require("./utils");
18
18
  var _text_truncate = require("./text_truncate.styles");
19
19
  var _react2 = require("@emotion/react");
20
- var _excluded = ["width"],
20
+ var _excluded = ["width", "onResize"],
21
21
  _excluded2 = ["width", "children", "text", "truncation", "truncationOffset", "truncationPosition", "ellipsis", "containerRef", "className"],
22
22
  _excluded3 = ["onResize"];
23
23
  /*
@@ -32,10 +32,13 @@ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj &&
32
32
  var TRUNCATION_TYPES = ['end', 'start', 'startEnd', 'middle'];
33
33
  var EuiTextTruncate = function EuiTextTruncate(_ref) {
34
34
  var width = _ref.width,
35
+ onResize = _ref.onResize,
35
36
  props = (0, _objectWithoutProperties2.default)(_ref, _excluded);
36
37
  return width != null ? (0, _react2.jsx)(EuiTextTruncateWithWidth, (0, _extends2.default)({
37
38
  width: width
38
- }, props)) : (0, _react2.jsx)(EuiTextTruncateWithResizeObserver, props);
39
+ }, props)) : (0, _react2.jsx)(EuiTextTruncateWithResizeObserver, (0, _extends2.default)({
40
+ onResize: onResize
41
+ }, props));
39
42
  };
40
43
  exports.EuiTextTruncate = EuiTextTruncate;
41
44
  EuiTextTruncate.propTypes = {