@salutejs/plasma-new-hope 0.337.0-canary.2237.17801180282.0 → 0.337.0-canary.2237.17941275054.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 (53) hide show
  1. package/cjs/components/Modal/Modal.js +4 -2
  2. package/cjs/components/Modal/Modal.js.map +1 -1
  3. package/cjs/hooks/useFocusTrap.js +11 -5
  4. package/cjs/hooks/useFocusTrap.js.map +1 -1
  5. package/cjs/utils/scopeTab.js +2 -2
  6. package/cjs/utils/scopeTab.js.map +1 -1
  7. package/emotion/cjs/components/Modal/Modal.js +3 -2
  8. package/emotion/cjs/examples/components/Chip/Chip.config.js +14 -14
  9. package/emotion/cjs/examples/components/Combobox/Combobox.config.js +15 -15
  10. package/emotion/cjs/examples/components/Select/Select.config.js +24 -24
  11. package/emotion/cjs/examples/components/TextField/TextField.config.js +23 -23
  12. package/emotion/cjs/hooks/useFocusTrap.js +12 -5
  13. package/emotion/cjs/utils/scopeTab.js +2 -2
  14. package/emotion/es/components/Modal/Modal.js +3 -2
  15. package/emotion/es/examples/components/Chip/Chip.config.js +14 -14
  16. package/emotion/es/examples/components/Combobox/Combobox.config.js +15 -15
  17. package/emotion/es/examples/components/Select/Select.config.js +24 -24
  18. package/emotion/es/examples/components/TextField/TextField.config.js +23 -23
  19. package/emotion/es/hooks/useFocusTrap.js +12 -5
  20. package/emotion/es/utils/scopeTab.js +2 -2
  21. package/es/components/Modal/Modal.js +4 -2
  22. package/es/components/Modal/Modal.js.map +1 -1
  23. package/es/hooks/useFocusTrap.js +11 -5
  24. package/es/hooks/useFocusTrap.js.map +1 -1
  25. package/es/utils/scopeTab.js +2 -2
  26. package/es/utils/scopeTab.js.map +1 -1
  27. package/package.json +5 -5
  28. package/styled-components/cjs/components/Modal/Modal.js +3 -2
  29. package/styled-components/cjs/examples/components/Chip/Chip.config.js +6 -6
  30. package/styled-components/cjs/examples/components/Combobox/Combobox.config.js +4 -4
  31. package/styled-components/cjs/examples/components/Combobox/Combobox.js +0 -15
  32. package/styled-components/cjs/examples/components/Select/Select.config.js +1 -1
  33. package/styled-components/cjs/examples/components/TextField/TextField.config.js +7 -6
  34. package/styled-components/cjs/hooks/useFocusTrap.js +12 -5
  35. package/styled-components/cjs/utils/scopeTab.js +2 -2
  36. package/styled-components/es/components/Modal/Modal.js +3 -2
  37. package/styled-components/es/examples/components/Chip/Chip.config.js +6 -6
  38. package/styled-components/es/examples/components/Combobox/Combobox.config.js +4 -4
  39. package/styled-components/es/examples/components/Select/Select.config.js +1 -1
  40. package/styled-components/es/examples/components/TextField/TextField.config.js +7 -6
  41. package/styled-components/es/hooks/useFocusTrap.js +12 -5
  42. package/styled-components/es/utils/scopeTab.js +2 -2
  43. package/types/components/Avatar/Avatar.types.d.ts +26 -1
  44. package/types/components/Avatar/Avatar.types.d.ts.map +1 -1
  45. package/types/components/Modal/Modal.d.ts.map +1 -1
  46. package/types/components/Modal/Modal.types.d.ts +5 -0
  47. package/types/components/Modal/Modal.types.d.ts.map +1 -1
  48. package/types/examples/components/Avatar/Avatar.d.ts +4 -4
  49. package/types/examples/components/TextField/TextField.config.d.ts.map +1 -1
  50. package/types/hooks/useFocusTrap.d.ts +1 -1
  51. package/types/hooks/useFocusTrap.d.ts.map +1 -1
  52. package/types/utils/scopeTab.d.ts +1 -1
  53. package/types/utils/scopeTab.d.ts.map +1 -1
@@ -47,14 +47,14 @@ var processNode = function(node, firstFocusSelector, ref) {
47
47
  };
48
48
  var focusManager = new _focusManager.FocusManager();
