@atlaskit/dropdown-menu 11.11.0 → 11.11.2

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,17 @@
1
1
  # @atlaskit/dropdown-menu
2
2
 
3
+ ## 11.11.2
4
+
5
+ ### Patch Changes
6
+
7
+ - [`1ed303de3e8`](https://bitbucket.org/atlassian/atlassian-frontend/commits/1ed303de3e8) - Updated dependencies
8
+
9
+ ## 11.11.1
10
+
11
+ ### Patch Changes
12
+
13
+ - [`fd493dc2358`](https://bitbucket.org/atlassian/atlassian-frontend/commits/fd493dc2358) - [ux] support nested dropdown menu
14
+
3
15
  ## 11.11.0
4
16
 
5
17
  ### Minor Changes
@@ -24,7 +24,7 @@ var _constants = require("@atlaskit/theme/constants");
24
24
  var _focusManager = _interopRequireDefault(require("./internal/components/focus-manager"));
25
25
  var _menuWrapper = _interopRequireDefault(require("./internal/components/menu-wrapper"));
26
26
  var _selectionStore = _interopRequireDefault(require("./internal/context/selection-store"));
27
- var _useGeneratedId = _interopRequireDefault(require("./internal/utils/use-generated-id"));
27
+ var _useGeneratedId = _interopRequireWildcard(require("./internal/utils/use-generated-id"));
28
28
  var _excluded = ["ref"]; // eslint-disable-next-line @atlaskit/design-system/no-deprecated-imports
29
29
  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); }
30
30
  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; }
@@ -59,6 +59,7 @@ var getFallbackPlacements = function getFallbackPlacements(placement) {
59
59
  return ["".concat(mainAxis, "-start"), "".concat(mainAxis, "-end"), "".concat(opposites[mainAxis]), "".concat(opposites[mainAxis], "-start"), "".concat(opposites[mainAxis], "-end"), "auto"];
60
60
  }
61
61
  };
62
+ var NestedContext = /*#__PURE__*/(0, _react.createContext)(false);
62
63
 
63
64
  /**
64
65
  * __Dropdown menu__
@@ -96,6 +97,7 @@ var DropdownMenu = function DropdownMenu(props) {
96
97
  _useControlledState2 = (0, _slicedToArray2.default)(_useControlledState, 2),
97
98
  isLocalOpen = _useControlledState2[0],
98
99
  setLocalIsOpen = _useControlledState2[1];
100
+ var isNested = (0, _react.useContext)(NestedContext);
99
101
  var _useState = (0, _react.useState)(false),
100
102
  _useState2 = (0, _slicedToArray2.default)(_useState, 2),
101
103
  isTriggeredUsingKeyboard = _useState2[0],
@@ -128,6 +130,11 @@ var DropdownMenu = function DropdownMenu(props) {
128
130
  });
129
131
  }, [onOpenChange, isLocalOpen, setLocalIsOpen]);
130
132
  var handleOnClose = (0, _react.useCallback)(function (event) {
133
+ if (event.key !== 'Escape' && event.target.closest("[id^=".concat(_useGeneratedId.PREFIX, "] [aria-haspopup]"))) {
134
+ // Check if it is within dropdown and it is a trigger button
135
+ // if it is a nested dropdown, clicking trigger won't close the dropdown
136
+ return;
137
+ }
131
138
  var newValue = false;
132
139
  setLocalIsOpen(newValue);
133
140
  onOpenChange({
@@ -168,7 +175,8 @@ var DropdownMenu = function DropdownMenu(props) {
168
175
  id: isLocalOpen ? id : undefined,
169
176
  shouldFlip: shouldFlip,
170
177
  isOpen: isLocalOpen,
171
- onClose: handleOnClose,
178
+ onClose: isNested ? undefined : handleOnClose // only outmost parent needs onCloseHandler
179
+ ,
172
180
  zIndex: zIndex,
173
181
  placement: placement,
174
182
  fallbackPlacements: fallbackPlacements,
@@ -212,7 +220,9 @@ var DropdownMenu = function DropdownMenu(props) {
212
220
  isLoading: isLoading,
213
221
  statusLabel: statusLabel,
214
222
  setInitialFocusRef: isTriggeredUsingKeyboard || autoFocus ? setInitialFocusRef : undefined
215
- }, children));
223
+ }, isNested ? children : /*#__PURE__*/_react.default.createElement(NestedContext.Provider, {
224
+ value: true
225
+ }, children)));
216
226
  }
