@primer/view-components 0.0.117 → 0.0.118-rc.67f0ec13

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.
@@ -21,9 +21,11 @@ const overlayStack = [];
21
21
  function clickHandler(event) {
22
22
  const target = event.target;
23
23
  const button = target === null || target === void 0 ? void 0 : target.closest('button');
24
+ if (!button)
25
+ return;
24
26
  // If the user is clicking a valid dialog trigger
25
27
  let dialogId = button === null || button === void 0 ? void 0 : button.getAttribute('data-show-dialog-id');
26
- if (button && dialogId) {
28
+ if (dialogId) {
27
29
  event.stopPropagation();
28
30
  const dialog = document.getElementById(dialogId);
29
31
  if (dialog instanceof ModalDialogElement) {
@@ -36,17 +38,6 @@ function clickHandler(event) {
36
38
  const topLevelDialog = overlayStack[overlayStack.length - 1];
37
39
  if (!topLevelDialog)
38
40
  return;
39
- // Check if the click happened outside the boundary of the top level dialog
40
- const clickOutsideDialog = !target.closest(`#${topLevelDialog.getAttribute('id')}`);
41
- // Only close dialog if it's a click outside the dialog and the dialog has a
42
- // button?
43
- if (!button) {
44
- if (clickOutsideDialog) {
45
- overlayStack.pop();
46
- topLevelDialog.close();
47
- }
48
- return;
49
- }
50
41
  dialogId = button.getAttribute('data-close-dialog-id');
51
42
  if (dialogId === topLevelDialog.id) {
52
43
  overlayStack.pop();
@@ -58,6 +49,26 @@ function clickHandler(event) {
58
49
  topLevelDialog.close(true);
59
50
  }
60
51
  }
52
+ function mousedownHandler(event) {
53
+ const target = event.target;
54
+ if (target === null || target === void 0 ? void 0 : target.closest('button'))
55
+ return;
56
+ // Find the top level dialog that is open.
57
+ const topLevelDialog = overlayStack[overlayStack.length - 1];
58
+ if (!topLevelDialog)
59
+ return;
60
+ // Check if the mousedown happened outside the boundary of the top level dialog
61
+ const mouseDownOutsideDialog = !target.closest(`#${topLevelDialog.getAttribute('id')}`);
62
+ // Only close dialog if it's a click outside the dialog and the dialog has a button?
63
+ if (mouseDownOutsideDialog) {
64
+ target.ownerDocument.addEventListener('mouseup', (upEvent) => {
65
+ if (upEvent.target === target) {
66
+ overlayStack.pop();
67
+ topLevelDialog.close();
68
+ }
69
+ }, { once: true });
70
+ }
71
+ }
61
72
  export class ModalDialogElement extends HTMLElement {
62
73
  constructor() {
63
74
  super(...arguments);
@@ -109,6 +120,7 @@ export class ModalDialogElement extends HTMLElement {
109
120
  if (!this.hasAttribute('role'))
110
121
  this.setAttribute('role', 'dialog');
111
122
  document.addEventListener('click', clickHandler);
123
+ document.addEventListener('mousedown', mousedownHandler);
112
124
  this.addEventListener('keydown', e => __classPrivateFieldGet(this, _ModalDialogElement_instances, "m", _ModalDialogElement_keydown).call(this, e));
113
125
  }
114
126
  show() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@primer/view-components",
3
- "version": "0.0.117",
3
+ "version": "0.0.118-rc.67f0ec13",
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",