@brightspace-ui/core 2.23.0 → 2.23.1

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.
@@ -16,7 +16,8 @@ class FocusTrap extends FocusMixin(LitElement) {
16
16
  * Whether the component should trap user focus.
17
17
  * @type {boolean}
18
18
  */
19
- trap: { type: Boolean }
19
+ trap: { type: Boolean },
20
+ _legacyPromptIds: { state: true }
20
21
  };
21
22
  }
22
23
 
@@ -35,6 +36,9 @@ class FocusTrap extends FocusMixin(LitElement) {
35
36
  super();
36
37
  this.trap = false;
37
38
  this._handleBodyFocus = this._handleBodyFocus.bind(this);
39
+ this._handleLegacyPromptOpen = this._handleLegacyPromptOpen.bind(this);
40
+ this._handleLegacyPromptClose = this._handleLegacyPromptClose.bind(this);
41
+ this._legacyPromptIds = new Set();
38
42
  }
39
43
 
40
44
  static get focusElementSelector() {
@@ -44,15 +48,19 @@ class FocusTrap extends FocusMixin(LitElement) {
44
48
  connectedCallback() {
45
49
  super.connectedCallback();
46
50
  document.body.addEventListener('focus', this._handleBodyFocus, true);
51
+ document.body.addEventListener('d2l-legacy-prompt-open', this._handleLegacyPromptOpen);
52
+ document.body.addEventListener('d2l-legacy-prompt-close', this._handleLegacyPromptClose);
47
53
  }
48
54
 
49
55
  disconnectedCallback() {
50
56
  super.disconnectedCallback();
51
57
  document.body.removeEventListener('focus', this._handleBodyFocus, true);
58
+ document.body.removeEventListener('d2l-legacy-prompt-open', this._handleLegacyPromptOpen);
59
+ document.body.removeEventListener('d2l-legacy-prompt-close', this._handleLegacyPromptClose);
52
60
  }
53
61
 
54
62
  render() {
55
- const tabindex = this.trap ? '0' : undefined;
63
+ const tabindex = (this.trap && this._legacyPromptIds.size === 0) ? '0' : undefined;
56
64
  return html`
57
65
  <span class="d2l-focus-trap-start" @focusin="${this._handleStartFocusIn}" tabindex="${ifDefined(tabindex)}"></span>
58
66
  <slot></slot>
@@ -72,7 +80,7 @@ class FocusTrap extends FocusMixin(LitElement) {
72
80
  }
73
81
 
74
82
  _handleBodyFocus(e) {
75
- if (!this.trap) return;
83
+ if (!this.trap || this._legacyPromptIds.size > 0) return;
76
84
  const container = this._getContainer();
77
85
  const target = e.composedPath()[0];
78
86
  if (isComposedAncestor(container, target)) return;
@@ -95,6 +103,16 @@ class FocusTrap extends FocusMixin(LitElement) {
95
103
  this._focusFirst();
96
104
  }
97
105
 
106
+ _handleLegacyPromptClose(e) {
107
+ this._legacyPromptIds.delete(e.detail.id);
108
+ this.requestUpdate();
109
+ }
110
+
111
+ _handleLegacyPromptOpen(e) {
112
+ this._legacyPromptIds.add(e.detail.id);
113
+ this.requestUpdate();
114
+ }
115
+
98
116
  _handleStartFocusIn(e) {
99
117
  const container = this._getContainer();
100
118
  if (this.shadowRoot && isComposedAncestor(container, e.relatedTarget)) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@brightspace-ui/core",
3
- "version": "2.23.0",
3
+ "version": "2.23.1",
4
4
  "description": "A collection of accessible, free, open-source web components for building Brightspace applications",
5
5
  "type": "module",
6
6
  "repository": "https://github.com/BrightspaceUI/core.git",