@atlaskit/dropdown-menu 16.4.7 → 16.5.0

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,16 @@
1
1
  # @atlaskit/dropdown-menu
2
2
 
3
+ ## 16.5.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [`77b41dc46e2c3`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/77b41dc46e2c3) -
8
+ Add new option `shouldPreventEscapePropagation` to prevent ESCAPE key events from propagating.
9
+
10
+ ### Patch Changes
11
+
12
+ - Updated dependencies
13
+
3
14
  ## 16.4.7
4
15
 
5
16
  ### Patch Changes
@@ -102,7 +102,9 @@ var DropdownMenu = function DropdownMenu(_ref) {
102
102
  label = _ref.label,
103
103
  interactionName = _ref.interactionName,
104
104
  strategy = _ref.strategy,
105
- menuLabel = _ref.menuLabel;
105
+ menuLabel = _ref.menuLabel,
106
+ _ref$shouldPreventEsc = _ref.shouldPreventEscapePropagation,
107
+ shouldPreventEscapePropagation = _ref$shouldPreventEsc === void 0 ? false : _ref$shouldPreventEsc;
106
108
  var _useControlledState = (0, _useControlled.default)(isOpen, function () {
107
109
  return defaultOpen;
108
110
  }),
@@ -157,6 +159,11 @@ var DropdownMenu = function DropdownMenu(_ref) {
157
159
  var handleOnClose = (0, _react.useCallback)(function (event, currentLevel) {
158
160
  var _event$target$closest, _event$target;
159
161
  var isTabOrEscapeKey = isKeyboardEvent(event) && (event.key === 'Tab' || event.key === 'Escape');
162
+
163
+ // Stop propagation on ESCAPE key if shouldPreventEscapePropagation is true
164
+ if (shouldPreventEscapePropagation && isKeyboardEvent(event) && event.key === 'Escape') {
165
+ event.stopPropagation();
166
+ }
160
167
  if (event !== null && !isTabOrEscapeKey && event.target instanceof HTMLElement && (_event$target$closest = (_event$target = event.target).closest) !== null && _event$target$closest !== void 0 && _event$target$closest.call(_event$target, "[id^=".concat(_useGeneratedId.PREFIX, "] [aria-haspopup]"))) {
161
168
  var _itemRef$current2;
162
169
  // Check if it is within dropdown and it is a trigger button
@@ -204,7 +211,7 @@ var DropdownMenu = function DropdownMenu(_ref) {
204
211
  isOpen: newValue,
205
212
  event: event
206
213
  });
207
- }, [itemRef, onOpenChange, returnFocusRef, setLocalIsOpen]);
214
+ }, [itemRef, onOpenChange, returnFocusRef, setLocalIsOpen, shouldPreventEscapePropagation]);
208
215
  var _useFocus = (0, _useFocusEvent.default)(),
209
216
  isFocused = _useFocus.isFocused,
210
217
  bindFocus = _useFocus.bindFocus;
