@fluid-topics/ft-modal 2.0.14 → 2.0.16

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.
@@ -19,8 +19,10 @@ export declare class FtModal extends FtModal_base implements FtModalProperties {
19
19
  private intersectionObserver;
20
20
  open(elementToFocusOnClose?: HTMLElement): void;
21
21
  close(): void;
22
+ connectedCallback(): void;
22
23
  disconnectedCallback(): void;
23
24
  private onClose;
24
25
  private onOverlayClick;
26
+ private onEscapePressed;
25
27
  }
26
28
  export {};
package/build/ft-modal.js CHANGED
@@ -4,20 +4,20 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
4
4
  else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
5
  return c > 3 && r && Object.defineProperty(target, key, r), r;
6
6
  };
7
- import { html, nothing } from "lit";
8
- import { property, query } from "lit/decorators.js";
9
- import { FtdsBase } from "@fluid-topics/ft-wc-utils";
7
+ import { html, nothing, } from "lit";
8
+ import { property, query, } from "lit/decorators.js";
9
+ import { focusTrap, FtdsBase, } from "@fluid-topics/ft-wc-utils";
10
10
  import { classMap } from "lit/directives/class-map.js";
11
11
  import { DesignSystemSize } from "@fluid-topics/design-system-variables";
12
- import { FtIcon, FtIcons } from "@fluid-topics/ft-icon";
13
- import { FtTypography, FtTypographyVariants } from "@fluid-topics/ft-typography";
12
+ import { FtIcon, FtIcons, } from "@fluid-topics/ft-icon";
13
+ import { FtTypography, FtTypographyVariants, } from "@fluid-topics/ft-typography";
14
14
  import { withI18n } from "@fluid-topics/ft-i18n";
15
15
  import { modal } from "./FtDsModalMessages";
16
16
  import { FtButton } from "@fluid-topics/ft-button";
17
17
  import { ftmodalStyles } from "./ft-modal.styles";
18
18
  import { when } from "lit/directives/when.js";
19
19
  import { ifDefined } from "lit/directives/if-defined.js";
20
- import { defaultFtModalMessages, ftModalContext } from "./FtModalMessages";
20
+ import { defaultFtModalMessages, ftModalContext, } from "./FtModalMessages";
21
21
  class FtModalCloseEvent extends Event {
22
22
  constructor() {
23
23
  super("close");
@@ -28,7 +28,7 @@ class FtModalOpenEvent extends Event {
28
28
  super("open");
29
29
  }
30
30
  }
31
- class FtModal extends withI18n(FtdsBase) {
31
+ export class FtModal extends withI18n(FtdsBase) {
32
32
  constructor() {
33
33
  super();
34
34
  this.buttonLabel = "";
@@ -52,7 +52,7 @@ class FtModal extends withI18n(FtdsBase) {
52
52
  ${when(this.buttonIcon, () => nothing, () => this.buttonLabel)}
53
53
  </ft-button>
54
54
  </slot>
55
- <dialog part="dialog" aria-labelledby="heading" @close=${this.onClose}>
55
+ <dialog part="dialog" popover="manual" aria-labelledby="heading" @close=${this.onClose} ${focusTrap()}>
56
56
  <div part="overlay" @click=${this.onOverlayClick}></div>
57
57
  <div part="inner-container">
58
58
  <div part="header">
@@ -93,19 +93,24 @@ class FtModal extends withI18n(FtdsBase) {
93
93
  open(elementToFocusOnClose) {
94
94
  this.elementToFocusOnClose = elementToFocusOnClose;
95
95
  if (this.dialog) {
96
- this.dialog.showModal();
96
+ this.dialog.showPopover();
97
97
  this.intersectionObserver.observe(this.dialog);
98
98
  this.dispatchEvent(new FtModalOpenEvent());
99
99
  }
100
100
  }
101
101
  close() {
102
102
  var _a;
103
- (_a = this.dialog) === null || _a === void 0 ? void 0 : _a.close();
103
+ (_a = this.dialog) === null || _a === void 0 ? void 0 : _a.hidePopover();
104
104
  this.onClose();
105
105
  }
106
+ connectedCallback() {
107
+ super.connectedCallback();
108
+ this.addEventListener("keydown", this.onEscapePressed);
109
+ }
106
110
  disconnectedCallback() {
107
111
  super.disconnectedCallback();
108
112
  this.close();
113
+ this.removeEventListener("keydown", this.onEscapePressed);
109
114
  }
110
115
  onClose() {
111
116
  var _a;
@@ -116,6 +121,11 @@ class FtModal extends withI18n(FtdsBase) {
116
121
  onOverlayClick() {
117
122
  this.close();
118
123
  }
124
+ onEscapePressed(e) {
125
+ if (e.key === "Escape") {
126
+ this.close();
127
+ }
128
+ }
119
129
  }
120
130
  FtModal.elementDefinitions = {
121
131
  "ft-button": FtButton,
@@ -138,4 +148,3 @@ __decorate([
138
148
  __decorate([
139
149
  query("dialog")
140
150
  ], FtModal.prototype, "dialog", void 0);
141
- export { FtModal };