@ni/nimble-components 11.7.0 → 11.7.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.
@@ -278,30 +278,6 @@
278
278
  },
279
279
  });
280
280
 
281
- function spilloverSubscribe(subscriber) {
282
- const spillover = this.spillover;
283
- const index = spillover.indexOf(subscriber);
284
- if (index === -1) {
285
- spillover.push(subscriber);
286
- }
287
- }
288
- function spilloverUnsubscribe(subscriber) {
289
- const spillover = this.spillover;
290
- const index = spillover.indexOf(subscriber);
291
- if (index !== -1) {
292
- spillover.splice(index, 1);
293
- }
294
- }
295
- function spilloverNotifySubscribers(args) {
296
- const spillover = this.spillover;
297
- const source = this.source;
298
- for (let i = 0, ii = spillover.length; i < ii; ++i) {
299
- spillover[i].handleChange(source, args);
300
- }
301
- }
302
- function spilloverHas(subscriber) {
303
- return this.spillover.indexOf(subscriber) !== -1;
304
- }
305
281
  /**
306
282
  * An implementation of {@link Notifier} that efficiently keeps track of
307
283
  * subscribers interested in a specific change notification on an
@@ -331,42 +307,58 @@
331
307
  * @param subscriber - The subscriber to test for inclusion in this set.
332
308
  */
333
309
  has(subscriber) {
334
- return this.sub1 === subscriber || this.sub2 === subscriber;
310
+ return this.spillover === void 0
311
+ ? this.sub1 === subscriber || this.sub2 === subscriber
312
+ : this.spillover.indexOf(subscriber) !== -1;
335
313
  }
336
314
  /**
337
315
  * Subscribes to notification of changes in an object's state.
338
316
  * @param subscriber - The object that is subscribing for change notification.
339
317
  */
