@atlaskit/popup 1.24.2 → 1.26.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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,30 @@
1
1
  # @atlaskit/popup
2
2
 
3
+ ## 1.26.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#142538](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/142538)
8
+ [`3979d0196514a`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/3979d0196514a) -
9
+ [ux] We are testing focus ring for popup wrapper `onKeyDown`. Changes are implemented behind
10
+ feature flag. If this fix is successful, it will be available in a later release.
11
+
12
+ ## 1.25.0
13
+
14
+ ### Minor Changes
15
+
16
+ - [#138688](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/138688)
17
+ [`961d97994618c`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/961d97994618c) -
18
+ Adds `shouldFitViewport` prop which will apply `max-width` and `max-height` to contain the
19
+ popper/popup within the viewport.
20
+
21
+ ### Patch Changes
22
+
23
+ - [#138585](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/138585)
24
+ [`b72c2c7f9a2fd`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/b72c2c7f9a2fd) -
25
+ Support to close all layers when clicking outside under feature flag
26
+ - Updated dependencies
27
+
3
28
  ## 1.24.2
4
29
 
5
30
  ### Patch Changes
@@ -18,7 +18,7 @@ var _constants = require("@atlaskit/theme/constants");
18
18
  var _popperWrapper = _interopRequireDefault(require("../popper-wrapper"));
19
19
  var _useGetMemoizedMergedTriggerRef = require("../use-get-memoized-merged-trigger-ref");
20
20
  function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
21
- function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
21
+ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
22
22
  var IsOpenContext = /*#__PURE__*/(0, _react.createContext)(false);
23
23
  var IdContext = /*#__PURE__*/(0, _react.createContext)(undefined);
24
24
  var TriggerRefContext = /*#__PURE__*/(0, _react.createContext)(null);
@@ -129,7 +129,8 @@ var PopupContent = exports.PopupContent = function PopupContent(_ref4) {
129
129
  shouldRenderToParent = _ref4.shouldRenderToParent,
130
130
  _ref4$shouldDisableFo = _ref4.shouldDisableFocusLock,
131
131
  shouldDisableFocusLock = _ref4$shouldDisableFo === void 0 ? false : _ref4$shouldDisableFo,
132
- shouldFitContainer = _ref4.shouldFitContainer;
132
+ shouldFitContainer = _ref4.shouldFitContainer,
133
+ shouldFitViewport = _ref4.shouldFitViewport;
133
134
  useEnsureIsInsidePopup();
134
135
  var isOpen = (0, _react.useContext)(IsOpenContext);
135
136
  var id = (0, _react.useContext)(IdContext);
@@ -158,7 +159,8 @@ var PopupContent = exports.PopupContent = function PopupContent(_ref4) {
158
159
  shouldRenderToParent: shouldRenderToParent,
159
160
  shouldDisableFocusLock: shouldDisableFocusLock,
160
161
  triggerRef: triggerRef,
161
- strategy: strategy
162
+ strategy: strategy,
163
+ shouldFitViewport: shouldFitViewport
162
164
  }));
163
165
  if (shouldRenderToParent) {
164
166
  return popperWrapper;
@@ -12,7 +12,9 @@ var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/h
12
12
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
13
13
  var _react = require("react");
14
14
  var _react2 = require("@emotion/react");
15
+ var _focusRing = _interopRequireDefault(require("@atlaskit/focus-ring"));
15
16
  var _layering = require("@atlaskit/layering");
17
+ var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
16
18
  var _popper = require("@atlaskit/popper");
17
19
  var _colors = require("@atlaskit/theme/colors");
18
20
  var _constants = require("@atlaskit/theme/constants");
@@ -86,7 +88,8 @@ function PopperWrapper(_ref) {
86
88
  role = _ref.role,
87
89
  label = _ref.label,
88
90
  titleId = _ref.titleId,
89
- modifiers = _ref.modifiers;
91
+ modifiers = _ref.modifiers,
92
+ shouldFitViewport = _ref.shouldFitViewport;
90
93
  var _useState = (0, _react.useState)(null),
91
94
  _useState2 = (0, _slicedToArray2.default)(_useState, 2),
92
95
  popupRef = _useState2[0],
@@ -137,13 +140,14 @@ function PopperWrapper(_ref) {
137
140
  placement: placement,
138
141
  offset: offset,
139
142
  modifiers: mergedModifiers,
140
- strategy: strategy
143
+ strategy: strategy,
144
+ shouldFitViewport: shouldFitViewport
141
145
  }, function (_ref2) {
142
146
  var _ref3 = _ref2.ref,
143
147
  style = _ref2.style,
144
148
  placement = _ref2.placement,
145
149
  update = _ref2.update;
146
- return (0, _react2.jsx)(PopupContainer, {
150
+ var popupContainer = (0, _react2.jsx)(PopupContainer, {
147
151
  id: id,
148
152
  "data-ds--level": currentLevel,
149
153
  "data-placement": placement,
@@ -178,6 +182,7 @@ function PopperWrapper(_ref) {
178
182
  onClose: onClose,
179
183
  setInitialFocusRef: setInitialFocusRef
180
184
  })));
185
+ return !initialFocusRef && (0, _platformFeatureFlags.fg)('platform-design-system-apply-popup-wrapper-focus') ? (0, _react2.jsx)(_focusRing.default, null, popupContainer) : popupContainer;
181
186
  });
182
187
  }
183
188
 
package/dist/cjs/popup.js CHANGED
@@ -65,7 +65,8 @@ var Popup = exports.Popup = /*#__PURE__*/(0, _react.memo)(function (_ref) {
65
65
  role = _ref.role,
66
66
  label = _ref.label,
67
67
  titleId = _ref.titleId,
68
- modifiers = _ref.modifiers;
68
+ modifiers = _ref.modifiers,
69
+ shouldFitViewport = _ref.shouldFitViewport;
69
70
  var _useState = (0, _react.useState)(null),
70
71
  _useState2 = (0, _slicedToArray2.default)(_useState, 2),
71
72
  triggerRef = _useState2[0],
@@ -100,7 +101,8 @@ var Popup = exports.Popup = /*#__PURE__*/(0, _react.memo)(function (_ref) {
100
101
  role: role,
101
102
  label: label,
102
103
  titleId: titleId,
103
- modifiers: modifiers
104
+ modifiers: modifiers,
105
+ shouldFitViewport: shouldFitViewport
104
106
  }));
105
107
  var popupContent = (0, _react2.jsx)(_popper.Manager, null, (0, _react2.jsx)(_popper.Reference, null, function (_ref2) {
106
108
  var ref = _ref2.ref;
@@ -7,7 +7,7 @@ Object.defineProperty(exports, "__esModule", {
7
7
  exports.RepositionOnUpdate = void 0;
8
8
  var _react = _interopRequireWildcard(require("react"));
9
9
  function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
10
- function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
10
+ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
11
11
  // eslint-disable-next-line @repo/internal/react/require-jsdoc
12
12
  var RepositionOnUpdate = exports.RepositionOnUpdate = function RepositionOnUpdate(_ref) {
13
13
  var children = _ref.children,
@@ -36,14 +36,25 @@ var useCloseManager = exports.useCloseManager = function useCloseManager(_ref) {
36
36
  }
37
37
  var closePopup = function closePopup(event) {
38
38
  if (onClose) {
39
- onClose(event);
39
+ if ((0, _platformFeatureFlags.fg)('sibling-dropdown-close-issue')) {
40
+ var _currentLevel = null;
41
+ if (event.target instanceof HTMLElement) {
42
+ var _event$target$closest;
43
+ _currentLevel = (_event$target$closest = event.target.closest("[data-ds--level]")) === null || _event$target$closest === void 0 ? void 0 : _event$target$closest.getAttribute('data-ds--level');
44
+ }
45
+ _currentLevel ? onClose(event, Number(_currentLevel)) : onClose(event);
46
+ } else {
47
+ onClose(event);
48
+ }
40
49
  }
41
50
  if (shouldDisableFocusTrap && (0, _platformFeatureFlags.fg)('platform_dst_popup-disable-focuslock')) {
42
51
  // Restoring the normal focus order for trigger.
43
- triggerRef === null || triggerRef === void 0 || triggerRef.setAttribute('tabindex', '0');
44
- if (popupRef && autoFocus) {
45
- popupRef.setAttribute('tabindex', '0');
46
- }
52
+ requestFrame(function () {
53
+ triggerRef === null || triggerRef === void 0 || triggerRef.setAttribute('tabindex', '0');
54
+ if (popupRef && autoFocus) {
55
+ popupRef.setAttribute('tabindex', '0');
56
+ }
57
+ });
47
58
  }
48
59
  };
49
60
 
@@ -61,8 +72,19 @@ var useCloseManager = exports.useCloseManager = function useCloseManager(_ref) {
61
72
  return;
62
73
  }
63
74
  if (isLayerDisabled()) {
64
- //if it is a disabled layer, we need to disable its click listener.
65
- return;
75
+ //if it is a disabled layer, and we clicked inside a higher layer
76
+ //we will disable the click event
77
+ if ((0, _platformFeatureFlags.fg)('design-system-closed-all-when-click-outside')) {
78
+ if (target instanceof HTMLElement) {
79
+ var _target$closest;
80
+ var levelOfClickedLayer = (_target$closest = target.closest) === null || _target$closest === void 0 || (_target$closest = _target$closest.call(target, "[data-ds--level]")) === null || _target$closest === void 0 ? void 0 : _target$closest.getAttribute('data-ds--level');
81
+ if (levelOfClickedLayer && Number(levelOfClickedLayer) > currentLevel) {
82
+ return;
83
+ }
84
+ }
85
+ } else {
86
+ return;
87
+ }
66
88
  }
67
89
  var isClickOnPopup = popupRef && popupRef.contains(target);
68
90
  var isClickOnTrigger = triggerRef && triggerRef.contains(target);
@@ -108,7 +108,8 @@ export const PopupContent = ({
108
108
  shouldUseCaptureOnOutsideClick = false,
109
109
  shouldRenderToParent,
110
110
  shouldDisableFocusLock = false,
111
- shouldFitContainer
111
+ shouldFitContainer,
112
+ shouldFitViewport
112
113
  }) => {
113
114
  useEnsureIsInsidePopup();
114
115
  const isOpen = useContext(IsOpenContext);
@@ -138,7 +139,8 @@ export const PopupContent = ({
138
139
  shouldRenderToParent: shouldRenderToParent,
139
140
  shouldDisableFocusLock: shouldDisableFocusLock,
140
141
  triggerRef: triggerRef,
141
- strategy: strategy
142
+ strategy: strategy,
143
+ shouldFitViewport: shouldFitViewport
142
144
  }));
143
145
  if (shouldRenderToParent) {
144
146
  return popperWrapper;
@@ -5,7 +5,9 @@ import _extends from "@babel/runtime/helpers/extends";
5
5
  */
6
6
  import { forwardRef, useMemo, useState } from 'react';
7
7
  import { css, jsx } from '@emotion/react';
8
+ import FocusRing from '@atlaskit/focus-ring';
8
9
  import { UNSAFE_useLayering } from '@atlaskit/layering';
10
+ import { fg } from '@atlaskit/platform-feature-flags';
9
11
  import { Popper } from '@atlaskit/popper';
10
12
  import { N0, N50A, N60A } from '@atlaskit/theme/colors';
11
13
  import { layers } from '@atlaskit/theme/constants';
@@ -74,7 +76,8 @@ function PopperWrapper({
74
76
  role,
75
77
  label,
76
78
  titleId,
77
- modifiers
79
+ modifiers,
80
+ shouldFitViewport
78
81
  }) {
79
82
  const [popupRef, setPopupRef] = useState(null);
80
83
  const [initialFocusRef, setInitialFocusRef] = useState(null);
@@ -119,14 +122,15 @@ function PopperWrapper({
119
122
  placement: placement,
120
123
  offset: offset,
121
124
  modifiers: mergedModifiers,
122
- strategy: strategy
125
+ strategy: strategy,
126
+ shouldFitViewport: shouldFitViewport
123
127
  }, ({
124
128
  ref,
125
129
  style,
126
130
  placement,
127
131
  update
128
132
  }) => {
129
- return jsx(PopupContainer, {
133
+ const popupContainer = jsx(PopupContainer, {
130
134
  id: id,
131
135
  "data-ds--level": currentLevel,
132
136
  "data-placement": placement,
@@ -161,6 +165,7 @@ function PopperWrapper({
161
165
  onClose,
162
166
  setInitialFocusRef
163
167
  })));
168
+ return !initialFocusRef && fg('platform-design-system-apply-popup-wrapper-focus') ? jsx(FocusRing, null, popupContainer) : popupContainer;
164
169
  });
165
170
  }
166
171
 
@@ -46,7 +46,8 @@ export const Popup = /*#__PURE__*/memo(({
46
46
  role,
47
47
  label,
48
48
  titleId,
49
- modifiers
49
+ modifiers,
50
+ shouldFitViewport
50
51
  }) => {
51
52
  const [triggerRef, setTriggerRef] = useState(null);
52
53
  const getMergedTriggerRef = useGetMemoizedMergedTriggerRef();
@@ -79,7 +80,8 @@ export const Popup = /*#__PURE__*/memo(({
79
80
  role: role,
80
81
  label: label,
81
82
  titleId: titleId,
82
- modifiers: modifiers
83
+ modifiers: modifiers,
84
+ shouldFitViewport: shouldFitViewport
83
85
  }));
84
86
  const popupContent = jsx(Manager, null, jsx(Reference, null, ({
85
87
  ref
@@ -31,14 +31,25 @@ export const useCloseManager = ({
31
31
  }
32
32
  const closePopup = event => {
33
33
  if (onClose) {
34
- onClose(event);
34
+ if (fg('sibling-dropdown-close-issue')) {
35
+ let currentLevel = null;
36
+ if (event.target instanceof HTMLElement) {
37
+ var _event$target$closest;
38
+ currentLevel = (_event$target$closest = event.target.closest(`[data-ds--level]`)) === null || _event$target$closest === void 0 ? void 0 : _event$target$closest.getAttribute('data-ds--level');
39
+ }
40
+ currentLevel ? onClose(event, Number(currentLevel)) : onClose(event);
41
+ } else {
42
+ onClose(event);
43
+ }
35
44
  }
36
45
  if (shouldDisableFocusTrap && fg('platform_dst_popup-disable-focuslock')) {
37
46
  // Restoring the normal focus order for trigger.
38
- triggerRef === null || triggerRef === void 0 ? void 0 : triggerRef.setAttribute('tabindex', '0');
39
- if (popupRef && autoFocus) {
40
- popupRef.setAttribute('tabindex', '0');
41
- }
47
+ requestFrame(() => {
48
+ triggerRef === null || triggerRef === void 0 ? void 0 : triggerRef.setAttribute('tabindex', '0');
49
+ if (popupRef && autoFocus) {
50
+ popupRef.setAttribute('tabindex', '0');
51
+ }
52
+ });
42
53
  }
43
54
  };
44
55
 
@@ -58,8 +69,19 @@ export const useCloseManager = ({
58
69
  return;
59
70
  }
60
71
  if (isLayerDisabled()) {
61
- //if it is a disabled layer, we need to disable its click listener.
62
- return;
72
+ //if it is a disabled layer, and we clicked inside a higher layer
73
+ //we will disable the click event
74
+ if (fg('design-system-closed-all-when-click-outside')) {
75
+ if (target instanceof HTMLElement) {
76
+ var _target$closest, _target$closest$call;
77
+ const levelOfClickedLayer = (_target$closest = target.closest) === null || _target$closest === void 0 ? void 0 : (_target$closest$call = _target$closest.call(target, `[data-ds--level]`)) === null || _target$closest$call === void 0 ? void 0 : _target$closest$call.getAttribute('data-ds--level');
78
+ if (levelOfClickedLayer && Number(levelOfClickedLayer) > currentLevel) {
79
+ return;
80
+ }
81
+ }
82
+ } else {
83
+ return;
84
+ }
63
85
  }
64
86
  const isClickOnPopup = popupRef && popupRef.contains(target);
65
87
  const isClickOnTrigger = triggerRef && triggerRef.contains(target);
@@ -119,7 +119,8 @@ export var PopupContent = function PopupContent(_ref4) {
119
119
  shouldRenderToParent = _ref4.shouldRenderToParent,
120
120
  _ref4$shouldDisableFo = _ref4.shouldDisableFocusLock,
121
121
  shouldDisableFocusLock = _ref4$shouldDisableFo === void 0 ? false : _ref4$shouldDisableFo,
122
- shouldFitContainer = _ref4.shouldFitContainer;
122
+ shouldFitContainer = _ref4.shouldFitContainer,
123
+ shouldFitViewport = _ref4.shouldFitViewport;
123
124
  useEnsureIsInsidePopup();
124
125
  var isOpen = useContext(IsOpenContext);
125
126
  var id = useContext(IdContext);
@@ -148,7 +149,8 @@ export var PopupContent = function PopupContent(_ref4) {
148
149
  shouldRenderToParent: shouldRenderToParent,
149
150
  shouldDisableFocusLock: shouldDisableFocusLock,
150
151
  triggerRef: triggerRef,
151
- strategy: strategy
152
+ strategy: strategy,
153
+ shouldFitViewport: shouldFitViewport
152
154
  }));
153
155
  if (shouldRenderToParent) {
154
156
  return popperWrapper;
@@ -11,7 +11,9 @@ var _css;
11
11
  */
12
12
  import { forwardRef, useMemo, useState } from 'react';
13
13
  import { css, jsx } from '@emotion/react';
14
+ import FocusRing from '@atlaskit/focus-ring';
14
15
  import { UNSAFE_useLayering } from '@atlaskit/layering';
16
+ import { fg } from '@atlaskit/platform-feature-flags';
15
17
  import { Popper } from '@atlaskit/popper';
16
18
  import { N0, N50A, N60A } from '@atlaskit/theme/colors';
17
19
  import { layers } from '@atlaskit/theme/constants';
@@ -79,7 +81,8 @@ function PopperWrapper(_ref) {
79
81
  role = _ref.role,
80
82
  label = _ref.label,
81
83
  titleId = _ref.titleId,
82
- modifiers = _ref.modifiers;
84
+ modifiers = _ref.modifiers,
85
+ shouldFitViewport = _ref.shouldFitViewport;
83
86
  var _useState = useState(null),
84
87
  _useState2 = _slicedToArray(_useState, 2),
85
88
  popupRef = _useState2[0],
@@ -130,13 +133,14 @@ function PopperWrapper(_ref) {
130
133
  placement: placement,
131
134
  offset: offset,
132
135
  modifiers: mergedModifiers,
133
- strategy: strategy
136
+ strategy: strategy,
137
+ shouldFitViewport: shouldFitViewport
134
138
  }, function (_ref2) {
135
139
  var _ref3 = _ref2.ref,
136
140
  style = _ref2.style,
137
141
  placement = _ref2.placement,
138
142
  update = _ref2.update;
139
- return jsx(PopupContainer, {
143
+ var popupContainer = jsx(PopupContainer, {
140
144
  id: id,
141
145
  "data-ds--level": currentLevel,
142
146
  "data-placement": placement,
@@ -171,6 +175,7 @@ function PopperWrapper(_ref) {
171
175
  onClose: onClose,
172
176
  setInitialFocusRef: setInitialFocusRef
173
177
  })));
178
+ return !initialFocusRef && fg('platform-design-system-apply-popup-wrapper-focus') ? jsx(FocusRing, null, popupContainer) : popupContainer;
174
179
  });
175
180
  }
176
181
 
package/dist/esm/popup.js CHANGED
@@ -57,7 +57,8 @@ export var Popup = /*#__PURE__*/memo(function (_ref) {
57
57
  role = _ref.role,
58
58
  label = _ref.label,
59
59
  titleId = _ref.titleId,
60
- modifiers = _ref.modifiers;
60
+ modifiers = _ref.modifiers,
61
+ shouldFitViewport = _ref.shouldFitViewport;
61
62
  var _useState = useState(null),
62
63
  _useState2 = _slicedToArray(_useState, 2),
63
64
  triggerRef = _useState2[0],
@@ -92,7 +93,8 @@ export var Popup = /*#__PURE__*/memo(function (_ref) {
92
93
  role: role,
93
94
  label: label,
94
95
  titleId: titleId,
95
- modifiers: modifiers
96
+ modifiers: modifiers,
97
+ shouldFitViewport: shouldFitViewport
96
98
  }));
97
99
  var popupContent = jsx(Manager, null, jsx(Reference, null, function (_ref2) {
98
100
  var ref = _ref2.ref;
@@ -28,14 +28,25 @@ export var useCloseManager = function useCloseManager(_ref) {
28
28
  }
29
29
  var closePopup = function closePopup(event) {
30
30
  if (onClose) {
31
- onClose(event);
31
+ if (fg('sibling-dropdown-close-issue')) {
32
+ var _currentLevel = null;
33
+ if (event.target instanceof HTMLElement) {
34
+ var _event$target$closest;
35
+ _currentLevel = (_event$target$closest = event.target.closest("[data-ds--level]")) === null || _event$target$closest === void 0 ? void 0 : _event$target$closest.getAttribute('data-ds--level');
36
+ }
37
+ _currentLevel ? onClose(event, Number(_currentLevel)) : onClose(event);
38
+ } else {
39
+ onClose(event);
40
+ }
32
41
  }
33
42
  if (shouldDisableFocusTrap && fg('platform_dst_popup-disable-focuslock')) {
34
43
  // Restoring the normal focus order for trigger.
35
- triggerRef === null || triggerRef === void 0 || triggerRef.setAttribute('tabindex', '0');
36
- if (popupRef && autoFocus) {
37
- popupRef.setAttribute('tabindex', '0');
38
- }
44
+ requestFrame(function () {
45
+ triggerRef === null || triggerRef === void 0 || triggerRef.setAttribute('tabindex', '0');
46
+ if (popupRef && autoFocus) {
47
+ popupRef.setAttribute('tabindex', '0');
48
+ }
49
+ });
39
50
  }
40
51
  };
41
52
 
@@ -53,8 +64,19 @@ export var useCloseManager = function useCloseManager(_ref) {
53
64
  return;
54
65
  }
55
66
  if (isLayerDisabled()) {
56
- //if it is a disabled layer, we need to disable its click listener.
57
- return;
67
+ //if it is a disabled layer, and we clicked inside a higher layer
68
+ //we will disable the click event
69
+ if (fg('design-system-closed-all-when-click-outside')) {
70
+ if (target instanceof HTMLElement) {
71
+ var _target$closest;
72
+ var levelOfClickedLayer = (_target$closest = target.closest) === null || _target$closest === void 0 || (_target$closest = _target$closest.call(target, "[data-ds--level]")) === null || _target$closest === void 0 ? void 0 : _target$closest.getAttribute('data-ds--level');
73
+ if (levelOfClickedLayer && Number(levelOfClickedLayer) > currentLevel) {
74
+ return;
75
+ }
76
+ }
77
+ } else {
78
+ return;
79
+ }
58
80
  }
59
81
  var isClickOnPopup = popupRef && popupRef.contains(target);
60
82
  var isClickOnTrigger = triggerRef && triggerRef.contains(target);
@@ -36,7 +36,7 @@ export type PopupTriggerProps = {
36
36
  * It must be a child of the Popup component.
37
37
  */
38
38
  export declare const PopupTrigger: ({ children }: PopupTriggerProps) => JSX.Element;
39
- type CommonContentPopupProps = Pick<LegacyPopupProps, 'boundary' | 'offset' | 'onClose' | 'testId' | 'placement' | 'fallbackPlacements' | 'popupComponent' | 'shouldFlip' | 'rootBoundary' | 'autoFocus' | 'shouldRenderToParent' | 'shouldUseCaptureOnOutsideClick' | 'shouldDisableFocusLock' | 'strategy' | 'zIndex'> & {
39
+ type CommonContentPopupProps = Pick<LegacyPopupProps, 'boundary' | 'offset' | 'onClose' | 'testId' | 'placement' | 'fallbackPlacements' | 'popupComponent' | 'shouldFlip' | 'rootBoundary' | 'autoFocus' | 'shouldRenderToParent' | 'shouldUseCaptureOnOutsideClick' | 'shouldDisableFocusLock' | 'strategy' | 'zIndex' | 'shouldFitViewport'> & {
40
40
  children: (props: ContentProps) => React.ReactNode;
41
41
  };
42
42
  type ShouldFitContainerContentPopupProps = CommonContentPopupProps & {
@@ -55,5 +55,5 @@ export type PopupContentProps = ShouldFitContainerContentPopupProps | StandardPo
55
55
  *
56
56
  * It must be a child of the Popup component.
57
57
  */
58
- export declare const PopupContent: ({ children, boundary, offset, strategy, onClose, testId, rootBoundary, shouldFlip, placement, fallbackPlacements, popupComponent, autoFocus, zIndex, shouldUseCaptureOnOutsideClick, shouldRenderToParent, shouldDisableFocusLock, shouldFitContainer, }: PopupContentProps) => JSX.Element | null;
58
+ export declare const PopupContent: ({ children, boundary, offset, strategy, onClose, testId, rootBoundary, shouldFlip, placement, fallbackPlacements, popupComponent, autoFocus, zIndex, shouldUseCaptureOnOutsideClick, shouldRenderToParent, shouldDisableFocusLock, shouldFitContainer, shouldFitViewport, }: PopupContentProps) => JSX.Element | null;
59
59
  export {};
@@ -1,4 +1,4 @@
1
1
  import { jsx } from '@emotion/react';
2
2
  import { type PopperWrapperProps } from './types';
3
- declare function PopperWrapper({ isOpen, id, offset, testId, content, fallbackPlacements, onClose, boundary, rootBoundary, shouldFlip, placement, popupComponent: PopupContainer, autoFocus, triggerRef, shouldUseCaptureOnOutsideClick, shouldRenderToParent, shouldFitContainer, shouldDisableFocusLock, shouldReturnFocus, strategy, role, label, titleId, modifiers, }: PopperWrapperProps): jsx.JSX.Element;
3
+ declare function PopperWrapper({ isOpen, id, offset, testId, content, fallbackPlacements, onClose, boundary, rootBoundary, shouldFlip, placement, popupComponent: PopupContainer, autoFocus, triggerRef, shouldUseCaptureOnOutsideClick, shouldRenderToParent, shouldFitContainer, shouldDisableFocusLock, shouldReturnFocus, strategy, role, label, titleId, modifiers, shouldFitViewport, }: PopperWrapperProps): jsx.JSX.Element;
4
4
  export default PopperWrapper;
@@ -5,6 +5,7 @@ export interface TriggerProps {
5
5
  'aria-controls'?: string;
6
6
  'aria-expanded': boolean;
7
7
  'aria-haspopup': boolean | 'dialog';
8
+ 'data-ds--level'?: string;
8
9
  }
9
10
  export type PopupRef = HTMLDivElement | null;
10
11
  export type TriggerRef = HTMLElement | HTMLButtonElement | null;
@@ -133,7 +134,7 @@ interface BaseProps {
133
134
  * This happens either when clicking away from the popup or pressing the escape key.
134
135
  * You'll want to use this to set open state accordingly, and then pump it back into the `isOpen` prop.
135
136
  */
136
- onClose?(event: Event | React.MouseEvent | React.KeyboardEvent): void;
137
+ onClose?(event: Event | React.MouseEvent | React.KeyboardEvent, currentLevel?: number | any): void;
137
138
  /**
138
139
  * The element that is shown when `isOpen` prop is `true`.
139
140
  * The result of the `content` prop will be placed as children here.
@@ -199,6 +200,11 @@ interface BaseProps {
199
200
  * for more details - https://popper.js.org/docs/v1/#modifiers
200
201
  */
201
202
  modifiers?: Partial<Modifier<string, object>>[];
203
+ /**
204
+ * Determines if the popup will have a `max-width` and `max-height` set to
205
+ * constrain it to the viewport.
206
+ */
207
+ shouldFitViewport?: boolean;
202
208
  }
203
209
  interface InternalPopupProps extends BaseProps {
204
210
  /**
@@ -36,7 +36,7 @@ export type PopupTriggerProps = {
36
36
  * It must be a child of the Popup component.
37
37
  */
38
38
  export declare const PopupTrigger: ({ children }: PopupTriggerProps) => JSX.Element;
39
- type CommonContentPopupProps = Pick<LegacyPopupProps, 'boundary' | 'offset' | 'onClose' | 'testId' | 'placement' | 'fallbackPlacements' | 'popupComponent' | 'shouldFlip' | 'rootBoundary' | 'autoFocus' | 'shouldRenderToParent' | 'shouldUseCaptureOnOutsideClick' | 'shouldDisableFocusLock' | 'strategy' | 'zIndex'> & {
39
+ type CommonContentPopupProps = Pick<LegacyPopupProps, 'boundary' | 'offset' | 'onClose' | 'testId' | 'placement' | 'fallbackPlacements' | 'popupComponent' | 'shouldFlip' | 'rootBoundary' | 'autoFocus' | 'shouldRenderToParent' | 'shouldUseCaptureOnOutsideClick' | 'shouldDisableFocusLock' | 'strategy' | 'zIndex' | 'shouldFitViewport'> & {
40
40
  children: (props: ContentProps) => React.ReactNode;
41
41
  };
42
42
  type ShouldFitContainerContentPopupProps = CommonContentPopupProps & {
@@ -55,5 +55,5 @@ export type PopupContentProps = ShouldFitContainerContentPopupProps | StandardPo
55
55
  *
56
56
  * It must be a child of the Popup component.
57
57
  */
58
- export declare const PopupContent: ({ children, boundary, offset, strategy, onClose, testId, rootBoundary, shouldFlip, placement, fallbackPlacements, popupComponent, autoFocus, zIndex, shouldUseCaptureOnOutsideClick, shouldRenderToParent, shouldDisableFocusLock, shouldFitContainer, }: PopupContentProps) => JSX.Element | null;
58
+ export declare const PopupContent: ({ children, boundary, offset, strategy, onClose, testId, rootBoundary, shouldFlip, placement, fallbackPlacements, popupComponent, autoFocus, zIndex, shouldUseCaptureOnOutsideClick, shouldRenderToParent, shouldDisableFocusLock, shouldFitContainer, shouldFitViewport, }: PopupContentProps) => JSX.Element | null;
59
59
  export {};
@@ -1,4 +1,4 @@
1
1
  import { jsx } from '@emotion/react';
2
2
  import { type PopperWrapperProps } from './types';
3
- declare function PopperWrapper({ isOpen, id, offset, testId, content, fallbackPlacements, onClose, boundary, rootBoundary, shouldFlip, placement, popupComponent: PopupContainer, autoFocus, triggerRef, shouldUseCaptureOnOutsideClick, shouldRenderToParent, shouldFitContainer, shouldDisableFocusLock, shouldReturnFocus, strategy, role, label, titleId, modifiers, }: PopperWrapperProps): jsx.JSX.Element;
3
+ declare function PopperWrapper({ isOpen, id, offset, testId, content, fallbackPlacements, onClose, boundary, rootBoundary, shouldFlip, placement, popupComponent: PopupContainer, autoFocus, triggerRef, shouldUseCaptureOnOutsideClick, shouldRenderToParent, shouldFitContainer, shouldDisableFocusLock, shouldReturnFocus, strategy, role, label, titleId, modifiers, shouldFitViewport, }: PopperWrapperProps): jsx.JSX.Element;
4
4
  export default PopperWrapper;
@@ -5,6 +5,7 @@ export interface TriggerProps {
5
5
  'aria-controls'?: string;
6
6
  'aria-expanded': boolean;
7
7
  'aria-haspopup': boolean | 'dialog';
8
+ 'data-ds--level'?: string;
8
9
  }
9
10
  export type PopupRef = HTMLDivElement | null;
10
11
  export type TriggerRef = HTMLElement | HTMLButtonElement | null;
@@ -136,7 +137,7 @@ interface BaseProps {
136
137
  * This happens either when clicking away from the popup or pressing the escape key.
137
138
  * You'll want to use this to set open state accordingly, and then pump it back into the `isOpen` prop.
138
139
  */
139
- onClose?(event: Event | React.MouseEvent | React.KeyboardEvent): void;
140
+ onClose?(event: Event | React.MouseEvent | React.KeyboardEvent, currentLevel?: number | any): void;
140
141
  /**
141
142
  * The element that is shown when `isOpen` prop is `true`.
142
143
  * The result of the `content` prop will be placed as children here.
@@ -202,6 +203,11 @@ interface BaseProps {
202
203
  * for more details - https://popper.js.org/docs/v1/#modifiers
203
204
  */
204
205
  modifiers?: Partial<Modifier<string, object>>[];
206
+ /**
207
+ * Determines if the popup will have a `max-width` and `max-height` set to
208
+ * constrain it to the viewport.
209
+ */
210
+ shouldFitViewport?: boolean;
205
211
  }
206
212
  interface InternalPopupProps extends BaseProps {
207
213
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/popup",
3
- "version": "1.24.2",
3
+ "version": "1.26.0",
4
4
  "description": "A popup displays brief content in an overlay.",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/"
@@ -37,13 +37,14 @@
37
37
  },
38
38
  "dependencies": {
39
39
  "@atlaskit/ds-lib": "^2.5.0",
40
+ "@atlaskit/focus-ring": "^1.6.0",
40
41
  "@atlaskit/layering": "^0.4.0",
41
42
  "@atlaskit/platform-feature-flags": "^0.3.0",
42
- "@atlaskit/popper": "^6.2.0",
43
+ "@atlaskit/popper": "^6.3.0",
43
44
  "@atlaskit/portal": "^4.9.0",
44
45
  "@atlaskit/primitives": "^12.1.0",
45
46
  "@atlaskit/theme": "^13.0.0",
46
- "@atlaskit/tokens": "^1.59.0",
47
+ "@atlaskit/tokens": "^1.60.0",
47
48
  "@babel/runtime": "^7.0.0",
48
49
  "@emotion/react": "^11.7.1",
49
50
  "bind-event-listener": "^3.0.0",
@@ -60,10 +61,10 @@
60
61
  "@af/integration-testing": "*",
61
62
  "@af/visual-regression": "*",
62
63
  "@atlaskit/button": "^20.1.0",
63
- "@atlaskit/icon": "^22.15.0",
64
+ "@atlaskit/icon": "^22.18.0",
64
65
  "@atlaskit/ssr": "*",
65
66
  "@atlaskit/textfield": "^6.5.0",
66
- "@atlaskit/toggle": "^13.3.0",
67
+ "@atlaskit/toggle": "^13.4.0",
67
68
  "@atlaskit/visual-regression": "*",
68
69
  "@atlassian/feature-flags-test-utils": "*",
69
70
  "@testing-library/dom": "^10.1.0",
@@ -108,6 +109,15 @@
108
109
  },
109
110
  "platform-design-system-dsp-20476-dropdown-menu": {
110
111
  "type": "boolean"
112
+ },
113
+ "design-system-closed-all-when-click-outside": {
114
+ "type": "boolean"
115
+ },
116
+ "sibling-dropdown-close-issue": {
117
+ "type": "boolean"
118
+ },
119
+ "platform-design-system-apply-popup-wrapper-focus": {
120
+ "type": "boolean"
111
121
  }
112
122
  },
113
123
  "homepage": "https://atlassian.design/components/popup/"