@atlaskit/dropdown-menu 11.2.0 → 11.2.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 CHANGED
@@ -1,5 +1,13 @@
1
1
  # @atlaskit/dropdown-menu
2
2
 
3
+ ## 11.2.1
4
+
5
+ ### Patch Changes
6
+
7
+ - [`347fd703ce0`](https://bitbucket.org/atlassian/atlassian-frontend/commits/347fd703ce0) - Internally shifting to using bind-event-listener for events added in effects
8
+ - [`ce9438bddd0`](https://bitbucket.org/atlassian/atlassian-frontend/commits/ce9438bddd0) - Internal TypeScript authoring improvement
9
+ - Updated dependencies
10
+
3
11
  ## 11.2.0
4
12
 
5
13
  ### Minor Changes
@@ -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)(function (event) {
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
- var handleDownArrow = function handleDownArrow(e) {
144
- if (e.key === _keycodes.KEY_DOWN) {
145
- // prevent page scroll
146
- e.preventDefault();
147
- handleTriggerClicked(e);
157
+
158
+ if (isLocalOpen) {
159
+ return _noop.default;
148
160
  }
149
- };
150
161
 
151
- (0, _useKeydownEvent.default)(handleDownArrow, isFocused);
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 _useKeydownEvent = _interopRequireDefault(require("@atlaskit/ds-lib/use-keydown-event"));
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: function registerRef(ref) {}
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
- (0, _useKeydownEvent.default)((0, _handleFocus.default)(menuItemRefs.current));
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
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@atlaskit/dropdown-menu",
3
- "version": "11.2.0",
3
+ "version": "11.2.1",
4
4
  "sideEffects": false
5
5
  }
@@ -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
- const handleDownArrow = e => {
92
- if (e.key === KEY_DOWN) {
93
- // prevent page scroll
94
- e.preventDefault();
95
- handleTriggerClicked(e);
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
- useKeydownEvent(handleDownArrow, isFocused);
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 useKeydownEvent from '@atlaskit/ds-lib/use-keydown-event';
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: ref => {}
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
- useKeydownEvent(handleFocus(menuItemRefs.current));
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
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@atlaskit/dropdown-menu",
3
- "version": "11.2.0",
3
+ "version": "11.2.1",
4
4
  "sideEffects": false
5
5
  }
@@ -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(function (event) {
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
- var handleDownArrow = function handleDownArrow(e) {
115
- if (e.key === KEY_DOWN) {
116
- // prevent page scroll
117
- e.preventDefault();
118
- handleTriggerClicked(e);
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
- useKeydownEvent(handleDownArrow, isFocused);
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 useKeydownEvent from '@atlaskit/ds-lib/use-keydown-event';
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: function registerRef(ref) {}
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
- useKeydownEvent(handleFocus(menuItemRefs.current));
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
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@atlaskit/dropdown-menu",
3
- "version": "11.2.0",
3
+ "version": "11.2.1",
4
4
  "sideEffects": false
5
5
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/dropdown-menu",
3
- "version": "11.2.0",
3
+ "version": "11.2.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/"
@@ -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
27
  "@atlaskit/codemod-utils": "^4.1.0",
27
- "@atlaskit/ds-lib": "^1.4.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,7 +34,8 @@
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.0"
37
39
  },
38
40
  "peerDependencies": {
39
41
  "react": "^16.8.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": [