@fluentui/web-components 3.0.0-rc.22 → 3.0.0-rc.23

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.
@@ -2146,6 +2146,31 @@ export declare class BaseDropdown extends FASTElement {
2146
2146
  * This method can be overridden in derived classes to provide custom control elements, though this is not recommended.
2147
2147
  */
2148
2148
  protected insertControl(): void;
2149
+ /**
2150
+ * The duration in milliseconds after the last character search keystroke before the search string is cleared.
2151
+ */
2152
+ protected searchTimeoutMs: number;
2153
+ /**
2154
+ * The accumulated search string used to match option labels by prefix when printable characters are typed.
2155
+ *
2156
+ * @internal
2157
+ */
2158
+ private searchString;
2159
+ /**
2160
+ * The timeout id used to reset the search string.
2161
+ *
2162
+ * @internal
2163
+ */
2164
+ private searchTimeout?;
2165
+ /**
2166
+ * Handles printable character input by moving {@link activeIndex} to the next option whose label matches the
2167
+ * accumulated search string. When the string is a single character (or the same character repeated), matching
2168
+ * options are cycled through; otherwise the string is treated as a prefix match.
2169
+ *
2170
+ * @param char - the printable character that was pressed
2171
+ * @internal
2172
+ */
2173
+ private handleSearchCharacter;
2149
2174
  /**
2150
2175
  * Handles the keydown events for the dropdown.
2151
2176
  *
@@ -7575,6 +7575,16 @@ const _BaseDropdown = class _BaseDropdown extends FASTElement {
7575
7575
  * @internal
7576
7576
  */
7577
7577
  this._insertingControl = false;
7578
+ /**
7579
+ * The duration in milliseconds after the last character search keystroke before the search string is cleared.
7580
+ */
7581
+ this.searchTimeoutMs = 500;
7582
+ /**
7583
+ * The accumulated search string used to match option labels by prefix when printable characters are typed.
7584
+ *
7585
+ * @internal
7586
+ */
7587
+ this.searchString = "";
7578
7588
  this.elementInternals.role = "presentation";
7579
7589
  }
7580
7590
  get activeDescendant() {
@@ -8028,6 +8038,35 @@ const _BaseDropdown = class _BaseDropdown extends FASTElement {
8028
8038
  dropdownButtonTemplate.render(this, this);
8029
8039
  this._insertingControl = false;
8030
8040
  }
8041
+ /**
8042
+ * Handles printable character input by moving {@link activeIndex} to the next option whose label matches the
8043
+ * accumulated search string. When the string is a single character (or the same character repeated), matching
8044
+ * options are cycled through; otherwise the string is treated as a prefix match.
8045
+ *
8046
+ * @param char - the printable character that was pressed
8047
+ * @internal
8048
+ */
8049
+ handleSearchCharacter(char) {
8050
+ const isRepeating = this.searchString === char.repeat(this.searchString.length);
8051
+ this.searchString += char;
8052
+ let candidates = this.searchString.length > 1 ? this.filterOptions(this.searchString) : [];
8053
+ let isCycling = false;
8054
+ if (!candidates.length && isRepeating) {
8055
+ candidates = this.filterOptions(char);
8056
+ isCycling = true;
8057
+ }
8058
+ if (candidates.length) {
8059
+ const activeOption = this.enabledOptions[this.activeIndex];
8060
+ const currentPos = candidates.indexOf(activeOption);
8061
+ const nextMatch = isCycling ? candidates[this.getEnabledIndexInBounds(currentPos + 1, candidates.length)] : currentPos >= 0 ? activeOption : candidates[0];
8062
+ this.activeIndex = this.enabledOptions.indexOf(nextMatch);
8063
+ }
8064
+ clearTimeout(this.searchTimeout);
8065
+ this.searchTimeout = setTimeout(() => {
8066
+ this.searchString = "";
8067
+ this.searchTimeout = void 0;
8068
+ }, this.searchTimeoutMs);
8069
+ }
8031
8070
  /**
8032
8071
  * Handles the keydown events for the dropdown.
8033
8072
  *
@@ -8047,14 +8086,15 @@ const _BaseDropdown = class _BaseDropdown extends FASTElement {
8047
8086
  increment = 1;
8048
8087
  break;
8049
8088
  }
8050
- case " ": {
8051
- if (this.isCombobox) {
8052
- break;
8053
- }
8054
- e.preventDefault();
8055
- }
8089
+ case " ":
8056
8090
  case "Enter":
8057
8091
  case "Tab": {
8092
+ if (e.key === " ") {
8093
+ if (this.isCombobox) {
8094
+ break;
8095
+ }
8096
+ e.preventDefault();
8097
+ }
8058
8098
  if (this.open) {
8059
8099
  this.selectOption(this.activeIndex, true);
8060
8100
  if (this.multiple) {
@@ -8073,6 +8113,12 @@ const _BaseDropdown = class _BaseDropdown extends FASTElement {
8073
8113
  }
8074
8114
  }
8075
8115
  if (!increment) {
8116
+ if (!this.isCombobox && e.key.length === 1 && e.key !== " " && !e.ctrlKey && !e.metaKey && !e.altKey) {
8117
+ if (!this.open) {
8118
+ this.listbox.showPopover();
8119
+ }
8120
+ this.handleSearchCharacter(e.key);
8121
+ }
8076
8122
  return true;
8077
8123
  }
8078
8124
  if (!this.open) {
@@ -8200,6 +8246,11 @@ const _BaseDropdown = class _BaseDropdown extends FASTElement {
8200
8246
  disconnectedCallback() {
8201
8247
  _BaseDropdown.AnchorPositionFallbackObserver?.disconnect();
8202
8248
  this.debounceController?.abort();
8249
+ if (this.searchTimeout) {
8250
+ clearTimeout(this.searchTimeout);
8251
+ this.searchTimeout = void 0;
8252
+ this.searchString = "";
8253
+ }
8203
8254
  super.disconnectedCallback();
8204
8255
  }
8205
8256
  /**