@ni/fast-foundation 10.2.1 → 10.2.3

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.
@@ -61,6 +61,12 @@ export class Toolbar extends FoundationElement {
61
61
  * @internal
62
62
  */
63
63
  this.direction = Direction.ltr;
64
+ /**
65
+ * The collection of focusable toolbar controls.
66
+ *
67
+ * @internal
68
+ */
69
+ this.focusableElements = [];
64
70
  /**
65
71
  * The orientation of the toolbar.
66
72
  *
@@ -81,7 +87,7 @@ export class Toolbar extends FoundationElement {
81
87
  }
82
88
  set activeIndex(value) {
83
89
  if (this.$fastController.isConnected) {
84
- this._activeIndex = limit(0, this.focusableElements.length - 1, value);
90
+ this._activeIndex = limit(0, this.focusableElements.length > 0 ? this.focusableElements.length - 1 : 0, value);
85
91
  Observable.notify(this, "activeIndex");
86
92
  }
87
93
  }
@@ -96,7 +102,7 @@ export class Toolbar extends FoundationElement {
96
102
  * @internal
97
103
  */
98
104
  mouseDownHandler(e) {
99
- const activeIndex = this.focusableElements?.findIndex(x => x.contains(e.target));
105
+ const activeIndex = this.focusableElements.findIndex(x => x.contains(e.target));
100
106
  if (activeIndex > -1 && this.activeIndex !== activeIndex) {
101
107
  this.setFocusedElement(activeIndex);
102
108
  }
@@ -153,7 +159,7 @@ export class Toolbar extends FoundationElement {
153
159
  return !e.target.closest("[role=radiogroup]");
154
160
  }
155
161
  const nextIndex = this.activeIndex + incrementer;
156
- if (this.focusableElements[nextIndex]) {
162
+ if (this.focusableElements.length > 0 && this.focusableElements[nextIndex]) {
157
163
  e.preventDefault();
158
164
  }
159
165
  this.setFocusedElement(nextIndex);
@@ -176,7 +182,7 @@ export class Toolbar extends FoundationElement {
176
182
  * @internal
177
183
  */
178
184
  reduceFocusableElements() {
179
- const previousFocusedElement = this.focusableElements?.[this.activeIndex];
185
+ const previousFocusedElement = this.focusableElements[this.activeIndex];
180
186
  this.focusableElements = this.allSlottedItems.reduce(Toolbar.reduceFocusableItems, []);
181
187
  // If the previously active item is still focusable, adjust the active index to the
182
188
  // index of that item.
@@ -193,7 +199,8 @@ export class Toolbar extends FoundationElement {
193
199
  setFocusedElement(activeIndex = this.activeIndex) {
194
200
  this.activeIndex = activeIndex;
195
201
  this.setFocusableElements();
196
- if (this.focusableElements[this.activeIndex] &&
202
+ if (this.focusableElements.length > 0 &&
203
+ this.focusableElements[this.activeIndex] &&
197
204
  // Don't focus the toolbar element if some event handlers moved
198
205
  // the focus on another element in the page.
199
206
  this.contains(getRootActiveElement(this))) {
@@ -1327,9 +1327,6 @@ function compileTemplate(template, directives) {
1327
1327
  };
1328
1328
  }
1329
1329
 
1330
- // A singleton Range instance used to efficiently remove ranges of DOM nodes.
1331
- // See the implementation of HTMLView below for further details.
1332
- const range = document.createRange();
1333
1330
  /**
1334
1331
  * The standard View implementation, which also implements ElementView and SyntheticView.
1335
1332
  * @public
@@ -1464,23 +1461,16 @@ class HTMLView {
1464
1461
  this.source = null;
1465
1462
  }
1466
1463
  /**
1467
- * Efficiently disposes of a contiguous range of synthetic view instances.
1464
+ * Disposes of a contiguous range of synthetic view instances.
1468
1465
  * @param views - A contiguous range of views to be disposed.
1469
1466
  */
1470
1467
  static disposeContiguousBatch(views) {
1471
1468
  if (views.length === 0) {
1472
1469
  return;
1473
1470
  }
1474
- range.setStartBefore(views[0].firstChild);
1475
- range.setEndAfter(views[views.length - 1].lastChild);
1476
- range.deleteContents();
1477
1471
  for (let i = 0, ii = views.length; i < ii; ++i) {
1478
1472
  const view = views[i];
1479
- const behaviors = view.behaviors;
1480
- const oldSource = view.source;
1481
- for (let j = 0, jj = behaviors.length; j < jj; ++j) {
1482
- behaviors[j].unbind(oldSource);
1483
- }
1473
+ view.dispose();
1484
1474
  }
1485
1475
  }
1486
1476
  }
@@ -20029,6 +20019,12 @@ class Toolbar extends FoundationElement {
20029
20019
  * @internal
20030
20020
  */
20031
20021
  this.direction = Direction.ltr;
20022
+ /**
20023
+ * The collection of focusable toolbar controls.
20024
+ *
20025
+ * @internal
20026
+ */
20027
+ this.focusableElements = [];
20032
20028
  /**
20033
20029
  * The orientation of the toolbar.
20034
20030
  *
@@ -20049,7 +20045,7 @@ class Toolbar extends FoundationElement {
20049
20045
  }
20050
20046
  set activeIndex(value) {
20051
20047
  if (this.$fastController.isConnected) {
20052
- this._activeIndex = limit(0, this.focusableElements.length - 1, value);
20048
+ this._activeIndex = limit(0, this.focusableElements.length > 0 ? this.focusableElements.length - 1 : 0, value);
20053
20049
  Observable.notify(this, "activeIndex");
20054
20050
  }
20055
20051
  }
@@ -20064,7 +20060,7 @@ class Toolbar extends FoundationElement {
20064
20060
  * @internal
20065
20061
  */
20066
20062
  mouseDownHandler(e) {
20067
- const activeIndex = this.focusableElements?.findIndex(x => x.contains(e.target));
20063
+ const activeIndex = this.focusableElements.findIndex(x => x.contains(e.target));
20068
20064
  if (activeIndex > -1 && this.activeIndex !== activeIndex) {
20069
20065
  this.setFocusedElement(activeIndex);
20070
20066
  }
@@ -20121,7 +20117,7 @@ class Toolbar extends FoundationElement {
20121
20117
  return !e.target.closest("[role=radiogroup]");
20122
20118
  }
20123
20119
  const nextIndex = this.activeIndex + incrementer;
20124
- if (this.focusableElements[nextIndex]) {
20120
+ if (this.focusableElements.length > 0 && this.focusableElements[nextIndex]) {
20125
20121
  e.preventDefault();
20126
20122
  }
20127
20123
  this.setFocusedElement(nextIndex);
@@ -20144,7 +20140,7 @@ class Toolbar extends FoundationElement {
20144
20140
  * @internal
20145
20141
  */
20146
20142
  reduceFocusableElements() {
20147
- const previousFocusedElement = this.focusableElements?.[this.activeIndex];
20143
+ const previousFocusedElement = this.focusableElements[this.activeIndex];
20148
20144
  this.focusableElements = this.allSlottedItems.reduce(Toolbar.reduceFocusableItems, []);
20149
20145
  // If the previously active item is still focusable, adjust the active index to the
20150
20146
  // index of that item.
@@ -20161,7 +20157,8 @@ class Toolbar extends FoundationElement {
20161
20157
  setFocusedElement(activeIndex = this.activeIndex) {
20162
20158
  this.activeIndex = activeIndex;
20163
20159
  this.setFocusableElements();
20164
- if (this.focusableElements[this.activeIndex] &&
20160
+ if (this.focusableElements.length > 0 &&
20161
+ this.focusableElements[this.activeIndex] &&
20165
20162
  // Don't focus the toolbar element if some event handlers moved
20166
20163
  // the focus on another element in the page.
20167
20164
  this.contains(getRootActiveElement(this))) {