@brightspace-ui/core 3.12.0 → 3.13.0

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.
@@ -1,3 +1,4 @@
1
+ import { clearDismissible, setDismissible } from '../../helpers/dismissible.js';
1
2
  import { css, html } from 'lit';
2
3
  import { findComposedAncestor, isComposedAncestor } from '../../helpers/dom.js';
3
4
  import { classMap } from 'lit/directives/class-map.js';
@@ -7,11 +8,6 @@ import { LocalizeCoreElement } from '../../helpers/localize-core-element.js';
7
8
  import { offscreenStyles } from '../../components/offscreen/offscreen.js';
8
9
  import { RtlMixin } from '../rtl/rtl-mixin.js';
9
10
 
10
- const keyCodes = {
11
- ENTER: 13,
12
- ESCAPE: 27
13
- };
14
-
15
11
  export function isInteractiveDescendant(node) {
16
12
  if (!node) return false;
17
13
  return !!findComposedAncestor(node, node => {
@@ -41,6 +37,7 @@ export const InteractiveMixin = superclass => class extends LocalizeCoreElement(
41
37
 
42
38
  constructor() {
43
39
  super();
40
+ this._dismissibleId = null;
44
41
  this._focusingToggle = false;
45
42
  this._hasInteractiveAncestor = false;
46
43
  this._interactive = false;
@@ -55,6 +52,14 @@ export const InteractiveMixin = superclass => class extends LocalizeCoreElement(
55
52
  this._hasInteractiveAncestor = (parentGrid !== null);
56
53
  }
57
54
 
55
+ disconnectedCallback() {
56
+ super.disconnectedCallback();
57
+
58
+ if (!this._dismissibleId) return;
59
+ clearDismissible(this._dismissibleId);
60
+ this._dismissibleId = null;
61
+ }
62
+
58
63
  focus() {
59
64
  if (!this.shadowRoot) return;
60
65
  if (this._hasInteractiveAncestor && !this._interactive) this.shadowRoot.querySelector('.interactive-toggle').focus();
@@ -97,20 +102,29 @@ export const InteractiveMixin = superclass => class extends LocalizeCoreElement(
97
102
 
98
103
  _handleInteractiveContentFocusIn() {
99
104
  this._interactive = true;
105
+ this._dismissibleId = setDismissible(async() => {
106
+ await this._handleInteractiveExit();
107
+ });
100
108
  }
101
109
 
102
110
  _handleInteractiveContentFocusOut(e) {
103
111
  if (isComposedAncestor(this.shadowRoot.querySelector('.interactive-container-content'), e.relatedTarget)) return;
104
112
  // focus moved out of the interactive content
105
113
  this._interactive = false;
114
+ if (this._dismissibleId) {
115
+ clearDismissible(this._dismissibleId);
116
+ this._dismissibleId = null;
117
+ }
118
+ }
119
+
120
+ async _handleInteractiveExit() {
121
+ this._interactive = false;
122
+ await this.updateComplete;
123
+ this.shadowRoot.querySelector('.interactive-toggle').focus();
106
124
  }
107
125
 
108
126
  async _handleInteractiveKeyDown(e) {
109
- if (this._interactive && e.keyCode === keyCodes.ESCAPE) {
110
- this._interactive = false;
111
- await this.updateComplete;
112
- this.shadowRoot.querySelector('.interactive-toggle').focus();
113
- }
127
+ if (this._interactive && e.keyCode === 9) e.stopPropagation(); // tab
114
128
  }
115
129
 
116
130
  _handleInteractiveToggleBlur() {
@@ -129,9 +143,7 @@ export const InteractiveMixin = superclass => class extends LocalizeCoreElement(
129
143
 
130
144
  async _handleInteractiveTrapEndFocus() {
131
145
  // focus moved to trap-end either forwards from contents or backwards from outside - focus interactive toggle
132
- this._interactive = false;
133
- await this.updateComplete;
134
- this.shadowRoot.querySelector('.interactive-toggle').focus();
146
+ await this._handleInteractiveExit();
135
147
  }
136
148
 
137
149
  async _handleInteractiveTrapStartFocus(e) {
@@ -141,9 +153,7 @@ export const InteractiveMixin = superclass => class extends LocalizeCoreElement(
141
153
  if (nextFocusable) nextFocusable.focus();
142
154
  } else {
143
155
  // focus moved to trap-start backwards from within contents - toggle to non-interactive and apply focus
144
- this._interactive = false;
145
- await this.updateComplete;
146
- this.shadowRoot.querySelector('.interactive-toggle').focus();
156
+ await this._handleInteractiveExit();
147
157
  }
148
158
  }
149
159
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@brightspace-ui/core",
3
- "version": "3.12.0",
3
+ "version": "3.13.0",
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",