@atlaskit/dropdown-menu 11.13.0 → 11.14.1
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 +17 -1
- package/dist/cjs/dropdown-menu.js +6 -13
- package/dist/cjs/internal/components/focus-manager.js +5 -15
- package/dist/cjs/internal/utils/handle-focus.js +2 -2
- package/dist/es2019/dropdown-menu.js +15 -24
- package/dist/es2019/internal/components/focus-manager.js +6 -16
- package/dist/es2019/internal/utils/handle-focus.js +2 -2
- package/dist/esm/dropdown-menu.js +7 -14
- package/dist/esm/internal/components/focus-manager.js +6 -16
- package/dist/esm/internal/utils/handle-focus.js +2 -2
- package/dist/types/internal/utils/handle-focus.d.ts +1 -2
- package/dist/types-ts4.5/internal/utils/handle-focus.d.ts +1 -2
- package/package.json +9 -5
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
# @atlaskit/dropdown-menu
|
|
2
2
|
|
|
3
|
+
## 11.14.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [`53444bfd55a`](https://bitbucket.org/atlassian/atlassian-frontend/commits/53444bfd55a) - Use 0 timeout to delay clean up after layering unmounted
|
|
8
|
+
|
|
9
|
+
## 11.14.0
|
|
10
|
+
|
|
11
|
+
### Minor Changes
|
|
12
|
+
|
|
13
|
+
- [`f355884a4aa`](https://bitbucket.org/atlassian/atlassian-frontend/commits/f355884a4aa) - [ux] Support to press escape key and only close the top layer
|
|
14
|
+
|
|
15
|
+
### Patch Changes
|
|
16
|
+
|
|
17
|
+
- Updated dependencies
|
|
18
|
+
|
|
3
19
|
## 11.13.0
|
|
4
20
|
|
|
5
21
|
### Minor Changes
|
|
@@ -1166,7 +1182,7 @@
|
|
|
1166
1182
|
|
|
1167
1183
|
## 6.1.20
|
|
1168
1184
|
|
|
1169
|
-
- [patch][fe943bb
|
|
1185
|
+
- [patch][fe943bb](https://bitbucket.org/atlassian/atlaskit-mk-2/commits/fe943bb"
|
|
1170
1186
|
d):
|
|
1171
1187
|
|
|
1172
1188
|
- Make sure we check userAgent only if we have a DOM
|
|
@@ -23,7 +23,6 @@ var _chevronDown = _interopRequireDefault(require("@atlaskit/icon/glyph/chevron-
|
|
|
23
23
|
var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
|
|
24
24
|
var _popup = _interopRequireDefault(require("@atlaskit/popup"));
|
|
25
25
|
var _constants = require("@atlaskit/theme/constants");
|
|
26
|
-
var _context = require("./internal/components/context");
|
|
27
26
|
var _focusManager = _interopRequireDefault(require("./internal/components/focus-manager"));
|
|
28
27
|
var _menuWrapper = _interopRequireDefault(require("./internal/components/menu-wrapper"));
|
|
29
28
|
var _selectionStore = _interopRequireDefault(require("./internal/context/selection-store"));
|
|
@@ -102,7 +101,6 @@ var DropdownMenu = function DropdownMenu(props) {
|
|
|
102
101
|
_useControlledState2 = (0, _slicedToArray2.default)(_useControlledState, 2),
|
|
103
102
|
isLocalOpen = _useControlledState2[0],
|
|
104
103
|
setLocalIsOpen = _useControlledState2[1];
|
|
105
|
-
var nestedLevel = (0, _react.useContext)(_context.NestedLevelContext);
|
|
106
104
|
var _useState = (0, _react.useState)(false),
|
|
107
105
|
_useState2 = (0, _slicedToArray2.default)(_useState, 2),
|
|
108
106
|
isTriggeredUsingKeyboard = _useState2[0],
|
|
@@ -176,14 +174,12 @@ var DropdownMenu = function DropdownMenu(props) {
|
|
|
176
174
|
});
|
|
177
175
|
}, [isFocused, isLocalOpen, handleTriggerClicked]);
|
|
178
176
|
var id = (0, _useGeneratedId.default)();
|
|
179
|
-
var isNested = nestedLevel > 0;
|
|
180
177
|
var itemRef = (0, _useRegisterItemWithFocusManager.default)();
|
|
181
178
|
return /*#__PURE__*/_react.default.createElement(_selectionStore.default, null, /*#__PURE__*/_react.default.createElement(_popup.default, {
|
|
182
179
|
id: isLocalOpen ? id : undefined,
|
|
183
180
|
shouldFlip: shouldFlip,
|
|
184
181
|
isOpen: isLocalOpen,
|
|
185
|
-
onClose:
|
|
186
|
-
,
|
|
182
|
+
onClose: handleOnClose,
|
|
187
183
|
zIndex: zIndex,
|
|
188
184
|
placement: placement,
|
|
189
185
|
fallbackPlacements: fallbackPlacements,
|
|
@@ -195,7 +191,7 @@ var DropdownMenu = function DropdownMenu(props) {
|
|
|
195
191
|
var ref = triggerProps.ref,
|
|
196
192
|
providedProps = (0, _objectWithoutProperties2.default)(triggerProps, _excluded);
|
|
197
193
|
return _trigger(_objectSpread(_objectSpread(_objectSpread({}, providedProps), bindFocus), {}, {
|
|
198
|
-
triggerRef:
|
|
194
|
+
triggerRef: (0, _mergeRefs.default)([ref, itemRef]),
|
|
199
195
|
isSelected: isLocalOpen,
|
|
200
196
|
onClick: handleTriggerClicked,
|
|
201
197
|
testId: testId && "".concat(testId, "--trigger")
|
|
@@ -208,7 +204,7 @@ var DropdownMenu = function DropdownMenu(props) {
|
|
|
208
204
|
}),
|
|
209
205
|
onFocus: bindFocus.onFocus,
|
|
210
206
|
onBlur: bindFocus.onBlur,
|
|
211
|
-
ref:
|
|
207
|
+
ref: (0, _mergeRefs.default)([triggerProps.ref, itemRef]),
|
|
212
208
|
"aria-controls": triggerProps['aria-controls'],
|
|
213
209
|
"aria-expanded": triggerProps['aria-expanded'],
|
|
214
210
|
"aria-haspopup": triggerProps['aria-haspopup'],
|
|
@@ -216,7 +212,7 @@ var DropdownMenu = function DropdownMenu(props) {
|
|
|
216
212
|
onClick: handleTriggerClicked,
|
|
217
213
|
testId: testId && "".concat(testId, "--trigger")
|
|
218
214
|
}, _trigger) : /*#__PURE__*/_react.default.createElement(_standardButton.default, (0, _extends2.default)({}, bindFocus, {
|
|
219
|
-
ref:
|
|
215
|
+
ref: (0, _mergeRefs.default)([triggerProps.ref, itemRef]),
|
|
220
216
|
"aria-controls": triggerProps['aria-controls'],
|
|
221
217
|
"aria-expanded": triggerProps['aria-expanded'],
|
|
222
218
|
"aria-haspopup": triggerProps['aria-haspopup'],
|
|
@@ -232,7 +228,7 @@ var DropdownMenu = function DropdownMenu(props) {
|
|
|
232
228
|
content: function content(_ref) {
|
|
233
229
|
var setInitialFocusRef = _ref.setInitialFocusRef,
|
|
234
230
|
update = _ref.update;
|
|
235
|
-
|
|
231
|
+
return /*#__PURE__*/_react.default.createElement(_focusManager.default, null, /*#__PURE__*/_react.default.createElement(_menuWrapper.default, {
|
|
236
232
|
spacing: spacing,
|
|
237
233
|
maxHeight: MAX_HEIGHT,
|
|
238
234
|
maxWidth: 800,
|
|
@@ -241,10 +237,7 @@ var DropdownMenu = function DropdownMenu(props) {
|
|
|
241
237
|
isLoading: isLoading,
|
|
242
238
|
statusLabel: statusLabel,
|
|
243
239
|
setInitialFocusRef: isTriggeredUsingKeyboard || autoFocus ? setInitialFocusRef : undefined
|
|
244
|
-
},
|
|
245
|
-
value: nestedLevel + 1
|
|
246
|
-
}, children)));
|
|
247
|
-
return isNested ? content : /*#__PURE__*/_react.default.createElement(_context.TrackLevelProvider, null, content);
|
|
240
|
+
}, children));
|
|
248
241
|
}
|
|
249
242
|
}));
|
|
250
243
|
};
|
|
@@ -9,8 +9,8 @@ exports.default = exports.FocusManagerContext = void 0;
|
|
|
9
9
|
var _react = _interopRequireWildcard(require("react"));
|
|
10
10
|
var _bindEventListener = require("bind-event-listener");
|
|
11
11
|
var _noop = _interopRequireDefault(require("@atlaskit/ds-lib/noop"));
|
|
12
|
+
var _layering = require("@atlaskit/layering");
|
|
12
13
|
var _handleFocus = _interopRequireDefault(require("../utils/handle-focus"));
|
|
13
|
-
var _context = require("./context");
|
|
14
14
|
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); }
|
|
15
15
|
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; }
|
|
16
16
|
/**
|
|
@@ -38,24 +38,14 @@ var FocusManager = function FocusManager(_ref) {
|
|
|
38
38
|
menuItemRefs.current.push(ref);
|
|
39
39
|
}
|
|
40
40
|
}, []);
|
|
41
|
-
var
|
|
42
|
-
|
|
43
|
-
maxLevelRef = _useContext.maxLevelRef,
|
|
44
|
-
setMaxLevel = _useContext.setMaxLevel;
|
|
41
|
+
var _UNSAFE_useLayering = (0, _layering.UNSAFE_useLayering)(),
|
|
42
|
+
isLayerDisabled = _UNSAFE_useLayering.isLayerDisabled;
|
|
45
43
|
// Intentionally rebinding on each render
|
|
46
44
|
(0, _react.useEffect)(function () {
|
|
47
|
-
|
|
48
|
-
setMaxLevel(nestedLevel);
|
|
49
|
-
var unbind = (0, _bindEventListener.bind)(window, {
|
|
45
|
+
return (0, _bindEventListener.bind)(window, {
|
|
50
46
|
type: 'keydown',
|
|
51
|
-
listener: (0, _handleFocus.default)(menuItemRefs.current,
|
|
47
|
+
listener: (0, _handleFocus.default)(menuItemRefs.current, isLayerDisabled)
|
|
52
48
|
});
|
|
53
|
-
return function () {
|
|
54
|
-
// Always get the minimun level when multiple levels of menu are closed
|
|
55
|
-
// If the stored level is smaller, we won't update it
|
|
56
|
-
setMaxLevel(prevLevel, true);
|
|
57
|
-
unbind();
|
|
58
|
-
};
|
|
59
49
|
});
|
|
60
50
|
var contextValue = {
|
|
61
51
|
menuItemRefs: menuItemRefs.current,
|
|
@@ -41,13 +41,13 @@ var getPrevFocusableElement = function getPrevFocusableElement(refs, currentFocu
|
|
|
41
41
|
currentFocusedIdx--;
|
|
42
42
|
}
|
|
43
43
|
};
|
|
44
|
-
function handleFocus(refs,
|
|
44
|
+
function handleFocus(refs, isLayerDisabled) {
|
|
45
45
|
return function (e) {
|
|
46
46
|
var currentFocusedIdx = refs.findIndex(function (el) {
|
|
47
47
|
var _document$activeEleme;
|
|
48
48
|
return (_document$activeEleme = document.activeElement) === null || _document$activeEleme === void 0 ? void 0 : _document$activeEleme.isSameNode(el);
|
|
49
49
|
});
|
|
50
|
-
if (
|
|
50
|
+
if (isLayerDisabled()) {
|
|
51
51
|
// if it is a nested dropdown and the level of the given dropdown is not the current level,
|
|
52
52
|
// we don't need to have focus on it
|
|
53
53
|
return;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/extends";
|
|
2
|
-
import React, { useCallback,
|
|
2
|
+
import React, { useCallback, 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 { UNSAFE_BUTTON } from '@atlaskit/button/unsafe';
|
|
@@ -13,7 +13,6 @@ import { getBooleanFF } from '@atlaskit/platform-feature-flags';
|
|
|
13
13
|
import Popup from '@atlaskit/popup';
|
|
14
14
|
// eslint-disable-next-line @atlaskit/design-system/no-deprecated-imports
|
|
15
15
|
import { gridSize as gridSizeFn, layers } from '@atlaskit/theme/constants';
|
|
16
|
-
import { NestedLevelContext, TrackLevelProvider } from './internal/components/context';
|
|
17
16
|
import FocusManager from './internal/components/focus-manager';
|
|
18
17
|
import MenuWrapper from './internal/components/menu-wrapper';
|
|
19
18
|
import SelectionStore from './internal/context/selection-store';
|
|
@@ -76,7 +75,6 @@ const DropdownMenu = props => {
|
|
|
76
75
|
zIndex = layers.modal()
|
|
77
76
|
} = props;
|
|
78
77
|
const [isLocalOpen, setLocalIsOpen] = useControlledState(isOpen, () => defaultOpen);
|
|
79
|
-
const nestedLevel = useContext(NestedLevelContext);
|
|
80
78
|
const [isTriggeredUsingKeyboard, setTriggeredUsingKeyboard] = useState(false);
|
|
81
79
|
const fallbackPlacements = useMemo(() => getFallbackPlacements(placement), [placement]);
|
|
82
80
|
const handleTriggerClicked = useCallback(
|
|
@@ -148,14 +146,12 @@ const DropdownMenu = props => {
|
|
|
148
146
|
});
|
|
149
147
|
}, [isFocused, isLocalOpen, handleTriggerClicked]);
|
|
150
148
|
const id = useGeneratedId();
|
|
151
|
-
const isNested = nestedLevel > 0;
|
|
152
149
|
const itemRef = useRegisterItemWithFocusManager();
|
|
153
150
|
return /*#__PURE__*/React.createElement(SelectionStore, null, /*#__PURE__*/React.createElement(Popup, {
|
|
154
151
|
id: isLocalOpen ? id : undefined,
|
|
155
152
|
shouldFlip: shouldFlip,
|
|
156
153
|
isOpen: isLocalOpen,
|
|
157
|
-
onClose:
|
|
158
|
-
,
|
|
154
|
+
onClose: handleOnClose,
|
|
159
155
|
zIndex: zIndex,
|
|
160
156
|
placement: placement,
|
|
161
157
|
fallbackPlacements: fallbackPlacements,
|
|
@@ -171,7 +167,7 @@ const DropdownMenu = props => {
|
|
|
171
167
|
return trigger({
|
|
172
168
|
...providedProps,
|
|
173
169
|
...bindFocus,
|
|
174
|
-
triggerRef:
|
|
170
|
+
triggerRef: mergeRefs([ref, itemRef]),
|
|
175
171
|
isSelected: isLocalOpen,
|
|
176
172
|
onClick: handleTriggerClicked,
|
|
177
173
|
testId: testId && `${testId}--trigger`
|
|
@@ -184,7 +180,7 @@ const DropdownMenu = props => {
|
|
|
184
180
|
}),
|
|
185
181
|
onFocus: bindFocus.onFocus,
|
|
186
182
|
onBlur: bindFocus.onBlur,
|
|
187
|
-
ref:
|
|
183
|
+
ref: mergeRefs([triggerProps.ref, itemRef]),
|
|
188
184
|
"aria-controls": triggerProps['aria-controls'],
|
|
189
185
|
"aria-expanded": triggerProps['aria-expanded'],
|
|
190
186
|
"aria-haspopup": triggerProps['aria-haspopup'],
|
|
@@ -192,7 +188,7 @@ const DropdownMenu = props => {
|
|
|
192
188
|
onClick: handleTriggerClicked,
|
|
193
189
|
testId: testId && `${testId}--trigger`
|
|
194
190
|
}, trigger) : /*#__PURE__*/React.createElement(Button, _extends({}, bindFocus, {
|
|
195
|
-
ref:
|
|
191
|
+
ref: mergeRefs([triggerProps.ref, itemRef]),
|
|
196
192
|
"aria-controls": triggerProps['aria-controls'],
|
|
197
193
|
"aria-expanded": triggerProps['aria-expanded'],
|
|
198
194
|
"aria-haspopup": triggerProps['aria-haspopup'],
|
|
@@ -208,21 +204,16 @@ const DropdownMenu = props => {
|
|
|
208
204
|
content: ({
|
|
209
205
|
setInitialFocusRef,
|
|
210
206
|
update
|
|
211
|
-
}) => {
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
}, /*#__PURE__*/React.createElement(NestedLevelContext.Provider, {
|
|
222
|
-
value: nestedLevel + 1
|
|
223
|
-
}, children)));
|
|
224
|
-
return isNested ? content : /*#__PURE__*/React.createElement(TrackLevelProvider, null, content);
|
|
225
|
-
}
|
|
207
|
+
}) => /*#__PURE__*/React.createElement(FocusManager, null, /*#__PURE__*/React.createElement(MenuWrapper, {
|
|
208
|
+
spacing: spacing,
|
|
209
|
+
maxHeight: MAX_HEIGHT,
|
|
210
|
+
maxWidth: 800,
|
|
211
|
+
onClose: handleOnClose,
|
|
212
|
+
onUpdate: update,
|
|
213
|
+
isLoading: isLoading,
|
|
214
|
+
statusLabel: statusLabel,
|
|
215
|
+
setInitialFocusRef: isTriggeredUsingKeyboard || autoFocus ? setInitialFocusRef : undefined
|
|
216
|
+
}, children))
|
|
226
217
|
}));
|
|
227
218
|
};
|
|
228
219
|
export default DropdownMenu;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import React, { createContext, useCallback,
|
|
1
|
+
import React, { createContext, useCallback, useEffect, useRef } from 'react';
|
|
2
2
|
import { bind } from 'bind-event-listener';
|
|
3
3
|
import __noop from '@atlaskit/ds-lib/noop';
|
|
4
|
+
import { UNSAFE_useLayering } from '@atlaskit/layering';
|
|
4
5
|
import handleFocus from '../utils/handle-focus';
|
|
5
|
-
import { NestedLevelContext, TrackMaxLevelContext } from './context';
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
*
|
|
@@ -29,25 +29,15 @@ const FocusManager = ({
|
|
|
29
29
|
menuItemRefs.current.push(ref);
|
|
30
30
|
}
|
|
31
31
|
}, []);
|
|
32
|
-
const nestedLevel = useContext(NestedLevelContext);
|
|
33
32
|
const {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
} = useContext(TrackMaxLevelContext);
|
|
33
|
+
isLayerDisabled
|
|
34
|
+
} = UNSAFE_useLayering();
|
|
37
35
|
// Intentionally rebinding on each render
|
|
38
36
|
useEffect(() => {
|
|
39
|
-
|
|
40
|
-
setMaxLevel(nestedLevel);
|
|
41
|
-
const unbind = bind(window, {
|
|
37
|
+
return bind(window, {
|
|
42
38
|
type: 'keydown',
|
|
43
|
-
listener: handleFocus(menuItemRefs.current,
|
|
39
|
+
listener: handleFocus(menuItemRefs.current, isLayerDisabled)
|
|
44
40
|
});
|
|
45
|
-
return () => {
|
|
46
|
-
// Always get the minimun level when multiple levels of menu are closed
|
|
47
|
-
// If the stored level is smaller, we won't update it
|
|
48
|
-
setMaxLevel(prevLevel, true);
|
|
49
|
-
unbind();
|
|
50
|
-
};
|
|
51
41
|
});
|
|
52
42
|
const contextValue = {
|
|
53
43
|
menuItemRefs: menuItemRefs.current,
|
|
@@ -37,13 +37,13 @@ const getPrevFocusableElement = (refs, currentFocusedIdx) => {
|
|
|
37
37
|
currentFocusedIdx--;
|
|
38
38
|
}
|
|
39
39
|
};
|
|
40
|
-
export default function handleFocus(refs,
|
|
40
|
+
export default function handleFocus(refs, isLayerDisabled) {
|
|
41
41
|
return e => {
|
|
42
42
|
const currentFocusedIdx = refs.findIndex(el => {
|
|
43
43
|
var _document$activeEleme;
|
|
44
44
|
return (_document$activeEleme = document.activeElement) === null || _document$activeEleme === void 0 ? void 0 : _document$activeEleme.isSameNode(el);
|
|
45
45
|
});
|
|
46
|
-
if (
|
|
46
|
+
if (isLayerDisabled()) {
|
|
47
47
|
// if it is a nested dropdown and the level of the given dropdown is not the current level,
|
|
48
48
|
// we don't need to have focus on it
|
|
49
49
|
return;
|
|
@@ -5,7 +5,7 @@ import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
|
5
5
|
var _excluded = ["ref"];
|
|
6
6
|
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
7
7
|
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
8
|
-
import React, { useCallback,
|
|
8
|
+
import React, { useCallback, 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 { UNSAFE_BUTTON } from '@atlaskit/button/unsafe';
|
|
@@ -19,7 +19,6 @@ import { getBooleanFF } from '@atlaskit/platform-feature-flags';
|
|
|
19
19
|
import Popup from '@atlaskit/popup';
|
|
20
20
|
// eslint-disable-next-line @atlaskit/design-system/no-deprecated-imports
|
|
21
21
|
import { gridSize as gridSizeFn, layers } from '@atlaskit/theme/constants';
|
|
22
|
-
import { NestedLevelContext, TrackLevelProvider } from './internal/components/context';
|
|
23
22
|
import FocusManager from './internal/components/focus-manager';
|
|
24
23
|
import MenuWrapper from './internal/components/menu-wrapper';
|
|
25
24
|
import SelectionStore from './internal/context/selection-store';
|
|
@@ -93,7 +92,6 @@ var DropdownMenu = function DropdownMenu(props) {
|
|
|
93
92
|
_useControlledState2 = _slicedToArray(_useControlledState, 2),
|
|
94
93
|
isLocalOpen = _useControlledState2[0],
|
|
95
94
|
setLocalIsOpen = _useControlledState2[1];
|
|
96
|
-
var nestedLevel = useContext(NestedLevelContext);
|
|
97
95
|
var _useState = useState(false),
|
|
98
96
|
_useState2 = _slicedToArray(_useState, 2),
|
|
99
97
|
isTriggeredUsingKeyboard = _useState2[0],
|
|
@@ -167,14 +165,12 @@ var DropdownMenu = function DropdownMenu(props) {
|
|
|
167
165
|
});
|
|
168
166
|
}, [isFocused, isLocalOpen, handleTriggerClicked]);
|
|
169
167
|
var id = useGeneratedId();
|
|
170
|
-
var isNested = nestedLevel > 0;
|
|
171
168
|
var itemRef = useRegisterItemWithFocusManager();
|
|
172
169
|
return /*#__PURE__*/React.createElement(SelectionStore, null, /*#__PURE__*/React.createElement(Popup, {
|
|
173
170
|
id: isLocalOpen ? id : undefined,
|
|
174
171
|
shouldFlip: shouldFlip,
|
|
175
172
|
isOpen: isLocalOpen,
|
|
176
|
-
onClose:
|
|
177
|
-
,
|
|
173
|
+
onClose: handleOnClose,
|
|
178
174
|
zIndex: zIndex,
|
|
179
175
|
placement: placement,
|
|
180
176
|
fallbackPlacements: fallbackPlacements,
|
|
@@ -186,7 +182,7 @@ var DropdownMenu = function DropdownMenu(props) {
|
|
|
186
182
|
var ref = triggerProps.ref,
|
|
187
183
|
providedProps = _objectWithoutProperties(triggerProps, _excluded);
|
|
188
184
|
return _trigger(_objectSpread(_objectSpread(_objectSpread({}, providedProps), bindFocus), {}, {
|
|
189
|
-
triggerRef:
|
|
185
|
+
triggerRef: mergeRefs([ref, itemRef]),
|
|
190
186
|
isSelected: isLocalOpen,
|
|
191
187
|
onClick: handleTriggerClicked,
|
|
192
188
|
testId: testId && "".concat(testId, "--trigger")
|
|
@@ -199,7 +195,7 @@ var DropdownMenu = function DropdownMenu(props) {
|
|
|
199
195
|
}),
|
|
200
196
|
onFocus: bindFocus.onFocus,
|
|
201
197
|
onBlur: bindFocus.onBlur,
|
|
202
|
-
ref:
|
|
198
|
+
ref: mergeRefs([triggerProps.ref, itemRef]),
|
|
203
199
|
"aria-controls": triggerProps['aria-controls'],
|
|
204
200
|
"aria-expanded": triggerProps['aria-expanded'],
|
|
205
201
|
"aria-haspopup": triggerProps['aria-haspopup'],
|
|
@@ -207,7 +203,7 @@ var DropdownMenu = function DropdownMenu(props) {
|
|
|
207
203
|
onClick: handleTriggerClicked,
|
|
208
204
|
testId: testId && "".concat(testId, "--trigger")
|
|
209
205
|
}, _trigger) : /*#__PURE__*/React.createElement(Button, _extends({}, bindFocus, {
|
|
210
|
-
ref:
|
|
206
|
+
ref: mergeRefs([triggerProps.ref, itemRef]),
|
|
211
207
|
"aria-controls": triggerProps['aria-controls'],
|
|
212
208
|
"aria-expanded": triggerProps['aria-expanded'],
|
|
213
209
|
"aria-haspopup": triggerProps['aria-haspopup'],
|
|
@@ -223,7 +219,7 @@ var DropdownMenu = function DropdownMenu(props) {
|
|
|
223
219
|
content: function content(_ref) {
|
|
224
220
|
var setInitialFocusRef = _ref.setInitialFocusRef,
|
|
225
221
|
update = _ref.update;
|
|
226
|
-
|
|
222
|
+
return /*#__PURE__*/React.createElement(FocusManager, null, /*#__PURE__*/React.createElement(MenuWrapper, {
|
|
227
223
|
spacing: spacing,
|
|
228
224
|
maxHeight: MAX_HEIGHT,
|
|
229
225
|
maxWidth: 800,
|
|
@@ -232,10 +228,7 @@ var DropdownMenu = function DropdownMenu(props) {
|
|
|
232
228
|
isLoading: isLoading,
|
|
233
229
|
statusLabel: statusLabel,
|
|
234
230
|
setInitialFocusRef: isTriggeredUsingKeyboard || autoFocus ? setInitialFocusRef : undefined
|
|
235
|
-
},
|
|
236
|
-
value: nestedLevel + 1
|
|
237
|
-
}, children)));
|
|
238
|
-
return isNested ? content : /*#__PURE__*/React.createElement(TrackLevelProvider, null, content);
|
|
231
|
+
}, children));
|
|
239
232
|
}
|
|
240
233
|
}));
|
|
241
234
|
};
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import React, { createContext, useCallback,
|
|
1
|
+
import React, { createContext, useCallback, useEffect, useRef } from 'react';
|
|
2
2
|
import { bind } from 'bind-event-listener';
|
|
3
3
|
import __noop from '@atlaskit/ds-lib/noop';
|
|
4
|
+
import { UNSAFE_useLayering } from '@atlaskit/layering';
|
|
4
5
|
import handleFocus from '../utils/handle-focus';
|
|
5
|
-
import { NestedLevelContext, TrackMaxLevelContext } from './context';
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
*
|
|
@@ -28,24 +28,14 @@ var FocusManager = function FocusManager(_ref) {
|
|
|
28
28
|
menuItemRefs.current.push(ref);
|
|
29
29
|
}
|
|
30
30
|
}, []);
|
|
31
|
-
var
|
|
32
|
-
|
|
33
|
-
maxLevelRef = _useContext.maxLevelRef,
|
|
34
|
-
setMaxLevel = _useContext.setMaxLevel;
|
|
31
|
+
var _UNSAFE_useLayering = UNSAFE_useLayering(),
|
|
32
|
+
isLayerDisabled = _UNSAFE_useLayering.isLayerDisabled;
|
|
35
33
|
// Intentionally rebinding on each render
|
|
36
34
|
useEffect(function () {
|
|
37
|
-
|
|
38
|
-
setMaxLevel(nestedLevel);
|
|
39
|
-
var unbind = bind(window, {
|
|
35
|
+
return bind(window, {
|
|
40
36
|
type: 'keydown',
|
|
41
|
-
listener: handleFocus(menuItemRefs.current,
|
|
37
|
+
listener: handleFocus(menuItemRefs.current, isLayerDisabled)
|
|
42
38
|
});
|
|
43
|
-
return function () {
|
|
44
|
-
// Always get the minimun level when multiple levels of menu are closed
|
|
45
|
-
// If the stored level is smaller, we won't update it
|
|
46
|
-
setMaxLevel(prevLevel, true);
|
|
47
|
-
unbind();
|
|
48
|
-
};
|
|
49
39
|
});
|
|
50
40
|
var contextValue = {
|
|
51
41
|
menuItemRefs: menuItemRefs.current,
|
|
@@ -34,13 +34,13 @@ var getPrevFocusableElement = function getPrevFocusableElement(refs, currentFocu
|
|
|
34
34
|
currentFocusedIdx--;
|
|
35
35
|
}
|
|
36
36
|
};
|
|
37
|
-
export default function handleFocus(refs,
|
|
37
|
+
export default function handleFocus(refs, isLayerDisabled) {
|
|
38
38
|
return function (e) {
|
|
39
39
|
var currentFocusedIdx = refs.findIndex(function (el) {
|
|
40
40
|
var _document$activeEleme;
|
|
41
41
|
return (_document$activeEleme = document.activeElement) === null || _document$activeEleme === void 0 ? void 0 : _document$activeEleme.isSameNode(el);
|
|
42
42
|
});
|
|
43
|
-
if (
|
|
43
|
+
if (isLayerDisabled()) {
|
|
44
44
|
// if it is a nested dropdown and the level of the given dropdown is not the current level,
|
|
45
45
|
// we don't need to have focus on it
|
|
46
46
|
return;
|
|
@@ -1,3 +1,2 @@
|
|
|
1
|
-
import { MutableRefObject } from 'react';
|
|
2
1
|
import { FocusableElement } from '../../types';
|
|
3
|
-
export default function handleFocus(refs: Array<FocusableElement>,
|
|
2
|
+
export default function handleFocus(refs: Array<FocusableElement>, isLayerDisabled: () => boolean): (e: KeyboardEvent) => void;
|
|
@@ -1,3 +1,2 @@
|
|
|
1
|
-
import { MutableRefObject } from 'react';
|
|
2
1
|
import { FocusableElement } from '../../types';
|
|
3
|
-
export default function handleFocus(refs: Array<FocusableElement>,
|
|
2
|
+
export default function handleFocus(refs: Array<FocusableElement>, isLayerDisabled: () => boolean): (e: KeyboardEvent) => void;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/dropdown-menu",
|
|
3
|
-
"version": "11.
|
|
3
|
+
"version": "11.14.1",
|
|
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/"
|
|
@@ -31,17 +31,18 @@
|
|
|
31
31
|
}
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@atlaskit/button": "^16.
|
|
34
|
+
"@atlaskit/button": "^16.10.0",
|
|
35
35
|
"@atlaskit/codemod-utils": "^4.2.0",
|
|
36
36
|
"@atlaskit/ds-lib": "^2.2.0",
|
|
37
37
|
"@atlaskit/icon": "^21.12.0",
|
|
38
|
+
"@atlaskit/layering": "^0.2.0",
|
|
38
39
|
"@atlaskit/menu": "^1.10.0",
|
|
39
40
|
"@atlaskit/platform-feature-flags": "^0.2.2",
|
|
40
|
-
"@atlaskit/popup": "^1.
|
|
41
|
-
"@atlaskit/primitives": "^1.
|
|
41
|
+
"@atlaskit/popup": "^1.10.0",
|
|
42
|
+
"@atlaskit/primitives": "^1.6.0",
|
|
42
43
|
"@atlaskit/spinner": "^15.5.0",
|
|
43
44
|
"@atlaskit/theme": "^12.6.0",
|
|
44
|
-
"@atlaskit/tokens": "^1.
|
|
45
|
+
"@atlaskit/tokens": "^1.25.0",
|
|
45
46
|
"@atlaskit/visually-hidden": "^1.2.0",
|
|
46
47
|
"@babel/runtime": "^7.0.0",
|
|
47
48
|
"@emotion/react": "^11.7.1",
|
|
@@ -116,6 +117,9 @@
|
|
|
116
117
|
"platform.design-system-team.icon-button-spacing-fix_o1zc5": {
|
|
117
118
|
"type": "boolean",
|
|
118
119
|
"referenceOnly": "true"
|
|
120
|
+
},
|
|
121
|
+
"platform.design-system-team.layering_qmiw3": {
|
|
122
|
+
"type": "boolean"
|
|
119
123
|
}
|
|
120
124
|
},
|
|
121
125
|
"homepage": "https://atlassian.design/components/dropdown-menu/",
|