217
227
  }));
218
228
  };
@@ -3,9 +3,11 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
+ exports.PREFIX = void 0;
6
7
  exports.default = useGeneratedId;
7
8
  var _react = require("react");
8
9
  var PREFIX = 'ds--dropdown--';
10
+ exports.PREFIX = PREFIX;
9
11
  var generateRandomString = function generateRandomString() {
10
12
  return (// This string is used only on client side usually triggered after a user interaction.
11
13
  // Therefore, so there is no risk of mismatch
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@atlaskit/dropdown-menu",
3
- "version": "11.11.0",
3
+ "version": "11.11.2",
4
4
  "sideEffects": false
5
5
  }
@@ -1,5 +1,5 @@
1
1
  import _extends from "@babel/runtime/helpers/extends";
2
- import React, { useCallback, useEffect, useMemo, useState } from 'react';
2
+ import React, { createContext, useCallback, useContext, useEffect, useMemo, useState } from 'react';
3
3
  import { bind } from 'bind-event-listener';
4
4
  import Button from '@atlaskit/button/standard-button';
5
5
  import { KEY_DOWN } from '@atlaskit/ds-lib/keycodes';
@@ -14,7 +14,7 @@ import { gridSize as gridSizeFn, layers } from '@atlaskit/theme/constants';
14
14
  import FocusManager from './internal/components/focus-manager';
15
15
  import MenuWrapper from './internal/components/menu-wrapper';
16
16
  import SelectionStore from './internal/context/selection-store';
17
- import useGeneratedId from './internal/utils/use-generated-id';
17
+ import useGeneratedId, { PREFIX } from './internal/utils/use-generated-id';
18
18
  const gridSize = gridSizeFn();
19
19
  const MAX_HEIGHT = `calc(100vh - ${gridSize * 2}px)`;
20
20
  const opposites = {
@@ -44,6 +44,7 @@ const getFallbackPlacements = placement => {
44
44
  return [`${mainAxis}-start`, `${mainAxis}-end`, `${opposites[mainAxis]}`, `${opposites[mainAxis]}-start`, `${opposites[mainAxis]}-end`, `auto`];
45
45
  }
46
46
  };
47
+ const NestedContext = /*#__PURE__*/createContext(false);
47
48
 
48
49
  /**
49
50
  * __Dropdown menu__
@@ -71,6 +72,7 @@ const DropdownMenu = props => {
71
72
  zIndex = layers.modal()
72
73
  } = props;
73
74
  const [isLocalOpen, setLocalIsOpen] = useControlledState(isOpen, () => defaultOpen);
75
+ const isNested = useContext(NestedContext);
74
76
  const [isTriggeredUsingKeyboard, setTriggeredUsingKeyboard] = useState(false);
75
77
  const fallbackPlacements = useMemo(() => getFallbackPlacements(placement), [placement]);
76
78
  const handleTriggerClicked = useCallback(
@@ -100,6 +102,11 @@ const DropdownMenu = props => {
100
102
  });
101
103
  }, [onOpenChange, isLocalOpen, setLocalIsOpen]);
102
104
  const handleOnClose = useCallback(event => {
105
+ if (event.key !== 'Escape' && event.target.closest(`[id^=${PREFIX}] [aria-haspopup]`)) {
106
+ // Check if it is within dropdown and it is a trigger button
107
+ // if it is a nested dropdown, clicking trigger won't close the dropdown
108
+ return;
109
+ }
103
110
  const newValue = false;
104
111
  setLocalIsOpen(newValue);
105
112
  onOpenChange({
@@ -141,7 +148,8 @@ const DropdownMenu = props => {
141
148
  id: isLocalOpen ? id : undefined,
142
149
  shouldFlip: shouldFlip,
143
150
  isOpen: isLocalOpen,
144
- onClose: handleOnClose,
151
+ onClose: isNested ? undefined : handleOnClose // only outmost parent needs onCloseHandler
152
+ ,
145
153
  zIndex: zIndex,
146
154
  placement: placement,
147
155
  fallbackPlacements: fallbackPlacements,
@@ -189,7 +197,9 @@ const DropdownMenu = props => {
189
197
  isLoading: isLoading,
190
198
  statusLabel: statusLabel,
191
199
  setInitialFocusRef: isTriggeredUsingKeyboard || autoFocus ? setInitialFocusRef : undefined
192
- }, children))
200
+ }, isNested ? children : /*#__PURE__*/React.createElement(NestedContext.Provider, {
201
+ value: true
202
+ }, children)))
193
203
  }));
