@atlaskit/dropdown-menu 12.1.8 → 12.1.9

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
+ ## 12.1.9
4
+
5
+ ### Patch Changes
6
+
7
+ - [#59251](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/59251) [`137c9cf6b36a`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/137c9cf6b36a) - Fix incorrect focus control after closing DropdownMenu.
8
+
3
9
  ## 12.1.8
4
10
 
5
11
  ### Patch Changes
@@ -105,6 +105,8 @@ var DropdownMenu = function DropdownMenu(_ref) {
105
105
  _useState2 = (0, _slicedToArray2.default)(_useState, 2),
106
106
  isTriggeredUsingKeyboard = _useState2[0],
107
107
  setTriggeredUsingKeyboard = _useState2[1];
108
+ var id = (0, _useGeneratedId.default)();
109
+ var itemRef = (0, _useRegisterItemWithFocusManager.default)();
108
110
  var fallbackPlacements = (0, _react.useMemo)(function () {
109
111
  return getFallbackPlacements(placement);
110
112
  }, [placement]);
@@ -129,13 +131,17 @@ var DropdownMenu = function DropdownMenu(_ref) {
129
131
  } else if (detail === 0) {
130
132
  // Fix for Safari. clientX and clientY !== 0 in Safari
131
133
  setTriggeredUsingKeyboard(true);
134
+ } else {
135
+ var _itemRef$current;
136
+ // The trigger element must be focused to avoid problems with an incorrectly focused element after closing DropdownMenu
137
+ itemRef === null || itemRef === void 0 || (_itemRef$current = itemRef.current) === null || _itemRef$current === void 0 || _itemRef$current.focus();
132
138
  }
133
139
  setLocalIsOpen(newValue);
134
140
  onOpenChange({
135
141
  isOpen: newValue,
136
142
  event: event
137
143
  });
138
- }, [onOpenChange, isLocalOpen, setLocalIsOpen]);
144
+ }, [itemRef, onOpenChange, isLocalOpen, setLocalIsOpen]);
139
145
  var handleOnClose = (0, _react.useCallback)(function (event) {
140
146
  if (event.key !== 'Escape' && event.target.closest("[id^=".concat(_useGeneratedId.PREFIX, "] [aria-haspopup]"))) {
141
147
  // Check if it is within dropdown and it is a trigger button
@@ -180,8 +186,6 @@ var DropdownMenu = function DropdownMenu(_ref) {
180
186
  }
181
187
  });
182
188
  }, [isFocused, isLocalOpen, handleTriggerClicked]);
