@jetbrains/ring-ui-built 6.0.38 → 6.0.40

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.
@@ -42,5 +42,6 @@ export default class Checkbox extends PureComponent<CheckboxProps> {
42
42
  componentDidUpdate(prevProps: CheckboxProps): void;
43
43
  input?: HTMLInputElement | null;
44
44
  inputRef: (el: HTMLInputElement | null) => void;
45
+ composedInputRef: import("memoize-one").MemoizedFn<(...refs: (Ref<HTMLInputElement> | undefined)[]) => (value: HTMLInputElement | null) => void>;
45
46
  render(): import("react").JSX.Element;
46
47
  }
@@ -7,7 +7,7 @@ import checkmarkIcon from '@jetbrains/icons/checkmark-12px';
7
7
  import minusIcon from '@jetbrains/icons/remove-12px';
8
8
  import Icon from '../icon/icon.js';
9
9
  import { refObject } from '../global/prop-types.js';
10
- import composeRefs from '../global/composeRefs.js';
10
+ import { createComposedRef } from '../global/composeRefs.js';
11
11
  import ControlHelp from '../control-help/control-help.js';
12
12
  import { jsxs, jsx } from 'react/jsx-runtime';
13
13
  import 'util-deprecate';
@@ -43,6 +43,7 @@ var Checkbox = /*#__PURE__*/function (_PureComponent) {
43
43
  }
44
44
  _this.input = el;
45
45
  });
46
+ _defineProperty(_this, "composedInputRef", createComposedRef());
46
47
  return _this;
47
48
  }
48
49
  _inherits(Checkbox, _PureComponent);