194
204
  };
195
205
  export default DropdownMenu;
@@ -1,5 +1,5 @@
1
1
  import { useRef } from 'react';
2
- const PREFIX = 'ds--dropdown--';
2
+ export const PREFIX = 'ds--dropdown--';
3
3
  const generateRandomString = () =>
4
4
  // This string is used only on client side usually triggered after a user interaction.
5
5
  // Therefore, so there is no risk of mismatch
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@atlaskit/dropdown-menu",
3
- "version": "11.11.0",
3
+ "version": "11.11.2",
4
4
  "sideEffects": false
5
5
  }
@@ -5,7 +5,7 @@ import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
5
5
  var _excluded = ["ref"];
6
6
  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; }
7
7
  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) { _defineProperty(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; }
8
- import React, { useCallback, useEffect, useMemo, useState } from 'react';
8
+ import React, { createContext, useCallback, useContext, useEffect, useMemo, useState } from 'react';
9
9
  import { bind } from 'bind-event-listener';
10
10
  import Button from '@atlaskit/button/standard-button';
11
11
  import { KEY_DOWN } from '@atlaskit/ds-lib/keycodes';
@@ -20,7 +20,7 @@ import { gridSize as gridSizeFn, layers } from '@atlaskit/theme/constants';
20
20
  import FocusManager from './internal/components/focus-manager';
21
21
  import MenuWrapper from './internal/components/menu-wrapper';
22
22
  import SelectionStore from './internal/context/selection-store';
23
- import useGeneratedId from './internal/utils/use-generated-id';
23
+ import useGeneratedId, { PREFIX } from './internal/utils/use-generated-id';
24
24
  var gridSize = gridSizeFn();
25
25
  var MAX_HEIGHT = "calc(100vh - ".concat(gridSize * 2, "px)");
26
26
  var opposites = {
@@ -50,6 +50,7 @@ var getFallbackPlacements = function getFallbackPlacements(placement) {
50
50
  return ["".concat(mainAxis, "-start"), "".concat(mainAxis, "-end"), "".concat(opposites[mainAxis]), "".concat(opposites[mainAxis], "-start"), "".concat(opposites[mainAxis], "-end"), "auto"];
51
51
  }
52
52
  };
53
+ var NestedContext = /*#__PURE__*/createContext(false);
53
54
 
54
55
  /**
55
56
  * __Dropdown menu__
@@ -87,6 +88,7 @@ var DropdownMenu = function DropdownMenu(props) {
87
88
  _useControlledState2 = _slicedToArray(_useControlledState, 2),
88
89
  isLocalOpen = _useControlledState2[0],
89
90
  setLocalIsOpen = _useControlledState2[1];
91
+ var isNested = useContext(NestedContext);
90
92
  var _useState = useState(false),
91
93
  _useState2 = _slicedToArray(_useState, 2),
92
94
  isTriggeredUsingKeyboard = _useState2[0],
@@ -119,6 +121,11 @@ var DropdownMenu = function DropdownMenu(props) {
119
121
  });
120
122
  }, [onOpenChange, isLocalOpen, setLocalIsOpen]);
121
123
  var handleOnClose = useCallback(function (event) {
124
+ if (event.key !== 'Escape' && event.target.closest("[id^=".concat(PREFIX, "] [aria-haspopup]"))) {
125
+ // Check if it is within dropdown and it is a trigger button
126
+ // if it is a nested dropdown, clicking trigger won't close the dropdown
127
+ return;
128
+ }
122
129
  var newValue = false;
123
130
  setLocalIsOpen(newValue);
124
131
  onOpenChange({
@@ -159,7 +166,8 @@ var DropdownMenu = function DropdownMenu(props) {
159
166
  id: isLocalOpen ? id : undefined,
160
167
  shouldFlip: shouldFlip,
161
168
  isOpen: isLocalOpen,
162
- onClose: handleOnClose,
169
+ onClose: isNested ? undefined : handleOnClose // only outmost parent needs onCloseHandler
170
+ ,
163
171
  zIndex: zIndex,
164
172
  placement: placement,
165
173
  fallbackPlacements: fallbackPlacements,
@@ -203,7 +211,9 @@ var DropdownMenu = function DropdownMenu(props) {
203
211
  isLoading: isLoading,
204
212
  statusLabel: statusLabel,
205
213
  setInitialFocusRef: isTriggeredUsingKeyboard || autoFocus ? setInitialFocusRef : undefined
206
- }, children));
214
+ }, isNested ? children : /*#__PURE__*/React.createElement(NestedContext.Provider, {
215
+ value: true
216
+ }, children)));
207
217
  }