49
49
  var useFocusTrap = function() {
50
- var active = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : true, firstFocusSelector = arguments.length > 1 ? arguments[1] : void 0, focusAfterNode = arguments.length > 2 ? arguments[2] : void 0, focusAfterAnimation = arguments.length > 3 ? arguments[3] : void 0;
50
+ var active = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : true, firstFocusSelector = arguments.length > 1 ? arguments[1] : void 0, focusAfterNode = arguments.length > 2 ? arguments[2] : void 0, focusAfterAnimation = arguments.length > 3 ? arguments[3] : void 0, enableOnFirstMount = arguments.length > 4 ? arguments[4] : void 0;
51
51
  var ref = (0, _react.useRef)();
52
52
  var setRef = (0, _react.useCallback)(function(node) {
53
53
  if (ref.current) {
54
54
  focusManager.teardownScopedFocus();
55
55
  focusManager.returnFocus();
56
56
  }
57
- if (active && node) {
57
+ if ((active || enableOnFirstMount) && node) {
58
58
  focusManager.setupScopedFocus(node);
59
59
  focusManager.markForFocusAfter(focusAfterNode);
60
60
  // Delay processing the HTML node by a frame. This ensures focus is assigned correctly.
@@ -73,15 +73,21 @@ var useFocusTrap = function() {
73
73
  ref.current = null;
74
74
  }, [
75
75
  active,
76
+ enableOnFirstMount,
76
77
  firstFocusSelector
77
78
  ]);
78
79
  (0, _react.useEffect)(function() {
79
- if (!active) {
80
+ if (!active && !enableOnFirstMount) {
80
81
  return;
81
82
  }
82
83
  var handleKeyDown = function(event) {
83
84
  if (event.key === 'Tab' && ref.current) {
84
- (0, _scopeTab.scopeTab)(ref.current, event);
85
+ (0, _scopeTab.scopeTab)(ref.current, event, active);
86
+ if (enableOnFirstMount) {
87
+ setTimeout(function() {
88
+ focusManager.teardownScopedFocus();
89
+ });
90
+ }
85
91
  }
86
92
  };
87
93
  document.addEventListener('keydown', handleKeyDown);
@@ -89,7 +95,8 @@ var useFocusTrap = function() {
89
95
  document.removeEventListener('keydown', handleKeyDown);
90
96
  };
91
97
  }, [
92
- active
98
+ active,
99
+ enableOnFirstMount
93
100
  ]);
94
101
  return setRef;
95
102
  };
@@ -9,7 +9,7 @@ Object.defineProperty(exports, "scopeTab", {
9
9
  }
10
10
  });
11
11
  var _tabbable = require("./tabbable");
12
- var scopeTab = function(node, event) {
12
+ var scopeTab = function(node, event, activeFocusTrap) {
13
13
  var tabbable = (0, _tabbable.findTabbableDescendants)(node);
14
14
  if (!tabbable.length) {
15
15
  event.preventDefault();
@@ -19,7 +19,7 @@ var scopeTab = function(node, event) {
19
19
  var finalTabbable = tabbable[event.shiftKey ? 0 : tabbable.length - 1];
20
20
  var leavingFinalTabbable = finalTabbable === document.activeElement || node === document.activeElement;
21
21
  // если не является, то передаем обработку таба самому браузеру
22
- if (!leavingFinalTabbable) {
22
+ if (!leavingFinalTabbable || !activeFocusTrap) {
23
23
  return;
24
24
  }
25
25
  // иначе зацкливаемся
@@ -74,7 +74,7 @@ var Popup = component(popupConfig);
74
74
  * Управляет показом/скрытием, подложкой и анимацией визуальной части модального окна.
75
75
  */ export var modalRoot = function(Root) {
76
76
  return /*#__PURE__*/ forwardRef(function(_param, outerRootRef) {
77
- var id = _param.id, withAnimation = _param.withAnimation, onClose = _param.onClose, onOverlayClick = _param.onOverlayClick, onEscKeyDown = _param.onEscKeyDown, _param_closeOnEsc = _param.closeOnEsc, closeOnEsc = _param_closeOnEsc === void 0 ? true : _param_closeOnEsc, _param_closeOnOverlayClick = _param.closeOnOverlayClick, closeOnOverlayClick = _param_closeOnOverlayClick === void 0 ? true : _param_closeOnOverlayClick, withBlur = _param.withBlur, initialFocusRef = _param.initialFocusRef, focusAfterRef = _param.focusAfterRef, zIndex = _param.zIndex, popupInfo = _param.popupInfo, children = _param.children, view = _param.view, opened = _param.opened, isOpen = _param.isOpen, hasBody = _param.hasBody, hasClose = _param.hasClose, resizable = _param.resizable, draggable = _param.draggable, rest = _object_without_properties(_param, [
77
+ var id = _param.id, withAnimation = _param.withAnimation, onClose = _param.onClose, onOverlayClick = _param.onOverlayClick, onEscKeyDown = _param.onEscKeyDown, _param_closeOnEsc = _param.closeOnEsc, closeOnEsc = _param_closeOnEsc === void 0 ? true : _param_closeOnEsc, _param_closeOnOverlayClick = _param.closeOnOverlayClick, closeOnOverlayClick = _param_closeOnOverlayClick === void 0 ? true : _param_closeOnOverlayClick, withBlur = _param.withBlur, _param_isFocusTrapped = _param.isFocusTrapped, isFocusTrapped = _param_isFocusTrapped === void 0 ? true : _param_isFocusTrapped, initialFocusRef = _param.initialFocusRef, focusAfterRef = _param.focusAfterRef, zIndex = _param.zIndex, popupInfo = _param.popupInfo, children = _param.children, view = _param.view, opened = _param.opened, isOpen = _param.isOpen, hasBody = _param.hasBody, hasClose = _param.hasClose, resizable = _param.resizable, draggable = _param.draggable, rest = _object_without_properties(_param, [
78
78
  "id",
79
79
  "withAnimation",
80
80
  "onClose",
@@ -83,6 +83,7 @@ var Popup = component(popupConfig);
83
83
  "closeOnEsc",
84
84
  "closeOnOverlayClick",
85
85
  "withBlur",
86
+ "isFocusTrapped",
86
87
  "initialFocusRef",
87
88
  "focusAfterRef",
88
89
  "zIndex",
@@ -98,7 +99,7 @@ var Popup = component(popupConfig);
98
99
  ]);
99
100
  var innerIsOpen = Boolean(isOpen || opened);
100
101
  var innerHasClose = hasClose === undefined && hasBody || hasClose;
101
- var trapRef = useFocusTrap(true, initialFocusRef, focusAfterRef, true);
102
+ var trapRef = useFocusTrap(isFocusTrapped, initialFocusRef, focusAfterRef, true, !isFocusTrapped);
102
103
  var popupController = usePopupContext();
103
104
  var innerRef = useForkRef(trapRef, outerRootRef);
104
105
  var uniqId = safeUseId();