340
318
  subscribe(subscriber) {
341
- if (this.has(subscriber)) {
342
- return;
343
- }
344
- if (this.sub1 === void 0) {
345
- this.sub1 = subscriber;
346
- return;
319
+ const spillover = this.spillover;
320
+ if (spillover === void 0) {
321
+ if (this.has(subscriber)) {
322
+ return;
323
+ }
324
+ if (this.sub1 === void 0) {
325
+ this.sub1 = subscriber;
326
+ return;
327
+ }
328
+ if (this.sub2 === void 0) {
329
+ this.sub2 = subscriber;
330
+ return;
331
+ }
332
+ this.spillover = [this.sub1, this.sub2, subscriber];
333
+ this.sub1 = void 0;
334
+ this.sub2 = void 0;
347
335
  }
348
- if (this.sub2 === void 0) {
349
- this.sub2 = subscriber;
350
- return;
336
+ else {
337
+ const index = spillover.indexOf(subscriber);
338
+ if (index === -1) {
339
+ spillover.push(subscriber);
340
+ }
351
341
  }
352
- this.spillover = [this.sub1, this.sub2, subscriber];
353
- this.subscribe = spilloverSubscribe;
354
- this.unsubscribe = spilloverUnsubscribe;
355
- this.notify = spilloverNotifySubscribers;
356
- this.has = spilloverHas;
357
- this.sub1 = void 0;
358
- this.sub2 = void 0;
359
342
  }
360
343
  /**
361
344
  * Unsubscribes from notification of changes in an object's state.
362
345
  * @param subscriber - The object that is unsubscribing from change notification.
363
346
  */
364
347
  unsubscribe(subscriber) {
365
- if (this.sub1 === subscriber) {
366
- this.sub1 = void 0;
348
+ const spillover = this.spillover;
349
+ if (spillover === void 0) {
350
+ if (this.sub1 === subscriber) {
351
+ this.sub1 = void 0;
352
+ }
353
+ else if (this.sub2 === subscriber) {
354
+ this.sub2 = void 0;
355
+ }
367
356
  }
368
- else if (this.sub2 === subscriber) {
369
- this.sub2 = void 0;
357
+ else {
358
+ const index = spillover.indexOf(subscriber);
359
+ if (index !== -1) {
360
+ spillover.splice(index, 1);
361
+ }
370
362
  }
371
363
  }
372
364
  /**
@@ -374,14 +366,22 @@
374
366
  * @param args - Data passed along to subscribers during notification.
375
367
  */
376
368
  notify(args) {
377
- const sub1 = this.sub1;
378
- const sub2 = this.sub2;
369
+ const spillover = this.spillover;
379
370
  const source = this.source;
380
- if (sub1 !== void 0) {
381
- sub1.handleChange(source, args);
371
+ if (spillover === void 0) {
372
+ const sub1 = this.sub1;
373
+ const sub2 = this.sub2;
374
+ if (sub1 !== void 0) {
375
+ sub1.handleChange(source, args);
376
+ }
377
+ if (sub2 !== void 0) {
378
+ sub2.handleChange(source, args);
379
+ }
382
380
  }
383
- if (sub2 !== void 0) {
384
- sub2.handleChange(source, args);
381
+ else {
382
+ for (let i = 0, ii = spillover.length; i < ii; ++i) {
383
+ spillover[i].handleChange(source, args);
384
+ }
385
385
  }
386
386
  }
387
387
  }
@@ -6745,8 +6745,14 @@
6745
6745
  * @internal
6746
6746
  */
6747
6747
  this.keypressHandler = (e) => {
6748
+ if (this.readOnly) {
6749
+ return;
6750
+ }
6748
6751
  switch (e.key) {
6749
6752
  case keySpace:
6753
+ if (this.indeterminate) {
6754
+ this.indeterminate = false;
6755
+ }
6750
6756
  this.checked = !this.checked;
6751
6757
  break;
6752
6758
  }
@@ -6756,6 +6762,9 @@
6756
6762
  */
6757
6763
  this.clickHandler = (e) => {
6758
6764
  if (!this.disabled && !this.readOnly) {
6765
+ if (this.indeterminate) {
6766
+ this.indeterminate = false;
6767
+ }
6759
6768
  this.checked = !this.checked;
6760
6769
  }
6761
6770
  };
@@ -7780,7 +7789,7 @@
7780
7789
  * @internal
7781
7790
  */
7782
7791
  focusoutHandler(e) {
7783
- this.updateValue();
7792
+ this.syncValue();
7784
7793
  if (!this.open) {
7785
7794
  return true;
7786
7795
  }
@@ -7802,7 +7811,12 @@
7802
7811
  inputHandler(e) {
7803
7812
  this.filter = this.control.value;
7804
7813
  this.filterOptions();
7805
- if (e.inputType === "deleteContentBackward" || !this.filter.length) {
7814
+ if (!this.isAutocompleteInline) {
7815
+ this.selectedIndex = this.options
7816
+ .map(option => option.text)
7817
+ .indexOf(this.control.value);
7818
+ }
7819
+ if (e.inputType.includes("deleteContent") || !this.filter.length) {
7806
7820
  return true;
7807
7821
  }
7808
7822
  if (this.isAutocompleteList && !this.open) {
@@ -7828,7 +7842,7 @@
7828
7842
  }
7829
7843
  switch (key) {
7830
7844
  case "Enter": {
7831
- this.updateValue(true);
7845
+ this.syncValue();
7832
7846
  if (this.isAutocompleteInline) {
7833
7847
  this.filter = this.value;
7834
7848
  }
@@ -7851,7 +7865,7 @@
7851
7865
  break;
7852
7866
  }
7853
7867
  case "Tab": {
7854
- this.updateValue();
7868
+ this.setInputToSelection();
7855
7869
  if (!this.open) {
7856
7870
  return true;
7857
7871
  }
@@ -7870,7 +7884,6 @@
7870
7884
  super.keydownHandler(e);
7871
7885
  }
7872
7886
  if (this.isAutocompleteInline) {
7873
- this.updateValue();
7874
7887
  this.setInlineSelection();
7875
7888
  }
7876
7889
  break;
@@ -7951,18 +7964,37 @@
7951
7964
  }
7952
7965
  }
7953
7966
  /**
7954
- * Focus and select the content of the control based on the first selected option.
7967
+ * Focus and set the content of the control based on the first selected option.
7955
7968
  *
7956
- * @param start - The index for the starting range
7957
7969
  * @internal
7958
7970
  */
7959
- setInlineSelection() {
7971
+ setInputToSelection() {
7960
7972
  if (this.firstSelectedOption) {
7961
7973
  this.control.value = this.firstSelectedOption.text;
7962
7974
  this.control.focus();
7975
+ }
7976
+ }
7977
+ /**
7978
+ * Focus, set and select the content of the control based on the first selected option.
7979
+ *
7980
+ * @internal
7981
+ */
7982
+ setInlineSelection() {
7983
+ if (this.firstSelectedOption) {
7984
+ this.setInputToSelection();
7963
7985
  this.control.setSelectionRange(this.filter.length, this.control.value.length, "backward");
7964
7986
  }
7965
7987
  }
7988
+ /**
7989
+ * Determines if a value update should involve emitting a change event, then updates the value.
7990
+ *
7991
+ * @internal
7992
+ */
7993
+ syncValue() {
7994
+ var _a;
7995
+ const newValue = this.selectedIndex > -1 ? (_a = this.firstSelectedOption) === null || _a === void 0 ? void 0 : _a.text : this.control.value;
7996
+ this.updateValue(this.value !== newValue);
7997
+ }
7966
7998
  /**
7967
7999
  * Calculate and apply listbox positioning based on available viewport space.
7968
8000
  *
@@ -8024,6 +8056,7 @@
8024
8056
  var _a;
8025
8057
  if (this.$fastController.isConnected) {
8026
8058
  this.value = ((_a = this.firstSelectedOption) === null || _a === void 0 ? void 0 : _a.text) || this.control.value;
8059
+ this.control.value = this.value;
8027
8060
  }
8028
8061
  if (shouldEmit) {
8029
8062
  this.$emit("change");
@@ -11894,7 +11927,7 @@
11894
11927
  this.updateValue(true);
11895
11928
  this.indexWhenOpened = this.selectedIndex;
11896
11929
  }
11897
- return !(key in ArrowKeys);
11930
+ return !(key === keyArrowDown || key === keyArrowUp);
11898
11931
  }
11899
11932
  connectedCallback() {
11900
11933
  super.connectedCallback();
@@ -12866,6 +12899,12 @@
12866
12899
  @click="${(x, c) => x.clickHandler(c.event)}"
12867
12900
  @focusin="${(x, c) => x.focusinHandler(c.event)}"
12868
12901
  @keydown="${(x, c) => x.keydownHandler(c.event)}"
12902
+ ${children({
12903
+ property: "childItems",
12904
+ attributeFilter: ["disabled", "hidden"],
12905
+ filter: elements(),
12906
+ subtree: true,
12907
+ })}
12869
12908
  >
12870
12909
  <slot name="label"></slot>
12871
12910
  <div class="positioning-region" part="positioning-region">
@@ -12942,11 +12981,6 @@
12942
12981
  * HTML Attribute: `orientation`
12943
12982
  */
12944
12983
  this.orientation = Orientation.horizontal;
12945
- this.startEndSlotChange = () => {
12946
- if (this.$fastController.isConnected) {
12947
- this.reduceFocusableElements();
12948
- }
12949
- };
12950
12984
  }
12951
12985
  /**
12952
12986
  * The index of the currently focused element, clamped between 0 and the last element.
@@ -12981,22 +13015,17 @@
12981
13015
  }
12982
13016
  return true;
12983
13017
  }
13018
+ childItemsChanged(prev, next) {
13019
+ if (this.$fastController.isConnected) {
13020
+ this.reduceFocusableElements();
13021
+ }
13022
+ }
12984
13023
  /**
12985
13024
  * @internal
12986
13025
  */
12987
13026
  connectedCallback() {
12988
13027
  super.connectedCallback();
12989
13028
  this.direction = getDirection(this);
12990
- this.start.addEventListener("slotchange", this.startEndSlotChange);
12991
- this.end.addEventListener("slotchange", this.startEndSlotChange);
12992
- }
12993
- /**
12994
- * @internal
12995
- */
12996
- disconnectedCallback() {
12997
- super.disconnectedCallback();
12998
- this.start.removeEventListener("slotchange", this.startEndSlotChange);
12999
- this.end.removeEventListener("slotchange", this.startEndSlotChange);
13000
13029
  }
13001
13030
  /**
13002
13031
  * When the toolbar receives focus, set the currently active element as focused.
@@ -13059,7 +13088,13 @@
13059
13088
  * @internal
13060
13089
  */
13061
13090
  reduceFocusableElements() {
13091
+ var _a;
13092
+ const previousFocusedElement = (_a = this.focusableElements) === null || _a === void 0 ? void 0 : _a[this.activeIndex];
13062
13093
  this.focusableElements = this.allSlottedItems.reduce(Toolbar$1.reduceFocusableItems, []);
13094
+ // If the previously active item is still focusable, adjust the active index to the
13095
+ // index of that item.
13096
+ const adjustedActiveIndex = this.focusableElements.indexOf(previousFocusedElement);
13097
+ this.activeIndex = Math.max(0, adjustedActiveIndex);
13063
13098
  this.setFocusableElements();
13064
13099
  }
13065
13100
  /**
@@ -13087,10 +13122,12 @@
13087
13122
  const isRoleRadio = element.getAttribute("role") === "radio";
13088
13123
  const isFocusableFastElement = (_b = (_a = element.$fastController) === null || _a === void 0 ? void 0 : _a.definition.shadowOptions) === null || _b === void 0 ? void 0 : _b.delegatesFocus;
13089
13124
  const hasFocusableShadow = Array.from((_d = (_c = element.shadowRoot) === null || _c === void 0 ? void 0 : _c.querySelectorAll("*")) !== null && _d !== void 0 ? _d : []).some(x => isFocusable(x));
13090
- if (isFocusable(element) ||
13091
- isRoleRadio ||
13092
- isFocusableFastElement ||
13093
- hasFocusableShadow) {
13125
+ if (!element.hasAttribute("disabled") &&
13126
+ !element.hasAttribute("hidden") &&
13127
+ (isFocusable(element) ||
13128
+ isRoleRadio ||
13129
+ isFocusableFastElement ||
13130
+ hasFocusableShadow)) {
13094
13131
  elements.push(element);
13095
13132
  return elements;
13096
13133
  }
@@ -13122,6 +13159,9 @@
13122
13159
  __decorate$1([
13123
13160
  observable
13124
13161
  ], Toolbar$1.prototype, "slottedLabel", void 0);
13162
+ __decorate$1([
13163
+ observable
13164
+ ], Toolbar$1.prototype, "childItems", void 0);
13125
13165
  /**
13126
13166
  * Includes ARIA states and properties relating to the ARIA toolbar role
13127
13167
  *