@@ -86,7 +87,7 @@ var Checkbox = /*#__PURE__*/function (_PureComponent) {
86
87
  "data-test": "ring-checkbox",
87
88
  children: [/*#__PURE__*/jsx("input", _objectSpread2(_objectSpread2({}, restProps), {}, {
88
89
  "data-checked": restProps.checked,
89
- ref: composeRefs(this.inputRef, inputRef),
90
+ ref: this.composedInputRef(this.inputRef, inputRef),
90
91
  type: "checkbox",
91
92
  className: classes
92
93
  })), /*#__PURE__*/jsx("div", {
@@ -19,6 +19,7 @@ import '../global/composeRefs.js';
19
19
  import 'core-js/modules/es.object.to-string.js';
20
20
  import 'core-js/modules/web.dom-collections.for-each.js';
21
21
  import 'memoize-one';
22
+ import 'util-deprecate';
22
23
  import '../table/selection.js';
23
24
  import 'core-js/modules/es.array.filter.js';
24
25
  import 'core-js/modules/es.array.index-of.js';
@@ -55,7 +56,6 @@ import '../loader-inline/loader-inline.js';
55
56
  import '../button/button.js';
56
57
  import '@jetbrains/icons/chevron-10px';
57
58
  import '../icon/icon.js';
58
- import 'util-deprecate';
59
59
  import '../icon/icon__constants.js';
60
60
  import '../_helpers/icon__svg.js';
61
61
  import 'core-js/modules/es.string.replace.js';
@@ -13,10 +13,10 @@ import '../global/composeRefs.js';
13
13
  import 'core-js/modules/es.object.to-string.js';
14
14
  import 'core-js/modules/web.dom-collections.for-each.js';
15
15
  import 'memoize-one';
16
+ import 'util-deprecate';
16
17
  import '@jetbrains/icons/checkmark-12px';
17
18
  import '@jetbrains/icons/remove-12px';
18
19
  import '../icon/icon.js';
19
- import 'util-deprecate';
20
20
  import '../icon/icon__constants.js';
21
21
  import '../_helpers/icon__svg.js';
22
22
  import 'core-js/modules/es.regexp.exec.js';
@@ -35,6 +35,7 @@ export default class DateInput extends React.PureComponent<DateInputProps> {
35
35
  onClear: PropTypes.Requireable<(...args: any[]) => any>;
36
36
  locale: PropTypes.Requireable<object>;
37
37
  };
38
+ componentDidMount(): void;
38
39
  componentDidUpdate(prevProps: DateInputProps): void;
39
40
  static contextType: React.Context<import("../i18n/i18n-context").I18nContextProps>;
40
41
  context: React.ContextType<typeof DateInput.contextType>;
@@ -54,7 +54,6 @@ var DateInput = /*#__PURE__*/function (_React$PureComponent) {
54
54
  _defineProperty(_this, "input", void 0);
55
55
  _defineProperty(_this, "inputRef", function (el) {
56
56
  _this.input = el;
57
- _this.updateInput(_this.props);
58
57
  });
59
58
  _defineProperty(_this, "handleChange", function (e) {
60
59
  return _this.props.onInput(e.currentTarget.value, e.currentTarget.dataset.name);
@@ -66,6 +65,11 @@ var DateInput = /*#__PURE__*/function (_React$PureComponent) {
66
65
  }
67
66
  _inherits(DateInput, _React$PureComponent);
68
67
  return _createClass(DateInput, [{
68
+ key: "componentDidMount",
69
+ value: function componentDidMount() {
70
+ this.updateInput(this.props);
71
+ }
72
+ }, {
69
73
  key: "componentDidUpdate",
70
74
  value: function componentDidUpdate(prevProps) {
71
75
  var _this$props = this.props,
@@ -132,6 +132,7 @@ var PopupComponent = function PopupComponent(_ref) {
132
132
  ref: popupRef,
133
133
  directions: [Popup.PopupProps.Directions.BOTTOM_RIGHT, Popup.PopupProps.Directions.BOTTOM_LEFT, Popup.PopupProps.Directions.TOP_LEFT, Popup.PopupProps.Directions.TOP_RIGHT]
134
134
  }, restProps), {}, {
135
+ trapFocus: true,
135
136
  children: /*#__PURE__*/jsx(DatePopup, _objectSpread2(_objectSpread2({
136
137
  onClear: onClear
137
138
  }, datePopupProps), {}, {
@@ -1,3 +1,5 @@
1
1
  import { Ref } from 'react';
2
- export default function composeRefs<T>(...refs: (Ref<T> | undefined)[]): (value: T | null) => void;
2
+ declare function composeRefs<T>(...refs: (Ref<T> | undefined)[]): (value: T | null) => void;
3
+ declare const _default: typeof composeRefs;
4
+ export default _default;
3
5
  export declare function createComposedRef<T>(): import("memoize-one").MemoizedFn<(...refs: (Ref<T> | undefined)[]) => (value: T | null) => void>;
@@ -1,6 +1,7 @@
1
1
  import 'core-js/modules/es.object.to-string.js';
2
2
  import 'core-js/modules/web.dom-collections.for-each.js';
3
3
  import memoizeOne from 'memoize-one';
4
+ import deprecate from 'util-deprecate';
4
5
 
5
6
  function composeRefs() {
6
7
  for (var _len = arguments.length, refs = new Array(_len), _key = 0; _key < _len; _key++) {
@@ -16,8 +17,10 @@ function composeRefs() {
16
17
  });
17
18
  };
18
19
  }
20
+ // TODO remove export in 7.0, composeRefs should be used only in createComposedRef and in useComposedRefs in the future
21
+ var composeRefs$1 = deprecate(composeRefs, 'composeRefs is deprecated and will be removed in 7.0. Use createComposedRef instead.');
19
22
  function createComposedRef() {
20
23
  return memoizeOne(composeRefs);
21
24
  }
22
25
 
23
- export { createComposedRef, composeRefs as default };
26
+ export { createComposedRef, composeRefs$1 as default };
@@ -3,11 +3,12 @@ import 'core-js/modules/es.array.concat.js';
3
3
  import { Component } from 'react';
4
4
  import PropTypes from 'prop-types';
5
5
  import { refObject } from './prop-types.js';
6
- import composeRefs from './composeRefs.js';
6
+ import { createComposedRef } from './composeRefs.js';
7
7
  import { jsx } from 'react/jsx-runtime';
8
8
  import 'core-js/modules/es.object.to-string.js';
9
9
  import 'core-js/modules/web.dom-collections.for-each.js';
10
10
  import 'memoize-one';
11
+ import 'util-deprecate';
11
12
 
12
13
  var _excluded = ["innerRef", "focused", "onFocusReset", "onFocusRestore"],
13
14
  _excluded2 = ["autofocus", "focused", "onFocus", "onBlur", "innerRef", "scrollOnTableFocus"];
@@ -42,6 +43,7 @@ function focusSensorHOC(ComposedComponent) {
42
43
  _this.node = node;
43
44
  }
44
45
  });
46
+ _defineProperty(_this, "composedRef", createComposedRef());
45
47
  _defineProperty(_this, "onFocusCapture", function (_ref2) {
46
48
  var _this$node;
47
49
  var target = _ref2.target;
@@ -137,7 +139,7 @@ function focusSensorHOC(ComposedComponent) {
137
139
  _this$props4.scrollOnTableFocus;
138
140
  var rest = _objectWithoutProperties(_this$props4, _excluded2);
139
141
  return /*#__PURE__*/jsx(ComposedComponent, _objectSpread2(_objectSpread2({}, rest), {}, {
140
- innerRef: composeRefs(innerRef, this.onRefUpdate),
142
+ innerRef: this.composedRef(innerRef, this.onRefUpdate),
141
143
  focused: this.state.focused,
142
144
  onFocusReset: this.onFocusReset,
143
145
  onFocusRestore: this.onFocusRestore
@@ -1,11 +1,12 @@
1
1
  import { a as _inherits, b as _createClass, d as _objectSpread2, e as _classCallCheck, f as _callSuper, _ as _defineProperty } from '../_helpers/_rollupPluginBabelHelpers.js';
2
2
  import 'core-js/modules/es.array.concat.js';
3
3
  import { forwardRef, Component } from 'react';
4
- import composeRefs from './composeRefs.js';
4
+ import { createComposedRef } from './composeRefs.js';
5
5
  import { jsx } from 'react/jsx-runtime';
6
6
  import 'core-js/modules/es.object.to-string.js';
7
7
  import 'core-js/modules/web.dom-collections.for-each.js';
8
8
  import 'memoize-one';
9
+ import 'util-deprecate';
9
10
 
10
11
  function rerenderHOC(ComposedComponent) {
11
12
  var Rerenderer = /*#__PURE__*/function (_Component) {
@@ -17,6 +18,7 @@ function rerenderHOC(ComposedComponent) {
17
18
  }
18
19
  _this = _callSuper(this, Rerenderer, [].concat(args));
19
20
  _defineProperty(_this, "state", _this.props.props);
21
+ _defineProperty(_this, "composedRef", createComposedRef());
20
22
  return _this;
21
23
  }
22
24
  _inherits(Rerenderer, _Component);
@@ -24,7 +26,7 @@ function rerenderHOC(ComposedComponent) {
24
26
  key: "render",
25
27
  value: function render() {
26
28
  var _this2 = this;
27
- var _ref = composeRefs(this.props.forwardedRef);
29
+ var _ref = this.composedRef(this.props.forwardedRef);
28
30
  return /*#__PURE__*/jsx(ComposedComponent, _objectSpread2(_objectSpread2({}, this.state), {}, {
29
31
  ref: function ref(instance) {
30
32
  return _ref(instance != null ? _objectSpread2(_objectSpread2({}, instance), {}, {
@@ -38,8 +38,8 @@ import '@jetbrains/icons/remove-12px';
38
38
  import '../global/prop-types.js';
39
39
  import '../global/composeRefs.js';
40
40
  import 'memoize-one';
41
- import '../control-help/control-help.js';
42
41
  import 'util-deprecate';
42
+ import '../control-help/control-help.js';
43
43
  import '../icon/icon__constants.js';
44
44
  import '../_helpers/icon__svg.js';
45
45
  import 'core-js/modules/es.string.starts-with.js';
@@ -259,6 +259,7 @@ export default class Select<T = unknown> extends Component<SelectProps<T>, Selec
259
259
  private _getAvatar;
260
260
  filter?: HTMLInputElement | null;
261
261
  filterRef: (el: HTMLInputElement | null) => void;
262
+ composedFilterRef: import("memoize-one").MemoizedFn<(...refs: (Ref<HTMLInputElement> | undefined)[]) => (value: HTMLInputElement | null) => void>;
262
263
  getShortcutsMap(): {
263
264
  enter: () => true | undefined;
264
265
  esc: (event: KeyboardEvent) => boolean | undefined;
@@ -33,7 +33,7 @@ import rerenderHOC from '../global/rerender-hoc.js';
33
33
  import fuzzyHighlight from '../global/fuzzy-highlight.js';
34
34
  import memoize from '../global/memoize.js';
35
35
  import { I18nContext } from '../i18n/i18n-context.js';
36
- import composeRefs from '../global/composeRefs.js';
36
+ import { createComposedRef } from '../global/composeRefs.js';
37
37
  import { refObject } from '../global/prop-types.js';
38
38
  import { isArray } from '../global/typescript-utils.js';
39
39
  import { ControlsHeightContext, ControlsHeight } from '../global/controls-height.js';
@@ -633,6 +633,7 @@ var Select = /*#__PURE__*/function (_Component) {
633
633
  _defineProperty(_this, "filterRef", function (el) {
634
634
  _this.filter = el;
635
635
  });
636
+ _defineProperty(_this, "composedFilterRef", createComposedRef());
636
637
  return _this;
637
638
  }
638
639
  _inherits(Select, _Component);
@@ -1010,7 +1011,7 @@ var Select = /*#__PURE__*/function (_Component) {
1010
1011
  autoComplete: "off",
1011
1012
  id: this.props.id,
1012
1013
  onClick: this._clickHandler,
1013
- inputRef: composeRefs(this.filterRef, this.props.filterRef),
1014
+ inputRef: this.composedFilterRef(this.filterRef, this.props.filterRef),
1014
1015
  disabled: this.props.disabled,
1015
1016
  value: this.state.filterValue,
1016
1017
  borderless: this.props.type === Type.INPUT_WITHOUT_CONTROLS,
@@ -126,6 +126,7 @@ export default class SelectPopup<T = unknown> extends PureComponent<SelectPopupP
126
126
  list?: List<T> | null;
127
127
  listRef: (el: List<T> | null) => void;
128
128
  filterRef: (el: HTMLInputElement | null) => void;
129
+ composedFilterRef: import("memoize-one").MemoizedFn<(...refs: (Ref<HTMLInputElement> | undefined)[]) => (value: HTMLInputElement | null) => void>;
129
130
  shortcutsScope: string;
130
131
  shortcutsMap: {
131
132
  tab: (event: Event) => void;
@@ -27,7 +27,7 @@ import { Button } from '../button/button.js';
27
27
  import Text from '../text/text.js';
28
28
  import { ControlsHeight } from '../global/controls-height.js';
29
29
  import { refObject } from '../global/prop-types.js';
30
- import composeRefs from '../global/composeRefs.js';
30
+ import { createComposedRef } from '../global/composeRefs.js';
31
31
  import { DEFAULT_DIRECTIONS } from '../popup/popup.consts.js';
32
32
  import { S as SelectFilter, m as modules_b607bec2 } from '../_helpers/select__filter.js';
33
33
  import { jsxs, jsx } from 'react/jsx-runtime';
@@ -237,6 +237,7 @@ var SelectPopup = /*#__PURE__*/function (_PureComponent) {
237
237
  _this.filter = el;
238
238
  _this.caret = el && new Caret(el);
239
239
  });
240
+ _defineProperty(_this, "composedFilterRef", createComposedRef());
240
241
  _defineProperty(_this, "shortcutsScope", getUID('select-popup-'));
241
242
  _defineProperty(_this, "shortcutsMap", {
242
243
  tab: _this.tabPress
@@ -396,7 +397,7 @@ var SelectPopup = /*#__PURE__*/function (_PureComponent) {
396
397
  rgShortcutsOptions: this.state.popupFilterShortcutsOptions,
397
398
  rgShortcutsMap: this.popupFilterShortcutsMap,
398
399
  value: this.props.filterValue,
399
- inputRef: composeRefs(this.filterRef, this.props.filterRef),
400
+ inputRef: this.composedFilterRef(this.filterRef, this.props.filterRef),
400
401
  onBlur: this.popupFilterOnBlur,
401
402
  onFocus: this.onFilterFocus,
402
403
  className: "ring-js-shortcuts",
@@ -1,44 +1,18 @@
1
- import { Component, ReactNode, HTMLAttributes } from 'react';
1
+ import { HTMLAttributes, ReactNode } from 'react';
2
2
  import * as React from 'react';
3
- import PropTypes from 'prop-types';
4
3
  export declare const FOCUSABLE_ELEMENTS = "input, button, select, textarea, a[href], *[tabindex]:not([data-trap-button]):not([data-scrollable-container])";
5
4
  export interface TabTrapProps extends HTMLAttributes<HTMLElement> {
6
5
  children: ReactNode;
7
- trapDisabled: boolean;
8
- autoFocusFirst: boolean;
9
- focusBackOnClose: boolean;
10
- focusBackOnExit: boolean;
6
+ trapDisabled?: boolean;
7
+ autoFocusFirst?: boolean;
8
+ focusBackOnClose?: boolean;
9
+ focusBackOnExit?: boolean;
11
10
  }
12
11
  /**
13
12
  * @name TabTrap
14
13
  */
15
- export default class TabTrap extends Component<TabTrapProps> {
16
- static propTypes: {
17
- children: PropTypes.Validator<NonNullable<PropTypes.ReactNodeLike>>;
18
- trapDisabled: PropTypes.Requireable<boolean>;
19
- autoFocusFirst: PropTypes.Requireable<boolean>;
20
- focusBackOnClose: PropTypes.Requireable<boolean>;
21
- focusBackOnExit: PropTypes.Requireable<boolean>;
22
- };
23
- static defaultProps: {
24
- trapDisabled: boolean;
25
- autoFocusFirst: boolean;
26
- focusBackOnClose: boolean;
27
- focusBackOnExit: boolean;
28
- };
29
- componentDidMount(): void;
30
- componentWillUnmount(): void;
31
- previousFocusedNode?: Element | null;
32
- trapWithoutFocus?: boolean;
33
- restoreFocus: () => void;
34
- node?: HTMLElement | null;
35
- containerRef: (node: HTMLElement | null) => void;
36
- focusElement: (first?: boolean) => void;
37
- focusFirst: () => void;
38
- focusLast: () => void;
39
- focusLastIfEnabled: (event: React.FocusEvent) => void;
40
- handleBlurIfWithoutFocus: (event: React.FocusEvent) => void;
41
- trapButtonNode?: HTMLElement | null;
42
- trapButtonRef: (node: HTMLElement | null) => void;
43
- render(): React.JSX.Element;
14
+ interface TabTrap {
15
+ node: HTMLElement | null;
44
16
  }
17
+ declare const TabTrap: React.ForwardRefExoticComponent<TabTrapProps & React.RefAttributes<TabTrap>>;
18
+ export default TabTrap;
@@ -1,8 +1,7 @@
1
- import { _ as _defineProperty, a as _inherits, b as _createClass, c as _objectWithoutProperties, d as _objectSpread2, e as _classCallCheck, f as _callSuper, j as _toConsumableArray } from '../_helpers/_rollupPluginBabelHelpers.js';
2
- import 'core-js/modules/es.array.concat.js';
1
+ import { c as _objectWithoutProperties, j as _toConsumableArray, d as _objectSpread2 } from '../_helpers/_rollupPluginBabelHelpers.js';
3
2
  import 'core-js/modules/es.array.filter.js';
4
3
  import 'core-js/modules/es.object.to-string.js';
5
- import { Component } from 'react';
4
+ import { forwardRef, useRef, useImperativeHandle, useCallback, useEffect } from 'react';
6
5
  import PropTypes from 'prop-types';
7
6
  import { isNodeInVisiblePartOfPage } from '../global/dom.js';
8
7
  import { jsx, jsxs } from 'react/jsx-runtime';
@@ -19,165 +18,161 @@ var modules_6dce58ae = {"light":"light_rui_2ac4","trapButton":"trapButton_rui_11
19
18
 
20
19
  var _excluded = ["children", "trapDisabled", "autoFocusFirst", "focusBackOnClose", "focusBackOnExit"];
21
20
  var FOCUSABLE_ELEMENTS = 'input, button, select, textarea, a[href], *[tabindex]:not([data-trap-button]):not([data-scrollable-container])';
22
- /**
23
- * @name TabTrap
24
- */
25
- var TabTrap = /*#__PURE__*/function (_Component) {
26
- function TabTrap() {
27
- var _this;
28
- _classCallCheck(this, TabTrap);
29
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
30
- args[_key] = arguments[_key];
31
- }
32
- _this = _callSuper(this, TabTrap, [].concat(args));
33
- _defineProperty(_this, "previousFocusedNode", void 0);
34
- _defineProperty(_this, "trapWithoutFocus", void 0);
35
- _defineProperty(_this, "restoreFocus", function () {
36
- var _this2 = _this,
37
- previousFocusedNode = _this2.previousFocusedNode;
38
- if (previousFocusedNode instanceof HTMLElement && previousFocusedNode.focus && isNodeInVisiblePartOfPage(previousFocusedNode)) {
39
- previousFocusedNode.focus({
40
- preventScroll: true
41
- });
42
- }
43
- });
44
- _defineProperty(_this, "node", void 0);
45
- _defineProperty(_this, "containerRef", function (node) {
46
- if (!node) {
47
- return;
48
- }
49
- _this.node = node;
50
- });
51
- _defineProperty(_this, "focusElement", function () {
52
- var first = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
53
- var _this3 = _this,
54
- node = _this3.node;
55
- if (!node) {
56
- return;
57
- }
58
- var tabables = _toConsumableArray(node.querySelectorAll(FOCUSABLE_ELEMENTS)).filter(function (item) {
59
- return item.tabIndex >= 0;
60
- });
61
- var toBeFocused = first ? tabables[0] : tabables[tabables.length - 1];
62
- if (toBeFocused) {
63
- toBeFocused.focus();
21
+ // eslint-disable-next-line @typescript-eslint/no-shadow
22
+ var TabTrap = /*#__PURE__*/forwardRef(function TabTrap(_ref, ref) {
23
+ var children = _ref.children,
24
+ _ref$trapDisabled = _ref.trapDisabled,
25
+ trapDisabled = _ref$trapDisabled === void 0 ? false : _ref$trapDisabled,
26
+ _ref$autoFocusFirst = _ref.autoFocusFirst,
27
+ autoFocusFirst = _ref$autoFocusFirst === void 0 ? true : _ref$autoFocusFirst,
28
+ _ref$focusBackOnClose = _ref.focusBackOnClose,
29
+ focusBackOnClose = _ref$focusBackOnClose === void 0 ? true : _ref$focusBackOnClose,
30
+ _ref$focusBackOnExit = _ref.focusBackOnExit,
31
+ focusBackOnExit = _ref$focusBackOnExit === void 0 ? false : _ref$focusBackOnExit,
32
+ restProps = _objectWithoutProperties(_ref, _excluded);
33
+ var nodeRef = useRef(null);
34
+ var trapButtonNodeRef = useRef(null);
35
+ var previousFocusedNodeRef = useRef(null);
36
+ var trapWithoutFocusRef = useRef(false);
37
+ var mountedRef = useRef(false);
38
+ // It's the same approach as in focus-trap-react:
39
+ // https://github.com/focus-trap/focus-trap-react/commit/3b22fca9eebeb883edc89548850fe5a5b9d6d50e
40
+ // We can't do it in useEffect because it's too late, some children might have already
41
+ // focused itself.
42
+ if (previousFocusedNodeRef.current === null) {
43
+ previousFocusedNodeRef.current = document.activeElement;
44
+ }
45
+ useImperativeHandle(ref, function () {
46
+ return {
47
+ node: nodeRef.current
48
+ };
49
+ }, []);
50
+ var focusFirst = useCallback(function () {
51
+ return focusElement(true);
52
+ }, []);
53
+ var focusLast = function focusLast() {
54
+ return focusElement(false);
55
+ };
56
+ useEffect(function () {
57
+ mountedRef.current = true;
58
+ return function () {
59
+ mountedRef.current = false;
60
+ };
61
+ }, []);
62
+ useEffect(function () {
63
+ if (autoFocusFirst) {
64
+ focusFirst();
65
+ } else if (!trapDisabled) {
66
+ var _nodeRef$current, _nodeRef$current2;
67
+ var previousFocusedElementIsInContainer = previousFocusedNodeRef.current && ((_nodeRef$current = nodeRef.current) === null || _nodeRef$current === void 0 ? void 0 : _nodeRef$current.contains(previousFocusedNodeRef.current));
68
+ // The component wrapped in TabTrap can already have a focused element (e.g. Date Picker),
69
+ // so we need to check if it does. If so, we don't need to focus anything.
70
+ var currentlyFocusedElementIsInContainer = (_nodeRef$current2 = nodeRef.current) === null || _nodeRef$current2 === void 0 ? void 0 : _nodeRef$current2.contains(document.activeElement);
71
+ if (!nodeRef.current || !previousFocusedElementIsInContainer && !currentlyFocusedElementIsInContainer) {
72
+ var _trapButtonNodeRef$cu;
73
+ trapWithoutFocusRef.current = true;
74
+ (_trapButtonNodeRef$cu = trapButtonNodeRef.current) === null || _trapButtonNodeRef$cu === void 0 || _trapButtonNodeRef$cu.focus();
64
75
  }
65
- });
66
- _defineProperty(_this, "focusFirst", function () {
67
- return _this.focusElement(true);
68
- });
69
- _defineProperty(_this, "focusLast", function () {
70
- return _this.focusElement(false);
71
- });
72
- _defineProperty(_this, "focusLastIfEnabled", function (event) {
73
- if (_this.trapWithoutFocus) {
74
- return;
76
+ }
77
+ return function () {
78
+ if (focusBackOnClose) {
79
+ restoreFocus();
75
80
  }
76
- if (_this.props.focusBackOnExit) {
77
- var prevFocused = event.nativeEvent.relatedTarget;
78
- if (prevFocused != null && _this.node != null && prevFocused instanceof Element && _this.node.contains(prevFocused)) {
79
- _this.restoreFocus();
81
+ };
82
+ }, [autoFocusFirst, trapDisabled, focusBackOnClose, focusFirst]);
83
+ function restoreFocus() {
84
+ var previousFocusedNode = previousFocusedNodeRef.current;
85
+ if (previousFocusedNode instanceof HTMLElement && previousFocusedNode.focus && isNodeInVisiblePartOfPage(previousFocusedNode)) {
86
+ // If no delay is added, restoring focus caused by pressing Enter will trigger
87
+ // the onClick event on the previousFocusedNode, e.g.
88
+ // https://youtrack.jetbrains.com/issue/RG-2450/Anchor-should-be-focused-after-closing-datepicker#focus=Comments-27-10044234.0-0.
89
+ setTimeout(function () {
90
+ // This is to prevent the focus from being restored the first time
91
+ // componentWillUnmount is called in StrictMode.
92
+ if (!mountedRef.current) {
93
+ previousFocusedNode.focus({
94
+ preventScroll: true
95
+ });
80
96
  }
81
- } else {
82
- _this.focusLast();
83
- }
84
- });
85
- _defineProperty(_this, "handleBlurIfWithoutFocus", function (event) {
86
- var _this$node;
87
- if (!_this.trapWithoutFocus) {
88
- return;
89
- }
90
- _this.trapWithoutFocus = false;
91
- var newFocused = event.nativeEvent.relatedTarget;
92
- if (!newFocused) {
93
- return;
94
- }
95
- if (newFocused instanceof Element && (_this$node = _this.node) !== null && _this$node !== void 0 && _this$node.contains(newFocused)) {
96
- return;
97
- }
98
- _this.focusLast();
99
- });
100
- _defineProperty(_this, "trapButtonNode", void 0);
101
- _defineProperty(_this, "trapButtonRef", function (node) {
102
- if (!node) {
103
- return;
104
- }
105
- _this.trapButtonNode = node;
97
+ });
98
+ }
99
+ }
100
+ function focusElement() {
101
+ var first = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
102
+ var node = nodeRef.current;
103
+ if (!node) {
104
+ return;
105
+ }
106
+ var tabables = _toConsumableArray(node.querySelectorAll(FOCUSABLE_ELEMENTS)).filter(function (item) {
107
+ return item.tabIndex >= 0;
106
108
  });
107
- return _this;
109
+ var toBeFocused = first ? tabables[0] : tabables[tabables.length - 1];
110
+ if (toBeFocused) {
111
+ toBeFocused.focus();
112
+ }
108
113
  }
109
- _inherits(TabTrap, _Component);
110
- return _createClass(TabTrap, [{
111
- key: "componentDidMount",
112
- value: function componentDidMount() {
113
- this.previousFocusedNode = document.activeElement;
114
- if (this.props.autoFocusFirst) {
115
- this.focusFirst();
116
- } else if (!this.props.trapDisabled && (!this.node || !this.node.contains(this.previousFocusedNode))) {
117
- var _this$trapButtonNode;
118
- this.trapWithoutFocus = true;
119
- (_this$trapButtonNode = this.trapButtonNode) === null || _this$trapButtonNode === void 0 || _this$trapButtonNode.focus();
120
- }
114
+ function focusLastIfEnabled(event) {
115
+ if (trapWithoutFocusRef.current) {
116
+ return;
121
117
  }
122
- }, {
123
- key: "componentWillUnmount",
124
- value: function componentWillUnmount() {
125
- if (this.props.focusBackOnClose) {
126
- this.restoreFocus();
118
+ if (focusBackOnExit) {
119
+ var prevFocused = event.nativeEvent.relatedTarget;
120
+ if (prevFocused != null && nodeRef.current != null && prevFocused instanceof Element && nodeRef.current.contains(prevFocused)) {
121
+ restoreFocus();
127
122
  }
123
+ } else {
124
+ focusLast();
128
125
  }
129
- }, {
130
- key: "render",
131
- value: function render() {
132
- var _this$props = this.props,
133
- children = _this$props.children,
134
- trapDisabled = _this$props.trapDisabled;
135
- _this$props.autoFocusFirst;
136
- _this$props.focusBackOnClose;
137
- var focusBackOnExit = _this$props.focusBackOnExit,
138
- restProps = _objectWithoutProperties(_this$props, _excluded);
139
- if (trapDisabled) {
140
- return /*#__PURE__*/jsx("div", _objectSpread2(_objectSpread2({
141
- ref: this.containerRef
142
- }, restProps), {}, {
143
- children: children
144
- }));
145
- }
146
- return /*#__PURE__*/jsxs("div", _objectSpread2(_objectSpread2({
147
- ref: this.containerRef
148
- }, restProps), {}, {
149
- children: [/*#__PURE__*/jsx("div", {
150
- // It never actually stays focused
151
- // eslint-disable-next-line jsx-a11y/no-noninteractive-tabindex
152
- tabIndex: 0,
153
- ref: this.trapButtonRef,
154
- className: modules_6dce58ae.trapButton,
155
- onFocus: this.focusLastIfEnabled,
156
- onBlur: this.handleBlurIfWithoutFocus,
157
- "data-trap-button": true
158
- }), children, /*#__PURE__*/jsx("div", {
159
- // It never actually stays focused
160
- // eslint-disable-next-line jsx-a11y/no-noninteractive-tabindex
161
- tabIndex: 0,
162
- onFocus: focusBackOnExit ? this.restoreFocus : this.focusFirst,
163
- "data-trap-button": true
164
- })]
165
- }));
126
+ }
127
+ function handleBlurIfWithoutFocus(event) {
128
+ var _nodeRef$current3;
129
+ if (!trapWithoutFocusRef.current) {
130
+ return;
131
+ }
132
+ trapWithoutFocusRef.current = false;
133
+ var newFocused = event.nativeEvent.relatedTarget;
134
+ if (!newFocused) {
135
+ return;
166
136
  }
167
- }]);
168
- }(Component);
169
- _defineProperty(TabTrap, "propTypes", {
137
+ if (newFocused instanceof Element && (_nodeRef$current3 = nodeRef.current) !== null && _nodeRef$current3 !== void 0 && _nodeRef$current3.contains(newFocused)) {
138
+ return;
139
+ }
140
+ focusLast();
141
+ }
142
+ if (trapDisabled) {
143
+ return /*#__PURE__*/jsx("div", _objectSpread2(_objectSpread2({
144
+ ref: nodeRef
145
+ }, restProps), {}, {
146
+ children: children
147
+ }));
148
+ }
149
+ return /*#__PURE__*/jsxs("div", _objectSpread2(_objectSpread2({
150
+ ref: nodeRef
151
+ }, restProps), {}, {
152
+ children: [/*#__PURE__*/jsx("div", {
153
+ // It never actually stays focused
154
+ // eslint-disable-next-line jsx-a11y/no-noninteractive-tabindex
155
+ tabIndex: 0,
156
+ ref: trapButtonNodeRef,
157
+ className: modules_6dce58ae.trapButton,
158
+ onFocus: focusLastIfEnabled,
159
+ onBlur: handleBlurIfWithoutFocus,
160
+ "data-trap-button": true
161
+ }), children, /*#__PURE__*/jsx("div", {
162
+ // It never actually stays focused
163
+ // eslint-disable-next-line jsx-a11y/no-noninteractive-tabindex
164
+ tabIndex: 0,
165
+ onFocus: focusBackOnExit ? restoreFocus : focusFirst,
166
+ "data-trap-button": true
167
+ })]
168
+ }));
169
+ });
170
+ TabTrap.propTypes = {
170
171
  children: PropTypes.node.isRequired,
171
172
  trapDisabled: PropTypes.bool,
172
173
  autoFocusFirst: PropTypes.bool,
173
174
  focusBackOnClose: PropTypes.bool,
174
175
  focusBackOnExit: PropTypes.bool
175
- });
176
- _defineProperty(TabTrap, "defaultProps", {
177
- trapDisabled: false,
178
- autoFocusFirst: true,
179
- focusBackOnClose: true,
180
- focusBackOnExit: false
181
- });
176
+ };
182
177
 
183
178
  export { FOCUSABLE_ELEMENTS, TabTrap as default };
@@ -10,6 +10,7 @@ import '../global/composeRefs.js';
10
10
  import 'core-js/modules/es.object.to-string.js';
11
11
  import 'core-js/modules/web.dom-collections.for-each.js';
12
12
  import 'memoize-one';
13
+ import 'util-deprecate';
13
14
  import 'core-js/modules/es.array.map.js';
14
15
  import 'classnames';
15
16
  import '@jetbrains/icons/chevron-right';
@@ -19,7 +20,6 @@ import '../checkbox/checkbox.js';
19
20
  import '@jetbrains/icons/checkmark-12px';
20
21
  import '@jetbrains/icons/remove-12px';
21
22
  import '../icon/icon.js';
22
- import 'util-deprecate';
23
23
  import '../icon/icon__constants.js';
24
24
  import '../_helpers/icon__svg.js';
25
25
  import 'core-js/modules/es.regexp.exec.js';
@@ -56,6 +56,7 @@ export default class Row<T extends SelectionItem> extends PureComponent<RowProps
56
56
  onDoubleClick: () => void;
57
57
  row?: HTMLElement | null;
58
58
  rowRef: (el: HTMLElement | null) => void;
59
+ composedRowRef: import("memoize-one").MemoizedFn<(...refs: (React.Ref<HTMLElement> | undefined)[]) => (value: HTMLElement | null) => void>;
59
60
  render(): React.JSX.Element;
60
61
  }
61
62
  export type RowAttrs<T extends SelectionItem> = JSX.LibraryManagedAttributes<typeof Row, RowProps<T>>;
@@ -12,7 +12,7 @@ import { Button } from '../button/button.js';
12
12
  import Tooltip from '../tooltip/tooltip.js';
13
13
  import joinDataTestAttributes from '../global/data-tests.js';
14
14
  import getUID from '../global/get-uid.js';
15
- import composeRefs from '../global/composeRefs.js';
15
+ import { createComposedRef } from '../global/composeRefs.js';
16
16
  import Cell from './cell.js';
17
17
  import { m as modules_1db4bbca } from '../_helpers/table.js';
18
18
  import { jsxs, jsx } from 'react/jsx-runtime';
@@ -122,6 +122,7 @@ var Row = /*#__PURE__*/function (_PureComponent) {
122
122
  _defineProperty(_this, "rowRef", function (el) {
123
123
  _this.row = el;
124
124
  });
125
+ _defineProperty(_this, "composedRowRef", createComposedRef());
125
126
  return _this;
126
127
  }
127
128
  _inherits(Row, _PureComponent);
@@ -249,7 +250,7 @@ var Row = /*#__PURE__*/function (_PureComponent) {
249
250
  });
250
251
  return /*#__PURE__*/jsx("tr", _objectSpread2(_objectSpread2(_objectSpread2({
251
252
  id: this.id,
252
- ref: composeRefs(this.rowRef, innerRef),
253
+ ref: this.composedRowRef(this.rowRef, innerRef),
253
254
  className: classes,
254
255
  tabIndex: 0,
255
256
  "data-test": joinDataTestAttributes('ring-table-row', dataTest)
@@ -14,6 +14,7 @@ import '../global/composeRefs.js';
14
14
  import 'core-js/modules/es.object.to-string.js';
15
15
  import 'core-js/modules/web.dom-collections.for-each.js';
16
16
  import 'memoize-one';
17
+ import 'util-deprecate';
17
18
  import '../global/get-uid.js';
18
19
  import 'core-js/modules/es.regexp.to-string.js';
19
20
  import '../shortcuts/shortcuts.js';
@@ -46,7 +47,6 @@ import '../checkbox/checkbox.js';
46
47
  import '@jetbrains/icons/checkmark-12px';
47
48
  import '@jetbrains/icons/remove-12px';
48
49
  import '../icon/icon.js';
49
- import 'util-deprecate';
50
50
  import '../icon/icon__constants.js';
51
51
  import '../_helpers/icon__svg.js';
52
52
  import 'core-js/modules/es.string.replace.js';
@@ -21,6 +21,7 @@ import '../global/composeRefs.js';
21
21
  import 'core-js/modules/es.object.to-string.js';
22
22
  import 'core-js/modules/web.dom-collections.for-each.js';
23
23
  import 'memoize-one';
24
+ import 'util-deprecate';
24
25
  import 'core-js/modules/es.regexp.to-string.js';
25
26
  import '../shortcuts/core.js';
26
27
  import 'core-js/modules/es.array.find-index.js';
@@ -50,7 +51,6 @@ import '../checkbox/checkbox.js';
50
51
  import '@jetbrains/icons/checkmark-12px';
51
52
  import '@jetbrains/icons/remove-12px';
52
53
  import '../icon/icon.js';
53
- import 'util-deprecate';
54
54
  import '../icon/icon__constants.js';
55
55
  import '../_helpers/icon__svg.js';
56
56
  import 'core-js/modules/es.string.replace.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jetbrains/ring-ui-built",
3
- "version": "6.0.38",
3
+ "version": "6.0.40",
4
4
  "description": "JetBrains UI library",
5
5
  "author": "JetBrains",
6
6
  "license": "Apache-2.0",
@@ -41,9 +41,9 @@
41
41
  "screenshots-test-ci": "npm --prefix packages/screenshots run test-ci",
42
42
  "screenshots-gather": "npm --prefix packages/screenshots run gather",
43
43
  "build-stories": "storybook build --quiet -c .storybook -o storybook-dist",
44
- "prebuild": "rimraf components && tsc --project tsconfig-build.json && cpy '**/*' '!**/*.ts' '!**/*.tsx' '!**/__mocks__/**' ../components --parents --cwd=src/",
44
+ "prebuild": "rimraf components && tsc --project tsconfig-build.json && cpy './**/*' '!**/*.ts' '!**/*.tsx' '!**/__mocks__/**' ../components --parents --cwd=src/",
45
45
  "build": "./node_modules/.bin/rollup -c --bundleConfigAsCjs",
46
- "postbuild": "cpy '**/*.d.ts' ../dist --parents --cwd=components/",
46
+ "postbuild": "cpy './**/*.d.ts' ../dist --parents --cwd=components/",
47
47
  "serve": "http-server storybook-dist/ -p 9999",
48
48
  "start": "storybook dev -p 9999",
49
49
  "storybook-debug": "node --inspect-brk node_modules/@storybook/react/bin -p 9999",