@@ -79,7 +79,8 @@ const DropdownMenu = ({
79
79
  label,
80
80
  interactionName,
81
81
  strategy,
82
- menuLabel
82
+ menuLabel,
83
+ shouldPreventEscapePropagation = false
83
84
  }) => {
84
85
  const [isLocalOpen, setLocalIsOpen] = useControlledState(isOpen, () => defaultOpen);
85
86
  const triggerRef = useRef(null);
@@ -128,6 +129,11 @@ const DropdownMenu = ({
128
129
  const handleOnClose = useCallback((event, currentLevel) => {
129
130
  var _event$target$closest, _event$target;
130
131
  const isTabOrEscapeKey = isKeyboardEvent(event) && (event.key === 'Tab' || event.key === 'Escape');
132
+
133
+ // Stop propagation on ESCAPE key if shouldPreventEscapePropagation is true
134
+ if (shouldPreventEscapePropagation && isKeyboardEvent(event) && event.key === 'Escape') {
135
+ event.stopPropagation();
136
+ }
131
137
  if (event !== null && !isTabOrEscapeKey && event.target instanceof HTMLElement && (_event$target$closest = (_event$target = event.target).closest) !== null && _event$target$closest !== void 0 && _event$target$closest.call(_event$target, `[id^=${PREFIX}] [aria-haspopup]`)) {
132
138
  var _itemRef$current2;
133
139
  // Check if it is within dropdown and it is a trigger button
@@ -175,7 +181,7 @@ const DropdownMenu = ({
175
181
  isOpen: newValue,
176
182
  event
177
183
  });
178
- }, [itemRef, onOpenChange, returnFocusRef, setLocalIsOpen]);
184
+ }, [itemRef, onOpenChange, returnFocusRef, setLocalIsOpen, shouldPreventEscapePropagation]);
179
185
  const {
180
186
  isFocused,
181
187
  bindFocus
@@ -94,7 +94,9 @@ var DropdownMenu = function DropdownMenu(_ref) {
94
94
  label = _ref.label,
95
95
  interactionName = _ref.interactionName,
96
96
  strategy = _ref.strategy,
97
- menuLabel = _ref.menuLabel;
97
+ menuLabel = _ref.menuLabel,
98
+ _ref$shouldPreventEsc = _ref.shouldPreventEscapePropagation,
99
+ shouldPreventEscapePropagation = _ref$shouldPreventEsc === void 0 ? false : _ref$shouldPreventEsc;
98
100
  var _useControlledState = useControlledState(isOpen, function () {
99
101
  return defaultOpen;
100
102
  }),
@@ -149,6 +151,11 @@ var DropdownMenu = function DropdownMenu(_ref) {
149
151
  var handleOnClose = useCallback(function (event, currentLevel) {
150
152
  var _event$target$closest, _event$target;
151
153
  var isTabOrEscapeKey = isKeyboardEvent(event) && (event.key === 'Tab' || event.key === 'Escape');
154
+
155
+ // Stop propagation on ESCAPE key if shouldPreventEscapePropagation is true
156
+ if (shouldPreventEscapePropagation && isKeyboardEvent(event) && event.key === 'Escape') {
157
+ event.stopPropagation();
158
+ }
152
159
  if (event !== null && !isTabOrEscapeKey && event.target instanceof HTMLElement && (_event$target$closest = (_event$target = event.target).closest) !== null && _event$target$closest !== void 0 && _event$target$closest.call(_event$target, "[id^=".concat(PREFIX, "] [aria-haspopup]"))) {
153
160
  var _itemRef$current2;
154
161
  // Check if it is within dropdown and it is a trigger button
@@ -196,7 +203,7 @@ var DropdownMenu = function DropdownMenu(_ref) {
196
203
  isOpen: newValue,
197
204
  event: event
198
205
  });
199
- }, [itemRef, onOpenChange, returnFocusRef, setLocalIsOpen]);
206
+ }, [itemRef, onOpenChange, returnFocusRef, setLocalIsOpen, shouldPreventEscapePropagation]);
200
207
  var _useFocus = useFocus(),
201
208
  isFocused = _useFocus.isFocused,
202
209
  bindFocus = _useFocus.bindFocus;
@@ -9,5 +9,5 @@ import type { DropdownMenuProps } from './types';
9
9
  * - [Code](https://atlassian.design/components/dropdown-menu/code)
10
10
  * - [Usage](https://atlassian.design/components/dropdown-menu/usage)
11
11
  */
12
- declare const DropdownMenu: <T extends HTMLElement = any>({ autoFocus, children, defaultOpen, isLoading, isOpen, onOpenChange, placement, shouldFitContainer, shouldFlip, shouldRenderToParent, returnFocusRef, spacing, statusLabel, testId, trigger, zIndex, label, interactionName, strategy, menuLabel, }: DropdownMenuProps<T>) => React.JSX.Element;
12
+ declare const DropdownMenu: <T extends HTMLElement = any>({ autoFocus, children, defaultOpen, isLoading, isOpen, onOpenChange, placement, shouldFitContainer, shouldFlip, shouldRenderToParent, returnFocusRef, spacing, statusLabel, testId, trigger, zIndex, label, interactionName, strategy, menuLabel, shouldPreventEscapePropagation, }: DropdownMenuProps<T>) => React.JSX.Element;
13
13
  export default DropdownMenu;
@@ -185,6 +185,11 @@ interface InternalDropdownMenuProps<TriggerElement extends HTMLElement = any> {
185
185
  * Provide an accessible label for the menu element for assistive technology.
186
186
  */
187
187
  menuLabel?: string;
188
+ /**
189
+ * When set to true, will call stopPropagation on the ESCAPE key event.
190
+ * This prevents the ESCAPE event from bubbling up to parent elements.
191
+ */
192
+ shouldPreventEscapePropagation?: boolean;
188
193
  }
189
194
  type StandardDropdownMenuProps<TriggerElement extends HTMLElement = any> = InternalDropdownMenuProps<TriggerElement> & {
190
195
  shouldFitContainer?: false;
@@ -9,5 +9,5 @@ import type { DropdownMenuProps } from './types';
9
9
  * - [Code](https://atlassian.design/components/dropdown-menu/code)
10
10
  * - [Usage](https://atlassian.design/components/dropdown-menu/usage)
11
11
  */
12
- declare const DropdownMenu: <T extends HTMLElement = any>({ autoFocus, children, defaultOpen, isLoading, isOpen, onOpenChange, placement, shouldFitContainer, shouldFlip, shouldRenderToParent, returnFocusRef, spacing, statusLabel, testId, trigger, zIndex, label, interactionName, strategy, menuLabel, }: DropdownMenuProps<T>) => React.JSX.Element;
12
+ declare const DropdownMenu: <T extends HTMLElement = any>({ autoFocus, children, defaultOpen, isLoading, isOpen, onOpenChange, placement, shouldFitContainer, shouldFlip, shouldRenderToParent, returnFocusRef, spacing, statusLabel, testId, trigger, zIndex, label, interactionName, strategy, menuLabel, shouldPreventEscapePropagation, }: DropdownMenuProps<T>) => React.JSX.Element;
13
13
  export default DropdownMenu;
@@ -185,6 +185,11 @@ interface InternalDropdownMenuProps<TriggerElement extends HTMLElement = any> {
185
185
  * Provide an accessible label for the menu element for assistive technology.
186
186
  */
187
187
  menuLabel?: string;
188
+ /**
189
+ * When set to true, will call stopPropagation on the ESCAPE key event.
190
+ * This prevents the ESCAPE event from bubbling up to parent elements.
191
+ */
192
+ shouldPreventEscapePropagation?: boolean;
188
193
  }
189
194
  type StandardDropdownMenuProps<TriggerElement extends HTMLElement = any> = InternalDropdownMenuProps<TriggerElement> & {
190
195
  shouldFitContainer?: false;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/dropdown-menu",
3
- "version": "16.4.7",
3
+ "version": "16.5.0",
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/"