@atlaskit/dropdown-menu 11.1.5 → 11.2.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 +25 -0
- package/dist/cjs/dropdown-menu-item.js +15 -5
- package/dist/cjs/dropdown-menu.js +32 -11
- package/dist/cjs/internal/components/focus-manager.js +12 -4
- package/dist/cjs/internal/utils/get-icon-colors.js +2 -2
- package/dist/cjs/version.json +1 -1
- package/dist/es2019/dropdown-menu-item.js +12 -3
- package/dist/es2019/dropdown-menu.js +31 -11
- package/dist/es2019/internal/components/focus-manager.js +12 -5
- package/dist/es2019/internal/utils/get-icon-colors.js +2 -2
- package/dist/es2019/version.json +1 -1
- package/dist/esm/dropdown-menu-item.js +14 -5
- package/dist/esm/dropdown-menu.js +32 -11
- package/dist/esm/internal/components/focus-manager.js +12 -5
- package/dist/esm/internal/utils/get-icon-colors.js +2 -2
- package/dist/esm/version.json +1 -1
- package/dist/types/internal/utils/get-icon-colors.d.ts +2 -2
- package/dist/types/types.d.ts +5 -1
- package/package.json +10 -7
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,30 @@
|
|
|
1
1
|
# @atlaskit/dropdown-menu
|
|
2
2
|
|
|
3
|
+
## 11.2.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [`8a5bdb3c844`](https://bitbucket.org/atlassian/atlassian-frontend/commits/8a5bdb3c844) - Upgrading internal dependency (bind-event-listener) for improved internal types
|
|
8
|
+
|
|
9
|
+
## 11.2.1
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- [`347fd703ce0`](https://bitbucket.org/atlassian/atlassian-frontend/commits/347fd703ce0) - Internally shifting to using bind-event-listener for events added in effects
|
|
14
|
+
- [`ce9438bddd0`](https://bitbucket.org/atlassian/atlassian-frontend/commits/ce9438bddd0) - Internal TypeScript authoring improvement
|
|
15
|
+
- Updated dependencies
|
|
16
|
+
|
|
17
|
+
## 11.2.0
|
|
18
|
+
|
|
19
|
+
### Minor Changes
|
|
20
|
+
|
|
21
|
+
- [`9a186cda60b`](https://bitbucket.org/atlassian/atlassian-frontend/commits/9a186cda60b) - Adds `component` prop to DropdownItem which allows overriding the item with a custom component.
|
|
22
|
+
|
|
23
|
+
### Patch Changes
|
|
24
|
+
|
|
25
|
+
- [`484bf3e9b12`](https://bitbucket.org/atlassian/atlassian-frontend/commits/484bf3e9b12) - [ux] DSP-4539 Update wrongly used tokens for radio/checkbox icons
|
|
26
|
+
- Updated dependencies
|
|
27
|
+
|
|
3
28
|
## 11.1.5
|
|
4
29
|
|
|
5
30
|
### Patch Changes
|
|
@@ -15,11 +15,13 @@ var _react = _interopRequireDefault(require("react"));
|
|
|
15
15
|
|
|
16
16
|
var _buttonItem = _interopRequireDefault(require("@atlaskit/menu/button-item"));
|
|
17
17
|
|
|
18
|
+
var _customItem = _interopRequireDefault(require("@atlaskit/menu/custom-item"));
|
|
19
|
+
|
|
18
20
|
var _linkItem = _interopRequireDefault(require("@atlaskit/menu/link-item"));
|
|
19
21
|
|
|
20
22
|
var _useRegisterItemWithFocusManager = _interopRequireDefault(require("./internal/hooks/use-register-item-with-focus-manager"));
|
|
21
23
|
|
|
22
|
-
var _excluded = ["
|
|
24
|
+
var _excluded = ["component", "elemBefore", "elemAfter", "shouldTitleWrap", "shouldDescriptionWrap"];
|
|
23
25
|
|
|
24
26
|
/**
|
|
25
27
|
* __Dropdown menu item__
|
|
@@ -31,9 +33,9 @@ var _excluded = ["elemBefore", "elemAfter", "href", "shouldTitleWrap", "shouldDe
|
|
|
31
33
|
* - [Usage](https://atlassian.design/components/dropdown-item/usage)
|
|
32
34
|
*/
|
|
33
35
|
var DropdownMenuItem = function DropdownMenuItem(props) {
|
|
34
|
-
var
|
|
36
|
+
var component = props.component,
|
|
37
|
+
elemBefore = props.elemBefore,
|
|
35
38
|
elemAfter = props.elemAfter,
|
|
36
|
-
href = props.href,
|
|
37
39
|
_props$shouldTitleWra = props.shouldTitleWrap,
|
|
38
40
|
shouldTitleWrap = _props$shouldTitleWra === void 0 ? true : _props$shouldTitleWra,
|
|
39
41
|
_props$shouldDescript = props.shouldDescriptionWrap,
|
|
@@ -41,9 +43,17 @@ var DropdownMenuItem = function DropdownMenuItem(props) {
|
|
|
41
43
|
rest = (0, _objectWithoutProperties2.default)(props, _excluded);
|
|
42
44
|
var itemRef = (0, _useRegisterItemWithFocusManager.default)();
|
|
43
45
|
|
|
44
|
-
if (
|
|
46
|
+
if (component) {
|
|
47
|
+
return /*#__PURE__*/_react.default.createElement(_customItem.default, (0, _extends2.default)({
|
|
48
|
+
component: component,
|
|
49
|
+
iconBefore: elemBefore,
|
|
50
|
+
iconAfter: elemAfter,
|
|
51
|
+
shouldTitleWrap: shouldTitleWrap,
|
|
52
|
+
shouldDescriptionWrap: shouldDescriptionWrap
|
|
53
|
+
}, rest));
|
|
54
|
+
} else if (props.href) {
|
|
45
55
|
return /*#__PURE__*/_react.default.createElement(_linkItem.default, (0, _extends2.default)({
|
|
46
|
-
href: href,
|
|
56
|
+
href: props.href,
|
|
47
57
|
iconBefore: elemBefore,
|
|
48
58
|
iconAfter: elemAfter,
|
|
49
59
|
role: "menuitem",
|
|
@@ -19,6 +19,8 @@ var _react = require("react");
|
|
|
19
19
|
|
|
20
20
|
var _core = require("@emotion/core");
|
|
21
21
|
|
|
22
|
+
var _bindEventListener = require("bind-event-listener");
|
|
23
|
+
|
|
22
24
|
var _standardButton = _interopRequireDefault(require("@atlaskit/button/standard-button"));
|
|
23
25
|
|
|
24
26
|
var _keycodes = require("@atlaskit/ds-lib/keycodes");
|
|
@@ -29,8 +31,6 @@ var _useControlled = _interopRequireDefault(require("@atlaskit/ds-lib/use-contro
|
|
|
29
31
|
|
|
30
32
|
var _useFocusEvent = _interopRequireDefault(require("@atlaskit/ds-lib/use-focus-event"));
|
|
31
33
|
|
|
32
|
-
var _useKeydownEvent = _interopRequireDefault(require("@atlaskit/ds-lib/use-keydown-event"));
|
|
33
|
-
|
|
34
34
|
var _chevronDown = _interopRequireDefault(require("@atlaskit/icon/glyph/chevron-down"));
|
|
35
35
|
|
|
36
36
|
var _popup = _interopRequireDefault(require("@atlaskit/popup"));
|
|
@@ -108,7 +108,12 @@ var DropdownMenu = function DropdownMenu(props) {
|
|
|
108
108
|
isTriggeredUsingKeyboard = _useState2[0],
|
|
109
109
|
setTriggeredUsingKeyboard = _useState2[1];
|
|
110
110
|
|
|
111
|
-
var handleTriggerClicked = (0, _react.useCallback)(
|
|
111
|
+
var handleTriggerClicked = (0, _react.useCallback)( // TODO: event is an `any` and is being cast incorrectly
|
|
112
|
+
// This means that the public type for `onOpenChange` is incorrect
|
|
113
|
+
// current: (event: React.MouseEvent | React.KeyboardEvent) => void;
|
|
114
|
+
// correct: (event: React.MouseEvent | KeyboardEvent) => void;
|
|
115
|
+
// https://product-fabric.atlassian.net/browse/DSP-4692
|
|
116
|
+
function (event) {
|
|
112
117
|
var newValue = !isLocalOpen;
|
|
113
118
|
var clientX = event.clientX,
|
|
114
119
|
clientY = event.clientY,
|
|
@@ -138,17 +143,33 @@ var DropdownMenu = function DropdownMenu(props) {
|
|
|
138
143
|
|
|
139
144
|
var _useFocus = (0, _useFocusEvent.default)(),
|
|
140
145
|
isFocused = _useFocus.isFocused,
|
|
141
|
-
bindFocus = _useFocus.bindFocus;
|
|
146
|
+
bindFocus = _useFocus.bindFocus; // When a trigger is focused, we want to open the dropdown if
|
|
147
|
+
// the user presses the DownArrow
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
(0, _react.useEffect)(function () {
|
|
151
|
+
// Only need to listen for keydown when focused
|
|
152
|
+
if (!isFocused) {
|
|
153
|
+
return _noop.default;
|
|
154
|
+
} // Being safe: we don't want to open the dropdown if it is already open
|
|
155
|
+
// Note: This shouldn't happen as the trigger should not be able to get focus
|
|
142
156
|
|
|
143
|
-
|
|
144
|
-
if (
|
|
145
|
-
|
|
146
|
-
e.preventDefault();
|
|
147
|
-
handleTriggerClicked(e);
|
|
157
|
+
|
|
158
|
+
if (isLocalOpen) {
|
|
159
|
+
return _noop.default;
|
|
148
160
|
}
|
|
149
|
-
};
|
|
150
161
|
|
|
151
|
-
|
|
162
|
+
return (0, _bindEventListener.bind)(window, {
|
|
163
|
+
type: 'keydown',
|
|
164
|
+
listener: function openOnKeyDown(e) {
|
|
165
|
+
if (e.key === _keycodes.KEY_DOWN) {
|
|
166
|
+
// prevent page scroll
|
|
167
|
+
e.preventDefault();
|
|
168
|
+
handleTriggerClicked(e);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
});
|
|
172
|
+
}, [isFocused, isLocalOpen, handleTriggerClicked]);
|
|
152
173
|
var id = (0, _useGeneratedId.default)();
|
|
153
174
|
return (0, _core.jsx)(_selectionStore.default, null, (0, _core.jsx)(_popup.default, {
|
|
154
175
|
id: isLocalOpen ? id : undefined,
|
|
@@ -11,7 +11,9 @@ exports.default = exports.FocusManagerContext = void 0;
|
|
|
11
11
|
|
|
12
12
|
var _react = _interopRequireWildcard(require("react"));
|
|
13
13
|
|
|
14
|
-
var
|
|
14
|
+
var _bindEventListener = require("bind-event-listener");
|
|
15
|
+
|
|
16
|
+
var _noop = _interopRequireDefault(require("@atlaskit/ds-lib/noop"));
|
|
15
17
|
|
|
16
18
|
var _handleFocus = _interopRequireDefault(require("../utils/handle-focus"));
|
|
17
19
|
|
|
@@ -29,7 +31,7 @@ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj &&
|
|
|
29
31
|
*/
|
|
30
32
|
var FocusManagerContext = /*#__PURE__*/(0, _react.createContext)({
|
|
31
33
|
menuItemRefs: [],
|
|
32
|
-
registerRef:
|
|
34
|
+
registerRef: _noop.default
|
|
33
35
|
});
|
|
34
36
|
/**
|
|
35
37
|
* Focus manager logic
|
|
@@ -44,8 +46,14 @@ var FocusManager = function FocusManager(_ref) {
|
|
|
44
46
|
if (ref && !menuItemRefs.current.includes(ref)) {
|
|
45
47
|
menuItemRefs.current.push(ref);
|
|
46
48
|
}
|
|
47
|
-
}, []);
|
|
48
|
-
|
|
49
|
+
}, []); // Intentionally rebinding on each render
|
|
50
|
+
|
|
51
|
+
(0, _react.useEffect)(function () {
|
|
52
|
+
return (0, _bindEventListener.bind)(window, {
|
|
53
|
+
type: 'keydown',
|
|
54
|
+
listener: (0, _handleFocus.default)(menuItemRefs.current)
|
|
55
|
+
});
|
|
56
|
+
});
|
|
49
57
|
var contextValue = {
|
|
50
58
|
menuItemRefs: menuItemRefs.current,
|
|
51
59
|
registerRef: registerRef
|
|
@@ -11,12 +11,12 @@ var getIconColors = function getIconColors(isSelected) {
|
|
|
11
11
|
if (isSelected) {
|
|
12
12
|
return {
|
|
13
13
|
primary: "var(--ds-background-brand-bold, ".concat(_colors.B400, ")"),
|
|
14
|
-
secondary: "var(--ds-
|
|
14
|
+
secondary: "var(--ds-icon-inverse, ".concat(_colors.N40, ")")
|
|
15
15
|
};
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
return {
|
|
19
|
-
primary: "var(--ds-
|
|
19
|
+
primary: "var(--ds-background-neutral, ".concat(_colors.N40, ")"),
|
|
20
20
|
secondary: "var(--ds-UNSAFE_util-transparent, ".concat(_colors.N40, ")")
|
|
21
21
|
};
|
|
22
22
|
};
|
package/dist/cjs/version.json
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/extends";
|
|
2
2
|
import React from 'react';
|
|
3
3
|
import ButtonItem from '@atlaskit/menu/button-item';
|
|
4
|
+
import CustomItem from '@atlaskit/menu/custom-item';
|
|
4
5
|
import LinkItem from '@atlaskit/menu/link-item';
|
|
5
6
|
import useRegisterItemWithFocusManager from './internal/hooks/use-register-item-with-focus-manager';
|
|
6
7
|
|
|
@@ -15,18 +16,26 @@ import useRegisterItemWithFocusManager from './internal/hooks/use-register-item-
|
|
|
15
16
|
*/
|
|
16
17
|
const DropdownMenuItem = props => {
|
|
17
18
|
const {
|
|
19
|
+
component,
|
|
18
20
|
elemBefore,
|
|
19
21
|
elemAfter,
|
|
20
|
-
href,
|
|
21
22
|
shouldTitleWrap = true,
|
|
22
23
|
shouldDescriptionWrap = true,
|
|
23
24
|
...rest
|
|
24
25
|
} = props;
|
|
25
26
|
const itemRef = useRegisterItemWithFocusManager();
|
|
26
27
|
|
|
27
|
-
if (
|
|
28
|
+
if (component) {
|
|
29
|
+
return /*#__PURE__*/React.createElement(CustomItem, _extends({
|
|
30
|
+
component: component,
|
|
31
|
+
iconBefore: elemBefore,
|
|
32
|
+
iconAfter: elemAfter,
|
|
33
|
+
shouldTitleWrap: shouldTitleWrap,
|
|
34
|
+
shouldDescriptionWrap: shouldDescriptionWrap
|
|
35
|
+
}, rest));
|
|
36
|
+
} else if (props.href) {
|
|
28
37
|
return /*#__PURE__*/React.createElement(LinkItem, _extends({
|
|
29
|
-
href: href,
|
|
38
|
+
href: props.href,
|
|
30
39
|
iconBefore: elemBefore,
|
|
31
40
|
iconAfter: elemAfter,
|
|
32
41
|
role: "menuitem",
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/extends";
|
|
2
2
|
|
|
3
3
|
/** @jsx jsx */
|
|
4
|
-
import { useCallback, useState } from 'react';
|
|
4
|
+
import { useCallback, useEffect, useState } from 'react';
|
|
5
5
|
import { css, jsx } from '@emotion/core';
|
|
6
|
+
import { bind } from 'bind-event-listener';
|
|
6
7
|
import Button from '@atlaskit/button/standard-button';
|
|
7
8
|
import { KEY_DOWN } from '@atlaskit/ds-lib/keycodes';
|
|
8
9
|
import noop from '@atlaskit/ds-lib/noop';
|
|
9
10
|
import useControlledState from '@atlaskit/ds-lib/use-controlled';
|
|
10
11
|
import useFocus from '@atlaskit/ds-lib/use-focus-event';
|
|
11
|
-
import useKeydownEvent from '@atlaskit/ds-lib/use-keydown-event';
|
|
12
12
|
import ExpandIcon from '@atlaskit/icon/glyph/chevron-down';
|
|
13
13
|
import Popup from '@atlaskit/popup';
|
|
14
14
|
import Spinner from '@atlaskit/spinner';
|
|
@@ -54,7 +54,12 @@ const DropdownMenu = props => {
|
|
|
54
54
|
} = props;
|
|
55
55
|
const [isLocalOpen, setLocalIsOpen] = useControlledState(isOpen, () => defaultOpen);
|
|
56
56
|
const [isTriggeredUsingKeyboard, setTriggeredUsingKeyboard] = useState(false);
|
|
57
|
-
const handleTriggerClicked = useCallback(event
|
|
57
|
+
const handleTriggerClicked = useCallback( // TODO: event is an `any` and is being cast incorrectly
|
|
58
|
+
// This means that the public type for `onOpenChange` is incorrect
|
|
59
|
+
// current: (event: React.MouseEvent | React.KeyboardEvent) => void;
|
|
60
|
+
// correct: (event: React.MouseEvent | KeyboardEvent) => void;
|
|
61
|
+
// https://product-fabric.atlassian.net/browse/DSP-4692
|
|
62
|
+
event => {
|
|
58
63
|
const newValue = !isLocalOpen;
|
|
59
64
|
const {
|
|
60
65
|
clientX,
|
|
@@ -86,17 +91,32 @@ const DropdownMenu = props => {
|
|
|
86
91
|
const {
|
|
87
92
|
isFocused,
|
|
88
93
|
bindFocus
|
|
89
|
-
} = useFocus();
|
|
94
|
+
} = useFocus(); // When a trigger is focused, we want to open the dropdown if
|
|
95
|
+
// the user presses the DownArrow
|
|
90
96
|
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
97
|
+
useEffect(() => {
|
|
98
|
+
// Only need to listen for keydown when focused
|
|
99
|
+
if (!isFocused) {
|
|
100
|
+
return noop;
|
|
101
|
+
} // Being safe: we don't want to open the dropdown if it is already open
|
|
102
|
+
// Note: This shouldn't happen as the trigger should not be able to get focus
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
if (isLocalOpen) {
|
|
106
|
+
return noop;
|
|
96
107
|
}
|
|
97
|
-
};
|
|
98
108
|
|
|
99
|
-
|
|
109
|
+
return bind(window, {
|
|
110
|
+
type: 'keydown',
|
|
111
|
+
listener: function openOnKeyDown(e) {
|
|
112
|
+
if (e.key === KEY_DOWN) {
|
|
113
|
+
// prevent page scroll
|
|
114
|
+
e.preventDefault();
|
|
115
|
+
handleTriggerClicked(e);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
});
|
|
119
|
+
}, [isFocused, isLocalOpen, handleTriggerClicked]);
|
|
100
120
|
const id = useGeneratedId();
|
|
101
121
|
return jsx(SelectionStore, null, jsx(Popup, {
|
|
102
122
|
id: isLocalOpen ? id : undefined,
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import React, { createContext, useCallback, useRef } from 'react';
|
|
2
|
-
import
|
|
1
|
+
import React, { createContext, useCallback, useEffect, useRef } from 'react';
|
|
2
|
+
import { bind } from 'bind-event-listener';
|
|
3
|
+
import __noop from '@atlaskit/ds-lib/noop';
|
|
3
4
|
import handleFocus from '../utils/handle-focus';
|
|
4
5
|
/**
|
|
5
6
|
*
|
|
@@ -12,7 +13,7 @@ import handleFocus from '../utils/handle-focus';
|
|
|
12
13
|
|
|
13
14
|
export const FocusManagerContext = /*#__PURE__*/createContext({
|
|
14
15
|
menuItemRefs: [],
|
|
15
|
-
registerRef:
|
|
16
|
+
registerRef: __noop
|
|
16
17
|
});
|
|
17
18
|
/**
|
|
18
19
|
* Focus manager logic
|
|
@@ -26,8 +27,14 @@ const FocusManager = ({
|
|
|
26
27
|
if (ref && !menuItemRefs.current.includes(ref)) {
|
|
27
28
|
menuItemRefs.current.push(ref);
|
|
28
29
|
}
|
|
29
|
-
}, []);
|
|
30
|
-
|
|
30
|
+
}, []); // Intentionally rebinding on each render
|
|
31
|
+
|
|
32
|
+
useEffect(() => {
|
|
33
|
+
return bind(window, {
|
|
34
|
+
type: 'keydown',
|
|
35
|
+
listener: handleFocus(menuItemRefs.current)
|
|
36
|
+
});
|
|
37
|
+
});
|
|
31
38
|
const contextValue = {
|
|
32
39
|
menuItemRefs: menuItemRefs.current,
|
|
33
40
|
registerRef
|
|
@@ -4,12 +4,12 @@ const getIconColors = isSelected => {
|
|
|
4
4
|
if (isSelected) {
|
|
5
5
|
return {
|
|
6
6
|
primary: `var(--ds-background-brand-bold, ${B400})`,
|
|
7
|
-
secondary: `var(--ds-
|
|
7
|
+
secondary: `var(--ds-icon-inverse, ${N40})`
|
|
8
8
|
};
|
|
9
9
|
}
|
|
10
10
|
|
|
11
11
|
return {
|
|
12
|
-
primary: `var(--ds-
|
|
12
|
+
primary: `var(--ds-background-neutral, ${N40})`,
|
|
13
13
|
secondary: `var(--ds-UNSAFE_util-transparent, ${N40})`
|
|
14
14
|
};
|
|
15
15
|
};
|
package/dist/es2019/version.json
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/extends";
|
|
2
2
|
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
|
|
3
|
-
var _excluded = ["
|
|
3
|
+
var _excluded = ["component", "elemBefore", "elemAfter", "shouldTitleWrap", "shouldDescriptionWrap"];
|
|
4
4
|
import React from 'react';
|
|
5
5
|
import ButtonItem from '@atlaskit/menu/button-item';
|
|
6
|
+
import CustomItem from '@atlaskit/menu/custom-item';
|
|
6
7
|
import LinkItem from '@atlaskit/menu/link-item';
|
|
7
8
|
import useRegisterItemWithFocusManager from './internal/hooks/use-register-item-with-focus-manager';
|
|
8
9
|
|
|
@@ -16,9 +17,9 @@ import useRegisterItemWithFocusManager from './internal/hooks/use-register-item-
|
|
|
16
17
|
* - [Usage](https://atlassian.design/components/dropdown-item/usage)
|
|
17
18
|
*/
|
|
18
19
|
var DropdownMenuItem = function DropdownMenuItem(props) {
|
|
19
|
-
var
|
|
20
|
+
var component = props.component,
|
|
21
|
+
elemBefore = props.elemBefore,
|
|
20
22
|
elemAfter = props.elemAfter,
|
|
21
|
-
href = props.href,
|
|
22
23
|
_props$shouldTitleWra = props.shouldTitleWrap,
|
|
23
24
|
shouldTitleWrap = _props$shouldTitleWra === void 0 ? true : _props$shouldTitleWra,
|
|
24
25
|
_props$shouldDescript = props.shouldDescriptionWrap,
|
|
@@ -27,9 +28,17 @@ var DropdownMenuItem = function DropdownMenuItem(props) {
|
|
|
27
28
|
|
|
28
29
|
var itemRef = useRegisterItemWithFocusManager();
|
|
29
30
|
|
|
30
|
-
if (
|
|
31
|
+
if (component) {
|
|
32
|
+
return /*#__PURE__*/React.createElement(CustomItem, _extends({
|
|
33
|
+
component: component,
|
|
34
|
+
iconBefore: elemBefore,
|
|
35
|
+
iconAfter: elemAfter,
|
|
36
|
+
shouldTitleWrap: shouldTitleWrap,
|
|
37
|
+
shouldDescriptionWrap: shouldDescriptionWrap
|
|
38
|
+
}, rest));
|
|
39
|
+
} else if (props.href) {
|
|
31
40
|
return /*#__PURE__*/React.createElement(LinkItem, _extends({
|
|
32
|
-
href: href,
|
|
41
|
+
href: props.href,
|
|
33
42
|
iconBefore: elemBefore,
|
|
34
43
|
iconAfter: elemAfter,
|
|
35
44
|
role: "menuitem",
|
|
@@ -9,14 +9,14 @@ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (O
|
|
|
9
9
|
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; }
|
|
10
10
|
|
|
11
11
|
/** @jsx jsx */
|
|
12
|
-
import { useCallback, useState } from 'react';
|
|
12
|
+
import { useCallback, useEffect, useState } from 'react';
|
|
13
13
|
import { css, jsx } from '@emotion/core';
|
|
14
|
+
import { bind } from 'bind-event-listener';
|
|
14
15
|
import Button from '@atlaskit/button/standard-button';
|
|
15
16
|
import { KEY_DOWN } from '@atlaskit/ds-lib/keycodes';
|
|
16
17
|
import noop from '@atlaskit/ds-lib/noop';
|
|
17
18
|
import useControlledState from '@atlaskit/ds-lib/use-controlled';
|
|
18
19
|
import useFocus from '@atlaskit/ds-lib/use-focus-event';
|
|
19
|
-
import useKeydownEvent from '@atlaskit/ds-lib/use-keydown-event';
|
|
20
20
|
import ExpandIcon from '@atlaskit/icon/glyph/chevron-down';
|
|
21
21
|
import Popup from '@atlaskit/popup';
|
|
22
22
|
import Spinner from '@atlaskit/spinner';
|
|
@@ -79,7 +79,12 @@ var DropdownMenu = function DropdownMenu(props) {
|
|
|
79
79
|
isTriggeredUsingKeyboard = _useState2[0],
|
|
80
80
|
setTriggeredUsingKeyboard = _useState2[1];
|
|
81
81
|
|
|
82
|
-
var handleTriggerClicked = useCallback(
|
|
82
|
+
var handleTriggerClicked = useCallback( // TODO: event is an `any` and is being cast incorrectly
|
|
83
|
+
// This means that the public type for `onOpenChange` is incorrect
|
|
84
|
+
// current: (event: React.MouseEvent | React.KeyboardEvent) => void;
|
|
85
|
+
// correct: (event: React.MouseEvent | KeyboardEvent) => void;
|
|
86
|
+
// https://product-fabric.atlassian.net/browse/DSP-4692
|
|
87
|
+
function (event) {
|
|
83
88
|
var newValue = !isLocalOpen;
|
|
84
89
|
var clientX = event.clientX,
|
|
85
90
|
clientY = event.clientY,
|
|
@@ -109,17 +114,33 @@ var DropdownMenu = function DropdownMenu(props) {
|
|
|
109
114
|
|
|
110
115
|
var _useFocus = useFocus(),
|
|
111
116
|
isFocused = _useFocus.isFocused,
|
|
112
|
-
bindFocus = _useFocus.bindFocus;
|
|
117
|
+
bindFocus = _useFocus.bindFocus; // When a trigger is focused, we want to open the dropdown if
|
|
118
|
+
// the user presses the DownArrow
|
|
113
119
|
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
120
|
+
|
|
121
|
+
useEffect(function () {
|
|
122
|
+
// Only need to listen for keydown when focused
|
|
123
|
+
if (!isFocused) {
|
|
124
|
+
return noop;
|
|
125
|
+
} // Being safe: we don't want to open the dropdown if it is already open
|
|
126
|
+
// Note: This shouldn't happen as the trigger should not be able to get focus
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
if (isLocalOpen) {
|
|
130
|
+
return noop;
|
|
119
131
|
}
|
|
120
|
-
};
|
|
121
132
|
|
|
122
|
-
|
|
133
|
+
return bind(window, {
|
|
134
|
+
type: 'keydown',
|
|
135
|
+
listener: function openOnKeyDown(e) {
|
|
136
|
+
if (e.key === KEY_DOWN) {
|
|
137
|
+
// prevent page scroll
|
|
138
|
+
e.preventDefault();
|
|
139
|
+
handleTriggerClicked(e);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
});
|
|
143
|
+
}, [isFocused, isLocalOpen, handleTriggerClicked]);
|
|
123
144
|
var id = useGeneratedId();
|
|
124
145
|
return jsx(SelectionStore, null, jsx(Popup, {
|
|
125
146
|
id: isLocalOpen ? id : undefined,
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import React, { createContext, useCallback, useRef } from 'react';
|
|
2
|
-
import
|
|
1
|
+
import React, { createContext, useCallback, useEffect, useRef } from 'react';
|
|
2
|
+
import { bind } from 'bind-event-listener';
|
|
3
|
+
import __noop from '@atlaskit/ds-lib/noop';
|
|
3
4
|
import handleFocus from '../utils/handle-focus';
|
|
4
5
|
/**
|
|
5
6
|
*
|
|
@@ -12,7 +13,7 @@ import handleFocus from '../utils/handle-focus';
|
|
|
12
13
|
|
|
13
14
|
export var FocusManagerContext = /*#__PURE__*/createContext({
|
|
14
15
|
menuItemRefs: [],
|
|
15
|
-
registerRef:
|
|
16
|
+
registerRef: __noop
|
|
16
17
|
});
|
|
17
18
|
/**
|
|
18
19
|
* Focus manager logic
|
|
@@ -25,8 +26,14 @@ var FocusManager = function FocusManager(_ref) {
|
|
|
25
26
|
if (ref && !menuItemRefs.current.includes(ref)) {
|
|
26
27
|
menuItemRefs.current.push(ref);
|
|
27
28
|
}
|
|
28
|
-
}, []);
|
|
29
|
-
|
|
29
|
+
}, []); // Intentionally rebinding on each render
|
|
30
|
+
|
|
31
|
+
useEffect(function () {
|
|
32
|
+
return bind(window, {
|
|
33
|
+
type: 'keydown',
|
|
34
|
+
listener: handleFocus(menuItemRefs.current)
|
|
35
|
+
});
|
|
36
|
+
});
|
|
30
37
|
var contextValue = {
|
|
31
38
|
menuItemRefs: menuItemRefs.current,
|
|
32
39
|
registerRef: registerRef
|
|
@@ -4,12 +4,12 @@ var getIconColors = function getIconColors(isSelected) {
|
|
|
4
4
|
if (isSelected) {
|
|
5
5
|
return {
|
|
6
6
|
primary: "var(--ds-background-brand-bold, ".concat(B400, ")"),
|
|
7
|
-
secondary: "var(--ds-
|
|
7
|
+
secondary: "var(--ds-icon-inverse, ".concat(N40, ")")
|
|
8
8
|
};
|
|
9
9
|
}
|
|
10
10
|
|
|
11
11
|
return {
|
|
12
|
-
primary: "var(--ds-
|
|
12
|
+
primary: "var(--ds-background-neutral, ".concat(N40, ")"),
|
|
13
13
|
secondary: "var(--ds-UNSAFE_util-transparent, ".concat(N40, ")")
|
|
14
14
|
};
|
|
15
15
|
};
|
package/dist/esm/version.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
declare const getIconColors: (isSelected: boolean | undefined) => {
|
|
2
2
|
primary: "var(--ds-background-brand-bold)";
|
|
3
|
-
secondary: "var(--ds-
|
|
3
|
+
secondary: "var(--ds-icon-inverse)";
|
|
4
4
|
} | {
|
|
5
|
-
primary: "var(--ds-
|
|
5
|
+
primary: "var(--ds-background-neutral)";
|
|
6
6
|
secondary: "var(--ds-UNSAFE_util-transparent)";
|
|
7
7
|
};
|
|
8
8
|
export default getIconColors;
|
package/dist/types/types.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { KeyboardEvent, MouseEvent, ReactElement, ReactNode, Ref } from 'react';
|
|
2
|
-
import type { MenuGroupProps, SectionProps } from '@atlaskit/menu/types';
|
|
2
|
+
import type { CustomItemProps, MenuGroupProps, SectionProps } from '@atlaskit/menu/types';
|
|
3
3
|
import type { ContentProps, TriggerProps } from '@atlaskit/popup/types';
|
|
4
4
|
export declare type FocusableElement = HTMLAnchorElement | HTMLButtonElement;
|
|
5
5
|
export declare type Action = 'next' | 'prev' | 'first' | 'last';
|
|
@@ -125,6 +125,10 @@ export interface DropdownItemProps {
|
|
|
125
125
|
* Primary content for the item.
|
|
126
126
|
*/
|
|
127
127
|
children: React.ReactNode;
|
|
128
|
+
/**
|
|
129
|
+
* Custom component to render as an item.
|
|
130
|
+
*/
|
|
131
|
+
component?: CustomItemProps['component'];
|
|
128
132
|
/**
|
|
129
133
|
* Description of the item.
|
|
130
134
|
* This will render smaller text below the primary text of the item as well as slightly increasing the height of the item.
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/dropdown-menu",
|
|
3
|
-
"version": "11.
|
|
3
|
+
"version": "11.2.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/"
|
|
7
7
|
},
|
|
8
|
-
"repository": "https://bitbucket.org/atlassian/atlassian-frontend",
|
|
8
|
+
"repository": "https://bitbucket.org/atlassian/atlassian-frontend-mirror",
|
|
9
9
|
"author": "Atlassian Pty Ltd",
|
|
10
10
|
"license": "Apache-2.0",
|
|
11
11
|
"main": "dist/cjs/index.js",
|
|
@@ -18,13 +18,14 @@
|
|
|
18
18
|
"team": "Design System Team",
|
|
19
19
|
"releaseModel": "scheduled",
|
|
20
20
|
"website": {
|
|
21
|
-
"name": "Dropdown menu"
|
|
21
|
+
"name": "Dropdown menu",
|
|
22
|
+
"category": "Components"
|
|
22
23
|
}
|
|
23
24
|
},
|
|
24
25
|
"dependencies": {
|
|
25
26
|
"@atlaskit/button": "^16.3.0",
|
|
26
|
-
"@atlaskit/codemod-utils": "^4.
|
|
27
|
-
"@atlaskit/ds-lib": "^
|
|
27
|
+
"@atlaskit/codemod-utils": "^4.1.0",
|
|
28
|
+
"@atlaskit/ds-lib": "^2.0.0",
|
|
28
29
|
"@atlaskit/icon": "^21.10.0",
|
|
29
30
|
"@atlaskit/menu": "^1.3.0",
|
|
30
31
|
"@atlaskit/popup": "^1.3.0",
|
|
@@ -33,14 +34,15 @@
|
|
|
33
34
|
"@atlaskit/tokens": "^0.10.0",
|
|
34
35
|
"@atlaskit/visually-hidden": "^1.0.0",
|
|
35
36
|
"@babel/runtime": "^7.0.0",
|
|
36
|
-
"@emotion/core": "^10.0.9"
|
|
37
|
+
"@emotion/core": "^10.0.9",
|
|
38
|
+
"bind-event-listener": "^2.1.1"
|
|
37
39
|
},
|
|
38
40
|
"peerDependencies": {
|
|
39
41
|
"react": "^16.8.0",
|
|
40
42
|
"react-dom": "^16.8.0"
|
|
41
43
|
},
|
|
42
44
|
"devDependencies": {
|
|
43
|
-
"@atlaskit/avatar": "^
|
|
45
|
+
"@atlaskit/avatar": "^21.0.0",
|
|
44
46
|
"@atlaskit/docs": "*",
|
|
45
47
|
"@atlaskit/lozenge": "11.1.11",
|
|
46
48
|
"@atlaskit/modal-dialog": "^12.2.0",
|
|
@@ -70,6 +72,7 @@
|
|
|
70
72
|
"import-structure": "atlassian-conventions"
|
|
71
73
|
},
|
|
72
74
|
"@repo/internal": {
|
|
75
|
+
"dom-events": "use-bind-event-listener",
|
|
73
76
|
"ui-components": "lite-mode",
|
|
74
77
|
"design-system": "v1",
|
|
75
78
|
"styling": [
|