@primer/view-components 0.32.0-rc.ae50af33 → 0.32.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -147,7 +147,7 @@ let ActionMenuElement = class ActionMenuElement extends HTMLElement {
147
147
  const dialogInvoker = item.closest('[data-show-dialog-id]');
148
148
  if (dialogInvoker) {
149
149
  const dialog = this.ownerDocument.getElementById(dialogInvoker.getAttribute('data-show-dialog-id') || '');
150
- if (dialog && this.contains(dialogInvoker) && this.contains(dialog)) {
150
+ if (dialog && this.contains(dialogInvoker)) {
151
151
  __classPrivateFieldGet(this, _ActionMenuElement_instances, "m", _ActionMenuElement_handleDialogItemActivated).call(this, event, dialog);
152
152
  return;
153
153
  }
@@ -289,20 +289,33 @@ _ActionMenuElement_handleInvokerActivated = function _ActionMenuElement_handleIn
289
289
  }
290
290
  };
291
291
  _ActionMenuElement_handleDialogItemActivated = function _ActionMenuElement_handleDialogItemActivated(event, dialog) {
292
- this.querySelector('.ActionListWrap').style.display = 'none';
292
+ if (this.contains(dialog)) {
293
+ this.querySelector('.ActionListWrap').style.display = 'none';
294
+ }
293
295
  const dialog_controller = new AbortController();
294
296
  const { signal } = dialog_controller;
295
297
  const handleDialogClose = () => {
296
298
  dialog_controller.abort();
297
- this.querySelector('.ActionListWrap').style.display = '';
298
- if (__classPrivateFieldGet(this, _ActionMenuElement_instances, "m", _ActionMenuElement_isOpen).call(this)) {
299
- __classPrivateFieldGet(this, _ActionMenuElement_instances, "m", _ActionMenuElement_hide).call(this);
299
+ if (this.contains(dialog)) {
300
+ this.querySelector('.ActionListWrap').style.display = '';
301
+ if (__classPrivateFieldGet(this, _ActionMenuElement_instances, "m", _ActionMenuElement_isOpen).call(this)) {
302
+ __classPrivateFieldGet(this, _ActionMenuElement_instances, "m", _ActionMenuElement_hide).call(this);
303
+ }
300
304
  }
301
305
  const activeElement = this.ownerDocument.activeElement;
302
306
  const lostFocus = this.ownerDocument.activeElement === this.ownerDocument.body;
303
307
  const focusInClosedMenu = this.contains(activeElement);
304
- if (lostFocus || focusInClosedMenu) {
305
- setTimeout(() => this.invokerElement?.focus(), 0);
308
+ const focusInDialog = dialog.contains(activeElement);
309
+ if (lostFocus || focusInClosedMenu || focusInDialog) {
310
+ setTimeout(() => {
311
+ // if the activeElement has changed after a task, then it's likely
312
+ // that other JS has tried to shift focus. We should respect that
313
+ // focus shift as long as it's not back at the document.
314
+ const newActiveElement = this.ownerDocument.activeElement;
315
+ if (newActiveElement === activeElement || newActiveElement === this.ownerDocument.body) {
316
+ this.invokerElement?.focus();
317
+ }
318
+ }, 0);
306
319
  }
307
320
  };
308
321
  // a modal <dialog> element will close all popovers
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@primer/view-components",
3
- "version": "0.32.0-rc.ae50af33",
3
+ "version": "0.32.0",
4
4
  "description": "ViewComponents for the Primer Design System",
5
5
  "main": "app/assets/javascripts/primer_view_components.js",
6
6
  "module": "app/components/primer/primer.js",