@ni/spright-components 1.0.0 → 1.0.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.
@@ -16333,7 +16333,7 @@
16333
16333
 
16334
16334
  /**
16335
16335
  * Do not edit directly
16336
- * Generated on Wed, 15 May 2024 18:39:02 GMT
16336
+ * Generated on Wed, 15 May 2024 20:53:59 GMT
16337
16337
  */
16338
16338
 
16339
16339
  const Information100DarkUi = "#a46eff";
@@ -20755,7 +20755,7 @@
20755
20755
 
20756
20756
  .indicator {
20757
20757
  flex: none;
20758
- margin-inline-start: 1em;
20758
+ margin-left: ${smallPadding};
20759
20759
  padding-right: 8px;
20760
20760
  display: flex;
20761
20761
  justify-content: center;
@@ -58639,8 +58639,15 @@ img.ProseMirror-separator {
58639
58639
  order: 1;
58640
58640
  }
58641
58641
 
58642
- [part='indicator'] {
58642
+ .clear-button {
58643
58643
  order: 3;
58644
+ width: auto;
58645
+ height: auto;
58646
+ margin-left: ${smallPadding};
58647
+ }
58648
+
58649
+ [part='indicator'] {
58650
+ order: 4;
58644
58651
  }
58645
58652
 
58646
58653
  .error-icon {
@@ -58776,7 +58783,6 @@ img.ProseMirror-separator {
58776
58783
  role="combobox"
58777
58784
  tabindex="${x => (!x.disabled ? '0' : null)}"
58778
58785
  @click="${(x, c) => x.clickHandler(c.event)}"
58779
- @change="${x => x.changeValueHandler()}"
58780
58786
  @contentchange="${x => x.updateDisplayValue()}"
58781
58787
  @focusin="${(x, c) => x.focusinHandler(c.event)}"
58782
58788
  @focusout="${(x, c) => x.focusoutHandler(c.event)}"
@@ -58795,6 +58801,17 @@ img.ProseMirror-separator {
58795
58801
  <div class="selected-value ${x => (x.displayPlaceholder ? 'placeholder' : '')}" part="selected-value" ${overflow('hasOverflow')} title=${x => (x.hasOverflow && x.displayValue ? x.displayValue : null)}>
58796
58802
  <slot name="selected-value">${x => x.displayValue}</slot>
58797
58803
  </div>
58804
+ ${when(x => !x.disabled && x.clearable && !x.displayPlaceholder && x.selectedIndex >= 0, html `
58805
+ <${buttonTag}
58806
+ class="clear-button"
58807
+ tabindex="-1"
58808
+ part="clear-button"
58809
+ content-hidden
58810
+ appearance="ghost"
58811
+ @click="${(x, c) => x.clearClickHandler(c.event)}">
58812
+ <${iconXmarkTag} slot="start"></${iconXmarkTag}>
58813
+ </${buttonTag}>
58814
+ `)}
58798
58815
  <div aria-hidden="true" class="indicator" part="indicator">
58799
58816
  <slot name="indicator">
58800
58817
  ${definition.indicator || ''}
@@ -58889,6 +58906,9 @@ img.ProseMirror-separator {
58889
58906
  const isOptionSelectable = (el) => {
58890
58907
  return !el.visuallyHidden && !el.disabled && !el.hidden;
58891
58908
  };
58909
+ const isOptionPlaceholder = (el) => {
58910
+ return el.disabled && el.hidden;
58911
+ };
58892
58912
  /**
58893
58913
  * A nimble-styled HTML select.
58894
58914
  */
@@ -58898,6 +58918,7 @@ img.ProseMirror-separator {
58898
58918
  this.appearance = DropdownAppearance.underline;
58899
58919
  this.errorVisible = false;
58900
58920
  this.filterMode = FilterMode.none;
58921
+ this.clearable = false;
58901
58922
  /**
58902
58923
  * @internal
58903
58924
  */
@@ -58970,13 +58991,8 @@ img.ProseMirror-separator {
58970
58991
  if (prev !== newValue && !(this.open && this.selectedIndex < 0)) {
58971
58992
  this._value = newValue;
58972
58993
  super.valueChanged(prev, newValue);
58973
- if (!this.open) {
58974
- this.committedSelectedOption = this.options.find(o => o.value === newValue);
58975
- }
58976
58994
  Observable.notify(this, 'value');
58977
- if (this.collapsible) {
58978
- Observable.notify(this, 'displayValue');
58979
- }
58995
+ this.updateDisplayValue();
58980
58996
  }
58981
58997
  }
58982
58998
  /**
@@ -58984,7 +59000,7 @@ img.ProseMirror-separator {
58984
59000
  */
58985
59001
  get displayValue() {
58986
59002
  Observable.track(this, 'displayValue');
58987
- return this.committedSelectedOption?.text ?? '';
59003
+ return this.firstSelectedOption?.text ?? '';
58988
59004
  }
58989
59005
  /**
58990
59006
  * @internal
@@ -59028,7 +59044,6 @@ img.ProseMirror-separator {
59028
59044
  if (value) {
59029
59045
  this.value = value;
59030
59046
  }
59031
- this.committedSelectedOption = this.options[this.selectedIndex];
59032
59047
  }
59033
59048
  /**
59034
59049
  * @internal
@@ -59073,11 +59088,13 @@ img.ProseMirror-separator {
59073
59088
  break;
59074
59089
  }
59075
59090
  case 'selected': {
59076
- if (isNimbleListOption(sourceElement)) {
59091
+ if (isNimbleListOption(sourceElement)
59092
+ && sourceElement.selected) {
59077
59093
  this.selectedIndex = this.options.indexOf(sourceElement);
59078
59094
  }
59079
- this.setSelectedOptions();
59080
- this.updateDisplayValue();
59095
+ else {
59096
+ this.clearSelect();
59097
+ }
59081
59098
  break;
59082
59099
  }
59083
59100
  case 'hidden': {
@@ -59134,24 +59151,25 @@ img.ProseMirror-separator {
59134
59151
  /**
59135
59152
  * @internal
59136
59153
  */
59137
- changeValueHandler() {
59138
- this.committedSelectedOption = this.options.find(option => option.selected);
59154
+ clearClickHandler(e) {
59155
+ this.open = false;
59156
+ this.clearSelect();
59157
+ this.updateValue(true);
59158
+ e.stopPropagation();
59139
59159
  }
59140
59160
  /**
59141
59161
  * @internal
59142
59162
  */
59143
59163
  updateDisplayValue() {
59144
- if (this.committedSelectedOption?.disabled
59145
- && this.committedSelectedOption?.hidden
59146
- && this.committedSelectedOption?.selected) {
59164
+ const placeholderOption = this.getPlaceholderOption();
59165
+ if (placeholderOption
59166
+ && this.firstSelectedOption === placeholderOption) {
59147
59167
  this.displayPlaceholder = true;
59148
59168
  }
59149
59169
  else {
59150
59170
  this.displayPlaceholder = false;
59151
59171
  }
59152
- if (this.collapsible) {
59153
- Observable.notify(this, 'displayValue');
59154
- }
59172
+ Observable.notify(this, 'displayValue');
59155
59173
  }
59156
59174
  /**
59157
59175
  * Handle content changes on the control input.
@@ -59241,6 +59259,11 @@ img.ProseMirror-separator {
59241
59259
  }
59242
59260
  case keyEscape: {
59243
59261
  if (!this.open) {
59262
+ if (this.clearable) {
59263
+ this.clearSelect();
59264
+ this.updateValue(true);
59265
+ return true;
59266
+ }
59244
59267
  break;
59245
59268
  }
59246
59269
  if (this.collapsible && this.open) {
@@ -59385,10 +59408,10 @@ img.ProseMirror-separator {
59385
59408
  // for more info.
59386
59409
  this.options.push(option);
59387
59410
  }
59388
- // Prevents parent classes from resetting selectedIndex to a positive
59389
- // value while filtering, which can result in a disabled option being
59390
- // selected.
59391
59411
  setSelectedOptions() {
59412
+ // Prevents parent classes from resetting selectedIndex to a positive
59413
+ // value while filtering, which can result in a disabled option being
59414
+ // selected.
59392
59415
  if (this.open && this.selectedIndex === -1) {
59393
59416
  return;
59394
59417
  }
@@ -59484,12 +59507,17 @@ img.ProseMirror-separator {
59484
59507
  };
59485
59508
  let selectedIndex = -1;
59486
59509
  let firstValidOptionIndex = -1;
59510
+ let placeholderIndex = -1;
59487
59511
  for (let i = 0; i < options?.length; i++) {
59488
59512
  const option = options[i];
59489
- if (optionIsSelected(option) || option?.value === this.value) {
59513
+ if (optionIsSelected(option) || option.value === this.value) {
59490
59514
  selectedIndex = i;
59515
+ break;
59491
59516
  }
59492
- if (firstValidOptionIndex === -1
59517
+ else if (placeholderIndex === -1 && isOptionPlaceholder(option)) {
59518
+ placeholderIndex = i;
59519
+ }
59520
+ else if (firstValidOptionIndex === -1
59493
59521
  && isOptionSelectable(option)) {
59494
59522
  firstValidOptionIndex = i;
59495
59523
  }
@@ -59497,13 +59525,15 @@ img.ProseMirror-separator {
59497
59525
  if (selectedIndex !== -1) {
59498
59526
  this.selectedIndex = selectedIndex;
59499
59527
  }
59528
+ else if (placeholderIndex !== -1) {
59529
+ this.selectedIndex = placeholderIndex;
59530
+ }
59500
59531
  else if (firstValidOptionIndex !== -1) {
59501
59532
  this.selectedIndex = firstValidOptionIndex;
59502
59533
  }
59503
59534
  else {
59504
59535
  this.selectedIndex = 0;
59505
59536
  }
59506
- this.committedSelectedOption = options[this.selectedIndex];
59507
59537
  }
59508
59538
  setActiveOption(newActiveIndex) {
59509
59539
  const activeOption = this.options[newActiveIndex];
@@ -59539,8 +59569,8 @@ img.ProseMirror-separator {
59539
59569
  });
59540
59570
  }
59541
59571
  }
59542
- committedSelectedOptionChanged() {
59543
- this.updateDisplayValue();
59572
+ getPlaceholderOption() {
59573
+ return this.options.find(o => o.hidden && o.disabled);
59544
59574
  }
59545
59575
  setPositioning() {
59546
59576
  if (!this.$fastController.isConnected) {
@@ -59615,6 +59645,12 @@ img.ProseMirror-separator {
59615
59645
  });
59616
59646
  }
59617
59647
  }
59648
+ clearSelect() {
59649
+ const placeholder = this.getPlaceholderOption();
59650
+ this.selectedIndex = placeholder
59651
+ ? this.options.indexOf(placeholder)
59652
+ : -1;
59653
+ }
59618
59654
  /**
59619
59655
  * Resets and fills the proxy to match the component's options.
59620
59656
  *
@@ -59641,7 +59677,6 @@ img.ProseMirror-separator {
59641
59677
  this.updateListboxMaxHeightCssVariable();
59642
59678
  }
59643
59679
  initializeOpenState() {
59644
- this.committedSelectedOption = this.options[this.selectedIndex];
59645
59680
  this.setActiveOption(this.selectedIndex);
59646
59681
  this.ariaControls = this.listboxId;
59647
59682
  this.ariaExpanded = 'true';
@@ -59669,6 +59704,9 @@ img.ProseMirror-separator {
59669
59704
  __decorate$1([
59670
59705
  attr({ attribute: 'filter-mode' })
59671
59706
  ], Select.prototype, "filterMode", void 0);
59707
+ __decorate$1([
59708
+ attr({ attribute: 'clearable', mode: 'boolean' })
59709
+ ], Select.prototype, "clearable", void 0);
59672
59710
  __decorate$1([
59673
59711
  observable
59674
59712
  ], Select.prototype, "displayPlaceholder", void 0);
@@ -59699,9 +59737,6 @@ img.ProseMirror-separator {
59699
59737
  __decorate$1([
59700
59738
  observable
59701
59739
  ], Select.prototype, "filter", void 0);
59702
- __decorate$1([
59703
- observable
59704
- ], Select.prototype, "committedSelectedOption", void 0);
59705
59740
  __decorate$1([
59706
59741
  observable
59707
59742
  ], Select.prototype, "maxHeight", void 0);