208
218
  }));
209
219
  };
@@ -1,5 +1,5 @@
1
1
  import { useRef } from 'react';
2
- var PREFIX = 'ds--dropdown--';
2
+ export var PREFIX = 'ds--dropdown--';
3
3
  var generateRandomString = function generateRandomString() {
4
4
  return (// This string is used only on client side usually triggered after a user interaction.
5
5
  // Therefore, so there is no risk of mismatch
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@atlaskit/dropdown-menu",
3
- "version": "11.11.0",
3
+ "version": "11.11.2",
4
4
  "sideEffects": false
5
5
  }
@@ -1,3 +1,4 @@
1
+ export declare const PREFIX = "ds--dropdown--";
1
2
  /**
2
3
  * useGeneratedId generates a random string which remains constant across
3
4
  * renders when called without any parameter.
@@ -1,3 +1,4 @@
1
+ export declare const PREFIX = "ds--dropdown--";
1
2
  /**
2
3
  * useGeneratedId generates a random string which remains constant across
3
4
  * renders when called without any parameter.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/dropdown-menu",
3
- "version": "11.11.0",
3
+ "version": "11.11.2",
4
4
  "description": "A dropdown menu displays a list of actions or options to a user.",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/"
@@ -23,7 +23,7 @@
23
23
  "sideEffects": false,
24
24
  "atlaskit:src": "src/index.tsx",
25
25
  "atlassian": {
26
- "team": "Design System Team",
26
+ "team": "Design System Maker Experience",
27
27
  "releaseModel": "continuous",
28
28
  "website": {
29
29
  "name": "Dropdown menu",
@@ -38,7 +38,7 @@
38
38
  "@atlaskit/menu": "^1.9.0",
39
39
  "@atlaskit/platform-feature-flags": "^0.2.2",
40
40
  "@atlaskit/popup": "^1.9.0",
41
- "@atlaskit/primitives": "^1.0.0",
41
+ "@atlaskit/primitives": "^1.0.6",
42
42
  "@atlaskit/spinner": "^15.5.0",
43
43
  "@atlaskit/theme": "^12.5.0",
44
44
  "@atlaskit/tokens": "^1.13.0",