@atlaskit/dropdown-menu 11.3.0 → 11.3.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,11 @@
1
1
  # @atlaskit/dropdown-menu
2
2
 
3
+ ## 11.3.1
4
+
5
+ ### Patch Changes
6
+
7
+ - [`61d8af6f398`](https://bitbucket.org/atlassian/atlassian-frontend/commits/61d8af6f398) - Adjusted the fallback placements for dropdown-menu to reduce how frequently the menu jumps while scrolling
8
+
3
9
  ## 11.3.0
4
10
 
5
11
  ### Minor Changes
@@ -63,7 +63,31 @@ var spinnerContainerStyles = (0, _core.css)({
63
63
  justifyContent: 'center'
64
64
  });
65
65
  var MAX_HEIGHT = "calc(100vh - ".concat(gridSize * 2, "px)");
66
- var fallbackPlacements = ['bottom', 'bottom-end', 'right-start', 'left-start', 'auto'];
66
+ var opposites = {
67
+ top: 'bottom',
68
+ bottom: 'top',
69
+ left: 'right',
70
+ right: 'left',
71
+ start: 'end',
72
+ auto: 'auto',
73
+ end: 'start'
74
+ };
75
+
76
+ var getFallbackPlacements = function getFallbackPlacements(placement) {
77
+ var placementPieces = placement.split('-');
78
+ var mainAxis = placementPieces[0]; // Left, right and auto placements can rely on standard popper sliding behaviour
79
+
80
+ if (!['top', 'bottom'].includes(mainAxis)) {
81
+ return undefined;
82
+ } // Top and bottom placements need to flip to the right/left to ensure
83
+ // long lists don't extend off the screen
84
+ else if (placementPieces.length === 2 && ['start', 'end'].includes(placementPieces[1])) {
85
+ var crossAxis = placementPieces[1];
86
+ return ["".concat(mainAxis), "".concat(mainAxis, "-").concat(opposites[crossAxis]), "".concat(opposites[mainAxis], "-").concat(crossAxis), "".concat(opposites[mainAxis]), "".concat(opposites[mainAxis], "-").concat(opposites[crossAxis]), 'auto'];
87
+ } else {
88
+ return ["".concat(mainAxis, "-start"), "".concat(mainAxis, "-end"), "".concat(opposites[mainAxis]), "".concat(opposites[mainAxis], "-start"), "".concat(opposites[mainAxis], "-end"), "auto"];
89
+ }
90
+ };
67
91
  /**
68
92
  * __Dropdown menu__
69
93
  *
@@ -74,6 +98,7 @@ var fallbackPlacements = ['bottom', 'bottom-end', 'right-start', 'left-start', '
74
98
  * - [Usage](https://atlassian.design/components/dropdown-menu/usage)
75
99
  */
76
100
 
101
+
77
102
  var DropdownMenu = function DropdownMenu(props) {
78
103
  var _props$defaultOpen = props.defaultOpen,
79
104
  defaultOpen = _props$defaultOpen === void 0 ? false : _props$defaultOpen,
@@ -108,6 +133,9 @@ var DropdownMenu = function DropdownMenu(props) {
108
133
  isTriggeredUsingKeyboard = _useState2[0],
109
134
  setTriggeredUsingKeyboard = _useState2[1];
110
135
 
136
+ var fallbackPlacements = (0, _react.useMemo)(function () {
137
+ return getFallbackPlacements(placement);
138
+ }, [placement]);
111
139
  var handleTriggerClicked = (0, _react.useCallback)( // TODO: event is an `any` and is being cast incorrectly
112
140
  // This means that the public type for `onOpenChange` is incorrect
113
141
  // current: (event: React.MouseEvent | React.KeyboardEvent) => void;
@@ -202,7 +230,7 @@ var DropdownMenu = function DropdownMenu(props) {
202
230
  isSelected: isLocalOpen,
203
231
  iconAfter: (0, _core.jsx)(_chevronDown.default, {
204
232
  size: "medium",
205
- label: "expand"
233
+ label: ""
206
234
  }),
207
235
  onClick: handleTriggerClicked,
208
236
  testId: testId && "".concat(testId, "--trigger")
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@atlaskit/dropdown-menu",
3
- "version": "11.3.0",
3
+ "version": "11.3.1",
4
4
  "sideEffects": false
5
5
  }
@@ -1,7 +1,7 @@
1
1
  import _extends from "@babel/runtime/helpers/extends";
2
2
 
3
3
  /** @jsx jsx */
4
- import { useCallback, useEffect, useState } from 'react';
4
+ import { useCallback, useEffect, useMemo, useState } from 'react';
5
5
  import { css, jsx } from '@emotion/core';
6
6
  import { bind } from 'bind-event-listener';
7
7
  import Button from '@atlaskit/button/standard-button';
@@ -26,7 +26,31 @@ const spinnerContainerStyles = css({
26
26
  justifyContent: 'center'
27
27
  });
28
28
  const MAX_HEIGHT = `calc(100vh - ${gridSize * 2}px)`;
29
- const fallbackPlacements = ['bottom', 'bottom-end', 'right-start', 'left-start', 'auto'];
29
+ const opposites = {
30
+ top: 'bottom',
31
+ bottom: 'top',
32
+ left: 'right',
33
+ right: 'left',
34
+ start: 'end',
35
+ auto: 'auto',
36
+ end: 'start'
37
+ };
38
+
39
+ const getFallbackPlacements = placement => {
40
+ const placementPieces = placement.split('-');
41
+ const mainAxis = placementPieces[0]; // Left, right and auto placements can rely on standard popper sliding behaviour
42
+
43
+ if (!['top', 'bottom'].includes(mainAxis)) {
44
+ return undefined;
45
+ } // Top and bottom placements need to flip to the right/left to ensure
46
+ // long lists don't extend off the screen
47
+ else if (placementPieces.length === 2 && ['start', 'end'].includes(placementPieces[1])) {
48
+ const crossAxis = placementPieces[1];
49
+ return [`${mainAxis}`, `${mainAxis}-${opposites[crossAxis]}`, `${opposites[mainAxis]}-${crossAxis}`, `${opposites[mainAxis]}`, `${opposites[mainAxis]}-${opposites[crossAxis]}`, 'auto'];
50
+ } else {
51
+ return [`${mainAxis}-start`, `${mainAxis}-end`, `${opposites[mainAxis]}`, `${opposites[mainAxis]}-start`, `${opposites[mainAxis]}-end`, `auto`];
52
+ }
53
+ };
30
54
  /**
31
55
  * __Dropdown menu__
32
56
  *
@@ -37,6 +61,7 @@ const fallbackPlacements = ['bottom', 'bottom-end', 'right-start', 'left-start',
37
61
  * - [Usage](https://atlassian.design/components/dropdown-menu/usage)
38
62
  */
39
63
 
64
+
40
65
  const DropdownMenu = props => {
41
66
  const {
42
67
  defaultOpen = false,
@@ -54,6 +79,7 @@ const DropdownMenu = props => {
54
79
  } = props;
55
80
  const [isLocalOpen, setLocalIsOpen] = useControlledState(isOpen, () => defaultOpen);
56
81
  const [isTriggeredUsingKeyboard, setTriggeredUsingKeyboard] = useState(false);
82
+ const fallbackPlacements = useMemo(() => getFallbackPlacements(placement), [placement]);
57
83
  const handleTriggerClicked = useCallback( // TODO: event is an `any` and is being cast incorrectly
58
84
  // This means that the public type for `onOpenChange` is incorrect
59
85
  // current: (event: React.MouseEvent | React.KeyboardEvent) => void;
@@ -152,7 +178,7 @@ const DropdownMenu = props => {
152
178
  isSelected: isLocalOpen,
153
179
  iconAfter: jsx(ExpandIcon, {
154
180
  size: "medium",
155
- label: "expand"
181
+ label: ""
156
182
  }),
157
183
  onClick: handleTriggerClicked,
158
184
  testId: testId && `${testId}--trigger`
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@atlaskit/dropdown-menu",
3
- "version": "11.3.0",
3
+ "version": "11.3.1",
4
4
  "sideEffects": false
5
5
  }
@@ -9,7 +9,7 @@ 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, useEffect, useState } from 'react';
12
+ import { useCallback, useEffect, useMemo, useState } from 'react';
13
13
  import { css, jsx } from '@emotion/core';
14
14
  import { bind } from 'bind-event-listener';
15
15
  import Button from '@atlaskit/button/standard-button';
@@ -34,7 +34,31 @@ var spinnerContainerStyles = css({
34
34
  justifyContent: 'center'
35
35
  });
36
36
  var MAX_HEIGHT = "calc(100vh - ".concat(gridSize * 2, "px)");
37
- var fallbackPlacements = ['bottom', 'bottom-end', 'right-start', 'left-start', 'auto'];
37
+ var opposites = {
38
+ top: 'bottom',
39
+ bottom: 'top',
40
+ left: 'right',
41
+ right: 'left',
42
+ start: 'end',
43
+ auto: 'auto',
44
+ end: 'start'
45
+ };
46
+
47
+ var getFallbackPlacements = function getFallbackPlacements(placement) {
48
+ var placementPieces = placement.split('-');
49
+ var mainAxis = placementPieces[0]; // Left, right and auto placements can rely on standard popper sliding behaviour
50
+
51
+ if (!['top', 'bottom'].includes(mainAxis)) {
52
+ return undefined;
53
+ } // Top and bottom placements need to flip to the right/left to ensure
54
+ // long lists don't extend off the screen
55
+ else if (placementPieces.length === 2 && ['start', 'end'].includes(placementPieces[1])) {
56
+ var crossAxis = placementPieces[1];
57
+ return ["".concat(mainAxis), "".concat(mainAxis, "-").concat(opposites[crossAxis]), "".concat(opposites[mainAxis], "-").concat(crossAxis), "".concat(opposites[mainAxis]), "".concat(opposites[mainAxis], "-").concat(opposites[crossAxis]), 'auto'];
58
+ } else {
59
+ return ["".concat(mainAxis, "-start"), "".concat(mainAxis, "-end"), "".concat(opposites[mainAxis]), "".concat(opposites[mainAxis], "-start"), "".concat(opposites[mainAxis], "-end"), "auto"];
60
+ }
61
+ };
38
62
  /**
39
63
  * __Dropdown menu__
40
64
  *
@@ -45,6 +69,7 @@ var fallbackPlacements = ['bottom', 'bottom-end', 'right-start', 'left-start', '
45
69
  * - [Usage](https://atlassian.design/components/dropdown-menu/usage)
46
70
  */
47
71
 
72
+
48
73
  var DropdownMenu = function DropdownMenu(props) {
49
74
  var _props$defaultOpen = props.defaultOpen,
50
75
  defaultOpen = _props$defaultOpen === void 0 ? false : _props$defaultOpen,
@@ -79,6 +104,9 @@ var DropdownMenu = function DropdownMenu(props) {
79
104
  isTriggeredUsingKeyboard = _useState2[0],
80
105
  setTriggeredUsingKeyboard = _useState2[1];
81
106
 
107
+ var fallbackPlacements = useMemo(function () {
108
+ return getFallbackPlacements(placement);
109
+ }, [placement]);
82
110
  var handleTriggerClicked = useCallback( // TODO: event is an `any` and is being cast incorrectly
83
111
  // This means that the public type for `onOpenChange` is incorrect
84
112
  // current: (event: React.MouseEvent | React.KeyboardEvent) => void;
@@ -174,7 +202,7 @@ var DropdownMenu = function DropdownMenu(props) {
174
202
  isSelected: isLocalOpen,
175
203
  iconAfter: jsx(ExpandIcon, {
176
204
  size: "medium",
177
- label: "expand"
205
+ label: ""
178
206
  }),
179
207
  onClick: handleTriggerClicked,
180
208
  testId: testId && "".concat(testId, "--trigger")
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@atlaskit/dropdown-menu",
3
- "version": "11.3.0",
3
+ "version": "11.3.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.3.0",
3
+ "version": "11.3.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/"