@ni/fast-foundation 10.2.1 → 10.2.2

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))) {
@@ -20029,6 +20029,12 @@ class Toolbar extends FoundationElement {
20029
20029
  * @internal
20030
20030
  */
20031
20031
  this.direction = Direction.ltr;
20032
+ /**
20033
+ * The collection of focusable toolbar controls.
20034
+ *
20035
+ * @internal
20036
+ */
20037
+ this.focusableElements = [];
20032
20038
  /**
20033
20039
  * The orientation of the toolbar.
20034
20040
  *
@@ -20049,7 +20055,7 @@ class Toolbar extends FoundationElement {
20049
20055
  }
20050
20056
  set activeIndex(value) {
20051
20057
  if (this.$fastController.isConnected) {
20052
- this._activeIndex = limit(0, this.focusableElements.length - 1, value);
20058
+ this._activeIndex = limit(0, this.focusableElements.length > 0 ? this.focusableElements.length - 1 : 0, value);
20053
20059
  Observable.notify(this, "activeIndex");
20054
20060
  }
20055
20061
  }
@@ -20064,7 +20070,7 @@ class Toolbar extends FoundationElement {
20064
20070
  * @internal
20065
20071
  */
20066
20072
  mouseDownHandler(e) {
20067
- const activeIndex = this.focusableElements?.findIndex(x => x.contains(e.target));
20073
+ const activeIndex = this.focusableElements.findIndex(x => x.contains(e.target));
20068
20074
  if (activeIndex > -1 && this.activeIndex !== activeIndex) {
20069
20075
  this.setFocusedElement(activeIndex);
20070
20076
  }
@@ -20121,7 +20127,7 @@ class Toolbar extends FoundationElement {
20121
20127
  return !e.target.closest("[role=radiogroup]");
20122
20128
  }
20123
20129
  const nextIndex = this.activeIndex + incrementer;
20124
- if (this.focusableElements[nextIndex]) {
20130
+ if (this.focusableElements.length > 0 && this.focusableElements[nextIndex]) {
20125
20131
  e.preventDefault();
20126
20132
  }
20127
20133
  this.setFocusedElement(nextIndex);
@@ -20144,7 +20150,7 @@ class Toolbar extends FoundationElement {
20144
20150
  * @internal
20145
20151
  */
20146
20152
  reduceFocusableElements() {
20147
- const previousFocusedElement = this.focusableElements?.[this.activeIndex];
20153
+ const previousFocusedElement = this.focusableElements[this.activeIndex];
20148
20154
  this.focusableElements = this.allSlottedItems.reduce(Toolbar.reduceFocusableItems, []);
20149
20155
  // If the previously active item is still focusable, adjust the active index to the
20150
20156
  // index of that item.
@@ -20161,7 +20167,8 @@ class Toolbar extends FoundationElement {
20161
20167
  setFocusedElement(activeIndex = this.activeIndex) {
20162
20168
  this.activeIndex = activeIndex;
20163
20169
  this.setFocusableElements();
20164
- if (this.focusableElements[this.activeIndex] &&
20170
+ if (this.focusableElements.length > 0 &&
20171
+ this.focusableElements[this.activeIndex] &&
20165
20172
  // Don't focus the toolbar element if some event handlers moved
20166
20173
  // the focus on another element in the page.
20167
20174
  this.contains(getRootActiveElement(this))) {
@@ -1390,7 +1390,7 @@ const t=function(){if("undefined"!=typeof globalThis)return globalThis;if("undef
1390
1390
  ${Jt(0,e)}
1391
1391
  </div>
1392
1392
  </template>
1393
- `;const Pr=Object.freeze({[Oi.ArrowUp]:{[li]:-1},[Oi.ArrowDown]:{[li]:1},[Oi.ArrowLeft]:{[ai]:{[Si.ltr]:-1,[Si.rtl]:1}},[Oi.ArrowRight]:{[ai]:{[Si.ltr]:1,[Si.rtl]:-1}}});class Mr extends ei{constructor(){super(...arguments),this._activeIndex=0,this.direction=Si.ltr,this.orientation=ai}get activeIndex(){return m.track(this,"activeIndex"),this._activeIndex}set activeIndex(t){this.$fastController.isConnected&&(this._activeIndex=Ri(0,this.focusableElements.length-1,t),m.notify(this,"activeIndex"))}slottedItemsChanged(){this.$fastController.isConnected&&this.reduceFocusableElements()}mouseDownHandler(t){const e=this.focusableElements?.findIndex((e=>e.contains(t.target)));return e>-1&&this.activeIndex!==e&&this.setFocusedElement(e),!0}childItemsChanged(t,e){this.$fastController.isConnected&&this.reduceFocusableElements()}connectedCallback(){super.connectedCallback(),this.direction=Bi(this)}focusinHandler(t){const e=t.relatedTarget;e&&!this.contains(e)&&this.setFocusedElement()}getDirectionalIncrementer(t){return Pr[t]?.[this.orientation]?.[this.direction]??Pr[t]?.[this.orientation]??0}keydownHandler(t){const e=t.key;if(!(e in Oi)||t.defaultPrevented||t.shiftKey)return!0;const i=this.getDirectionalIncrementer(e);if(!i)return!t.target.closest("[role=radiogroup]");const s=this.activeIndex+i;return this.focusableElements[s]&&t.preventDefault(),this.setFocusedElement(s),!0}get allSlottedItems(){return[...this.start.assignedElements(),...this.slottedItems,...this.end.assignedElements()]}reduceFocusableElements(){const t=this.focusableElements?.[this.activeIndex];this.focusableElements=this.allSlottedItems.reduce(Mr.reduceFocusableItems,[]);const e=this.focusableElements.indexOf(t);this.activeIndex=Math.max(0,e),this.setFocusableElements()}setFocusedElement(t=this.activeIndex){this.activeIndex=t,this.setFocusableElements(),this.focusableElements[this.activeIndex]&&this.contains(function(t){const e=t.getRootNode();return e instanceof ShadowRoot?e.activeElement:document.activeElement}(this))&&this.focusableElements[this.activeIndex].focus()}static reduceFocusableItems(t,e){const i="radio"===e.getAttribute("role"),s=e.$fastController?.definition.shadowOptions?.delegatesFocus,o=Array.from(e.shadowRoot?.querySelectorAll("*")??[]).some((t=>_o(t)));return e.hasAttribute("disabled")||e.hasAttribute("hidden")||!(_o(e)||i||s||o)?e.childElementCount?t.concat(Array.from(e.children).reduce(Mr.reduceFocusableItems,[])):t:(t.push(e),t)}setFocusableElements(){this.$fastController.isConnected&&this.focusableElements.length>0&&this.focusableElements.forEach(((t,e)=>{t.tabIndex=this.activeIndex===e?0:-1}))}}oe([f],Mr.prototype,"direction",void 0),oe([lt],Mr.prototype,"orientation",void 0),oe([f],Mr.prototype,"slottedItems",void 0),oe([f],Mr.prototype,"slottedLabel",void 0),oe([f],Mr.prototype,"childItems",void 0);class Vr{}oe([lt({attribute:"aria-labelledby"})],Vr.prototype,"ariaLabelledby",void 0),oe([lt({attribute:"aria-label"})],Vr.prototype,"ariaLabel",void 0),oi(Vr,Vi),oi(Mr,Zt,Vr);const Hr=(t,e)=>K`
1393
+ `;const Pr=Object.freeze({[Oi.ArrowUp]:{[li]:-1},[Oi.ArrowDown]:{[li]:1},[Oi.ArrowLeft]:{[ai]:{[Si.ltr]:-1,[Si.rtl]:1}},[Oi.ArrowRight]:{[ai]:{[Si.ltr]:1,[Si.rtl]:-1}}});class Mr extends ei{constructor(){super(...arguments),this._activeIndex=0,this.direction=Si.ltr,this.focusableElements=[],this.orientation=ai}get activeIndex(){return m.track(this,"activeIndex"),this._activeIndex}set activeIndex(t){this.$fastController.isConnected&&(this._activeIndex=Ri(0,this.focusableElements.length>0?this.focusableElements.length-1:0,t),m.notify(this,"activeIndex"))}slottedItemsChanged(){this.$fastController.isConnected&&this.reduceFocusableElements()}mouseDownHandler(t){const e=this.focusableElements.findIndex((e=>e.contains(t.target)));return e>-1&&this.activeIndex!==e&&this.setFocusedElement(e),!0}childItemsChanged(t,e){this.$fastController.isConnected&&this.reduceFocusableElements()}connectedCallback(){super.connectedCallback(),this.direction=Bi(this)}focusinHandler(t){const e=t.relatedTarget;e&&!this.contains(e)&&this.setFocusedElement()}getDirectionalIncrementer(t){return Pr[t]?.[this.orientation]?.[this.direction]??Pr[t]?.[this.orientation]??0}keydownHandler(t){const e=t.key;if(!(e in Oi)||t.defaultPrevented||t.shiftKey)return!0;const i=this.getDirectionalIncrementer(e);if(!i)return!t.target.closest("[role=radiogroup]");const s=this.activeIndex+i;return this.focusableElements.length>0&&this.focusableElements[s]&&t.preventDefault(),this.setFocusedElement(s),!0}get allSlottedItems(){return[...this.start.assignedElements(),...this.slottedItems,...this.end.assignedElements()]}reduceFocusableElements(){const t=this.focusableElements[this.activeIndex];this.focusableElements=this.allSlottedItems.reduce(Mr.reduceFocusableItems,[]);const e=this.focusableElements.indexOf(t);this.activeIndex=Math.max(0,e),this.setFocusableElements()}setFocusedElement(t=this.activeIndex){this.activeIndex=t,this.setFocusableElements(),this.focusableElements.length>0&&this.focusableElements[this.activeIndex]&&this.contains(function(t){const e=t.getRootNode();return e instanceof ShadowRoot?e.activeElement:document.activeElement}(this))&&this.focusableElements[this.activeIndex].focus()}static reduceFocusableItems(t,e){const i="radio"===e.getAttribute("role"),s=e.$fastController?.definition.shadowOptions?.delegatesFocus,o=Array.from(e.shadowRoot?.querySelectorAll("*")??[]).some((t=>_o(t)));return e.hasAttribute("disabled")||e.hasAttribute("hidden")||!(_o(e)||i||s||o)?e.childElementCount?t.concat(Array.from(e.children).reduce(Mr.reduceFocusableItems,[])):t:(t.push(e),t)}setFocusableElements(){this.$fastController.isConnected&&this.focusableElements.length>0&&this.focusableElements.forEach(((t,e)=>{t.tabIndex=this.activeIndex===e?0:-1}))}}oe([f],Mr.prototype,"direction",void 0),oe([lt],Mr.prototype,"orientation",void 0),oe([f],Mr.prototype,"slottedItems",void 0),oe([f],Mr.prototype,"slottedLabel",void 0),oe([f],Mr.prototype,"childItems",void 0);class Vr{}oe([lt({attribute:"aria-labelledby"})],Vr.prototype,"ariaLabelledby",void 0),oe([lt({attribute:"aria-label"})],Vr.prototype,"ariaLabel",void 0),oi(Vr,Vi),oi(Mr,Zt,Vr);const Hr=(t,e)=>K`
1394
1394
  ${zt((t=>t.tooltipVisible),K`
1395
1395
  <${t.tagFor(Ui)}
1396
1396
  fixed-placement="true"
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@ni/fast-foundation",
3
3
  "description": "A library of Web Component building blocks",
4
4
  "sideEffects": false,
5
- "version": "10.2.1",
5
+ "version": "10.2.2",
6
6
  "author": {
7
7
  "name": "National Instruments"
8
8
  },