@primer/behaviors 0.0.0-2022031122217 → 0.0.0-2022031145415

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.
@@ -6,7 +6,10 @@ class ModalDialogElement extends HTMLElement {
6
6
  var _a, _b;
7
7
  super();
8
8
  (_a = this.querySelector('.close-button')) === null || _a === void 0 ? void 0 : _a.addEventListener('click', () => this.close());
9
- (_b = document.body.querySelector(`.js-dialog-show-${this.id}`)) === null || _b === void 0 ? void 0 : _b.addEventListener('click', () => this.show());
9
+ (_b = document.body.querySelector(`.js-dialog-show-${this.id}`)) === null || _b === void 0 ? void 0 : _b.addEventListener('click', (event) => {
10
+ event.stopPropagation();
11
+ this.show();
12
+ });
10
13
  }
11
14
  connectedCallback() {
12
15
  if (!this.hasAttribute('role'))
@@ -14,7 +17,8 @@ class ModalDialogElement extends HTMLElement {
14
17
  const subscriptions = [
15
18
  fromEvent(this, 'compositionstart', e => trackComposition(this, e)),
16
19
  fromEvent(this, 'compositionend', e => trackComposition(this, e)),
17
- fromEvent(this, 'keydown', e => keydown(this, e))
20
+ fromEvent(this, 'keydown', e => keydown(this, e)),
21
+ fromEvent(window, 'click', e => clickToDismiss(this, e))
18
22
  ];
19
23
  states.set(this, { subscriptions, loaded: false, isComposing: false });
20
24
  }
@@ -85,6 +89,12 @@ function trackComposition(dialog, event) {
85
89
  return;
86
90
  state.isComposing = event.type === 'compositionstart';
87
91
  }
92
+ function clickToDismiss(dialog, event) {
93
+ const target = event.target;
94
+ if (dialog.hasAttribute('open') && target && !target.matches(`#${dialog.id}, #${dialog.id} *`)) {
95
+ dialog.close();
96
+ }
97
+ }
88
98
  exports.default = ModalDialogElement;
89
99
  if (!window.customElements.get('modal-dialog')) {
90
100
  window.ModalDialogElement = ModalDialogElement;
@@ -4,7 +4,10 @@ class ModalDialogElement extends HTMLElement {
4
4
  var _a, _b;
5
5
  super();
6
6
  (_a = this.querySelector('.close-button')) === null || _a === void 0 ? void 0 : _a.addEventListener('click', () => this.close());
7
- (_b = document.body.querySelector(`.js-dialog-show-${this.id}`)) === null || _b === void 0 ? void 0 : _b.addEventListener('click', () => this.show());
7
+ (_b = document.body.querySelector(`.js-dialog-show-${this.id}`)) === null || _b === void 0 ? void 0 : _b.addEventListener('click', (event) => {
8
+ event.stopPropagation();
9
+ this.show();
10
+ });
8
11
  }
9
12
  connectedCallback() {
10
13
  if (!this.hasAttribute('role'))
@@ -12,7 +15,8 @@ class ModalDialogElement extends HTMLElement {
12
15
  const subscriptions = [
13
16
  fromEvent(this, 'compositionstart', e => trackComposition(this, e)),
14
17
  fromEvent(this, 'compositionend', e => trackComposition(this, e)),
15
- fromEvent(this, 'keydown', e => keydown(this, e))
18
+ fromEvent(this, 'keydown', e => keydown(this, e)),
19
+ fromEvent(window, 'click', e => clickToDismiss(this, e))
16
20
  ];
17
21
  states.set(this, { subscriptions, loaded: false, isComposing: false });
18
22
  }
@@ -83,6 +87,12 @@ function trackComposition(dialog, event) {
83
87
  return;
84
88
  state.isComposing = event.type === 'compositionstart';
85
89
  }
90
+ function clickToDismiss(dialog, event) {
91
+ const target = event.target;
92
+ if (dialog.hasAttribute('open') && target && !target.matches(`#${dialog.id}, #${dialog.id} *`)) {
93
+ dialog.close();
94
+ }
95
+ }
86
96
  export default ModalDialogElement;
87
97
  if (!window.customElements.get('modal-dialog')) {
88
98
  window.ModalDialogElement = ModalDialogElement;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@primer/behaviors",
3
- "version": "0.0.0-2022031122217",
3
+ "version": "0.0.0-2022031145415",
4
4
  "description": "Shared behaviors for JavaScript components",
5
5
  "main": "dist/cjs/index.js",
6
6
  "module": "dist/esm/index.js",