183
- var id = (0, _useGeneratedId.default)();
184
- var itemRef = (0, _useRegisterItemWithFocusManager.default)();
185
189
  return /*#__PURE__*/_react.default.createElement(_selectionStore.default, null, /*#__PURE__*/_react.default.createElement(_popup.default, {
186
190
  id: isLocalOpen ? id : undefined,
187
191
  shouldFlip: shouldFlip,
@@ -75,6 +75,8 @@ const DropdownMenu = ({
75
75
  }) => {
76
76
  const [isLocalOpen, setLocalIsOpen] = useControlledState(isOpen, () => defaultOpen);
77
77
  const [isTriggeredUsingKeyboard, setTriggeredUsingKeyboard] = useState(false);
78
+ const id = useGeneratedId();
79
+ const itemRef = useRegisterItemWithFocusManager();
78
80
  const fallbackPlacements = useMemo(() => getFallbackPlacements(placement), [placement]);
79
81
  const handleTriggerClicked = useCallback(
80
82
  // TODO: event is an `any` and is being cast incorrectly
@@ -99,13 +101,17 @@ const DropdownMenu = ({
99
101
  } else if (detail === 0) {
100
102
  // Fix for Safari. clientX and clientY !== 0 in Safari
101
103
  setTriggeredUsingKeyboard(true);
104
+ } else {
105
+ var _itemRef$current;
106
+ // The trigger element must be focused to avoid problems with an incorrectly focused element after closing DropdownMenu
107
+ itemRef === null || itemRef === void 0 ? void 0 : (_itemRef$current = itemRef.current) === null || _itemRef$current === void 0 ? void 0 : _itemRef$current.focus();
102
108
  }
103
109
  setLocalIsOpen(newValue);
104
110
  onOpenChange({
105
111
  isOpen: newValue,
106
112
  event
107
113
  });
108
- }, [onOpenChange, isLocalOpen, setLocalIsOpen]);
114
+ }, [itemRef, onOpenChange, isLocalOpen, setLocalIsOpen]);
109
115
  const handleOnClose = useCallback(event => {
110
116
  if (event.key !== 'Escape' && event.target.closest(`[id^=${PREFIX}] [aria-haspopup]`)) {
111
117
  // Check if it is within dropdown and it is a trigger button
@@ -151,8 +157,6 @@ const DropdownMenu = ({
151
157
  }
152
158
  });
153
159
  }, [isFocused, isLocalOpen, handleTriggerClicked]);
154
- const id = useGeneratedId();
155
- const itemRef = useRegisterItemWithFocusManager();
156
160
  return /*#__PURE__*/React.createElement(SelectionStore, null, /*#__PURE__*/React.createElement(Popup, {
157
161
  id: isLocalOpen ? id : undefined,
158
162
  shouldFlip: shouldFlip,
@@ -96,6 +96,8 @@ var DropdownMenu = function DropdownMenu(_ref) {
96
96
  _useState2 = _slicedToArray(_useState, 2),
97
97
  isTriggeredUsingKeyboard = _useState2[0],
98
98
  setTriggeredUsingKeyboard = _useState2[1];
99
+ var id = useGeneratedId();
100
+ var itemRef = useRegisterItemWithFocusManager();
99
101
  var fallbackPlacements = useMemo(function () {
100
102
  return getFallbackPlacements(placement);
101
103
  }, [placement]);
@@ -120,13 +122,17 @@ var DropdownMenu = function DropdownMenu(_ref) {
120
122
  } else if (detail === 0) {
121
123
  // Fix for Safari. clientX and clientY !== 0 in Safari
122
124
  setTriggeredUsingKeyboard(true);
125
+ } else {
126
+ var _itemRef$current;
127
+ // The trigger element must be focused to avoid problems with an incorrectly focused element after closing DropdownMenu
128
+ itemRef === null || itemRef === void 0 || (_itemRef$current = itemRef.current) === null || _itemRef$current === void 0 || _itemRef$current.focus();
123
129
  }
124
130
  setLocalIsOpen(newValue);
125
131
  onOpenChange({
126
132
  isOpen: newValue,
127
133
  event: event
128
134
  });
129
- }, [onOpenChange, isLocalOpen, setLocalIsOpen]);
135
+ }, [itemRef, onOpenChange, isLocalOpen, setLocalIsOpen]);
130
136
  var handleOnClose = useCallback(function (event) {
131
137
  if (event.key !== 'Escape' && event.target.closest("[id^=".concat(PREFIX, "] [aria-haspopup]"))) {
132
138
  // Check if it is within dropdown and it is a trigger button
@@ -171,8 +177,6 @@ var DropdownMenu = function DropdownMenu(_ref) {
171
177
  }
172
178
  });
173
179
  }, [isFocused, isLocalOpen, handleTriggerClicked]);
174
- var id = useGeneratedId();
175
- var itemRef = useRegisterItemWithFocusManager();
176
180
  return /*#__PURE__*/React.createElement(SelectionStore, null, /*#__PURE__*/React.createElement(Popup, {
177
181
  id: isLocalOpen ? id : undefined,
178
182
  shouldFlip: shouldFlip,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/dropdown-menu",
3
- "version": "12.1.8",
3
+ "version": "12.1.9",
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/"
@@ -26,7 +26,7 @@
26
26
  }
27
27
  },
28
28
  "dependencies": {
29
- "@atlaskit/button": "^16.17.0",
29
+ "@atlaskit/button": "^16.18.0",
30
30
  "@atlaskit/codemod-utils": "^4.2.0",
31
31
  "@atlaskit/ds-lib": "^2.2.0",
32
32
  "@atlaskit/icon": "^22.0.0",
@@ -34,7 +34,7 @@
34
34
  "@atlaskit/menu": "^2.1.0",
35
35
  "@atlaskit/platform-feature-flags": "^0.2.2",
36
36
  "@atlaskit/popup": "^1.11.0",
37
- "@atlaskit/primitives": "^1.12.0",
37
+ "@atlaskit/primitives": "^1.13.0",
38
38
  "@atlaskit/spinner": "^16.0.0",
39
39
  "@atlaskit/theme": "^12.6.0",
40
40
  "@atlaskit/tokens": "^1.29.0",
@@ -48,6 +48,7 @@
48
48
  },
49
49
  "devDependencies": {
50
50
  "@af/accessibility-testing": "*",
51
+ "@af/integration-testing": "*",
51
52
  "@af/visual-regression": "*",
52
53
  "@atlaskit/visual-regression": "*",
53
54
  "@atlaskit/webdriver-runner": "*",
@@ -1,147 +0,0 @@
1
- ## API Report File for "@atlaskit/dropdown-menu"
2
-
3
- > Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/).
4
-
5
- ```ts
6
-
7
- /// <reference types="react" />
8
-
9
- import type { CustomItemProps } from '@atlaskit/menu/types';
10
- import { default as DropdownItemGroup } from '@atlaskit/menu/section';
11
- import { KeyboardEvent as KeyboardEvent_2 } from 'react';
12
- import type { MenuGroupProps } from '@atlaskit/menu/types';
13
- import { MouseEvent as MouseEvent_2 } from 'react';
14
- import { default as React_2 } from 'react';
15
- import { ReactElement } from 'react';
16
- import { ReactNode } from 'react';
17
- import { Ref } from 'react';
18
- import type { SectionProps } from '@atlaskit/menu';
19
- import type { SectionProps as SectionProps_2 } from '@atlaskit/menu/types';
20
- import type { TriggerProps } from '@atlaskit/popup/types';
21
-
22
- // @public (undocumented)
23
- export interface CustomTriggerProps<TriggerElement extends HTMLElement = HTMLElement> extends Omit<TriggerProps, 'ref'> {
24
- isSelected?: boolean;
25
- onClick?: (e: KeyboardEvent_2 | MouseEvent_2) => void;
26
- testId?: string;
27
- triggerRef: Ref<TriggerElement>;
28
- }
29
-
30
- // @public
31
- export const DropdownItem: React_2.ForwardRefExoticComponent<DropdownItemProps & React_2.RefAttributes<HTMLElement>>;
32
-
33
- // @public
34
- export const DropdownItemCheckbox: ({ children, defaultSelected, description, id, isDisabled, isSelected, onClick: providedOnClick, shouldDescriptionWrap, shouldTitleWrap, testId, ...rest }: DropdownItemCheckboxProps) => JSX.Element;
35
-
36
- // @public
37
- export const DropdownItemCheckboxGroup: ({ children, hasSeparator, id, isList, isScrollable, overrides, testId, title, ...rest }: DropdownItemCheckboxGroupProps) => JSX.Element;
38
-
39
- // @public (undocumented)
40
- interface DropdownItemCheckboxGroupProps extends SectionProps {
41
- id: string;
42
- }
43
-
44
- // @public (undocumented)
45
- interface DropdownItemCheckboxProps {
46
- children: React.ReactNode;
47
- defaultSelected?: boolean;
48
- description?: JSX.Element | string;
49
- id: string;
50
- isDisabled?: boolean;
51
- isSelected?: boolean;
52
- onClick?: (e: KeyboardEvent_2 | MouseEvent_2) => void;
53
- shouldDescriptionWrap?: boolean;
54
- shouldTitleWrap?: boolean;
55
- testId?: string;
56
- title?: string;
57
- }
58
-
59
- export { DropdownItemGroup }
60
-
61
- // @public (undocumented)
62
- export interface DropdownItemProps {
63
- children: React.ReactNode;
64
- component?: CustomItemProps['component'];
65
- description?: JSX.Element | string;
66
- elemAfter?: React.ReactNode;
67
- elemBefore?: React.ReactNode;
68
- href?: string;
69
- isDisabled?: boolean;
70
- isSelected?: boolean;
71
- onClick?: (e: KeyboardEvent_2 | MouseEvent_2) => void;
72
- rel?: string;
73
- shouldDescriptionWrap?: boolean;
74
- shouldTitleWrap?: boolean;
75
- target?: string;
76
- testId?: string;
77
- title?: string;
78
- }
79
-
80
- // @public
81
- export const DropdownItemRadio: ({ children, defaultSelected, testId, id, title, description, isDisabled, isSelected, onClick: providedOnClick, shouldDescriptionWrap, shouldTitleWrap, ...rest }: DropdownItemRadioProps) => JSX.Element;
82
-
83
- // @public
84
- export const DropdownItemRadioGroup: ({ children, hasSeparator, id, isList, isScrollable, overrides, testId, title, ...rest }: DropdownItemRadioGroupProps) => JSX.Element;
85
-
86
- // @public (undocumented)
87
- interface DropdownItemRadioGroupProps extends SectionProps {
88
- // (undocumented)
89
- id: string;
90
- }
91
-
92
- // @public (undocumented)
93
- interface DropdownItemRadioProps {
94
- children: React.ReactNode;
95
- defaultSelected?: boolean;
96
- description?: JSX.Element | string;
97
- id: string;
98
- isDisabled?: boolean;
99
- isSelected?: boolean;
100
- onClick?: (e: KeyboardEvent_2 | MouseEvent_2) => void;
101
- shouldDescriptionWrap?: boolean;
102
- shouldTitleWrap?: boolean;
103
- testId?: string;
104
- title?: string;
105
- }
106
-
107
- // @public
108
- const DropdownMenu: <T extends HTMLElement = HTMLElement>({ autoFocus, children, defaultOpen, isLoading, isOpen, onOpenChange, placement, shouldFlip, shouldRenderToParent, spacing, statusLabel, testId, trigger, zIndex, }: DropdownMenuProps<T>) => JSX.Element;
109
- export default DropdownMenu;
110
-
111
- // @public (undocumented)
112
- export interface DropdownMenuGroupProps extends SectionProps_2 {
113
- }
114
-
115
- // @public (undocumented)
116
- export interface DropdownMenuProps<TriggerElement extends HTMLElement = HTMLElement> {
117
- appearance?: 'default' | 'tall';
118
- autoFocus?: boolean;
119
- children?: ReactNode;
120
- defaultOpen?: boolean;
121
- isLoading?: boolean;
122
- isOpen?: boolean;
123
- onOpenChange?: (args: OnOpenChangeArgs) => void;
124
- placement?: Placement;
125
- shouldFlip?: boolean;
126
- shouldRenderToParent?: boolean;
127
- spacing?: Extract<MenuGroupProps['spacing'], 'compact' | 'cozy'>;
128
- statusLabel?: string;
129
- testId?: string;
130
- trigger?: ((triggerButtonProps: CustomTriggerProps<TriggerElement>) => ReactElement) | string;
131
- zIndex?: number;
132
- }
133
-
134
- // @public (undocumented)
135
- export interface OnOpenChangeArgs {
136
- // (undocumented)
137
- event: KeyboardEvent_2 | MouseEvent_2;
138
- // (undocumented)
139
- isOpen: boolean;
140
- }
141
-
142
- // @public (undocumented)
143
- type Placement = 'auto' | 'auto-end' | 'auto-start' | 'bottom' | 'bottom-end' | 'bottom-start' | 'left' | 'left-end' | 'left-start' | 'right' | 'right-end' | 'right-start' | 'top' | 'top-end' | 'top-start';
144
-
145
- // (No @packageDocumentation comment for this package)
146
-
147
- ```