@fluid-topics/ft-search-input 1.3.17 → 1.3.19

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.
@@ -25,7 +25,7 @@ class FtSearchInputSuggestionManager {
25
25
  role="listbox"
26
26
  aria-label="${searchInputContext.messages.suggestionsLabel()}"
27
27
  part="container">
28
- ${repeat(this.ftSearchInput.suggestResults || [], suggest => suggest.value, (suggest, index) => {
28
+ ${repeat(this.ftSearchInput.suggestResults || [], (suggest) => suggest.value, (suggest, index) => {
29
29
  return this.renderSuggestion(index, suggest, searchPlaceConverter);
30
30
  })}
31
31
  </div>
@@ -85,14 +85,14 @@ class FtSearchInputSuggestionManager {
85
85
  break;
86
86
  }
87
87
  return html `
88
- <ft-icon .variant="${iconVariant}" .value="${icon}" part="suggestion-icon"></ft-icon>
88
+ <ft-icon .variant=${iconVariant} .value=${icon} part="suggestion-icon"></ft-icon>
89
89
  `;
90
90
  }
91
91
  get selectedSuggestOption() {
92
92
  return this.ftSearchInput.shadowRoot.querySelector(`#${this.ftSearchInput.selectedSuggestOptionId}`);
93
93
  }
94
94
  getLastSuggestionElement() {
95
- let suggestions = this.ftSearchInput.shadowRoot.querySelectorAll("[role=option]");
95
+ const suggestions = this.ftSearchInput.shadowRoot.querySelectorAll("[role=option]");
96
96
  return suggestions.length > 0 ? suggestions[suggestions.length - 1] : null;
97
97
  }
98
98
  getFirstSuggestionElement() {
@@ -17,6 +17,7 @@ export declare class FtSearchInput extends FtSearchInput_base implements FtSearc
17
17
  launchSearchPath?: string;
18
18
  useCustomSearchPath: boolean;
19
19
  triggerSearchOnClear: boolean;
20
+ focusOnDisplay: boolean;
20
21
  input: HTMLInputElement;
21
22
  private launchSearchButton;
22
23
  suggestions: FtSearchInputSuggestionManager;
@@ -30,7 +31,9 @@ export declare class FtSearchInput extends FtSearchInput_base implements FtSearc
30
31
  onSuggestionSelected(value: string): void;
31
32
  get shouldDisplaySuggestions(): boolean;
32
33
  private onClick;
34
+ private showSuggestionsOnFocus;
33
35
  private onFocus;
36
+ focusInput(showSuggestions?: boolean): Promise<void>;
34
37
  connectedCallback(): Promise<void>;
35
38
  disconnectedCallback(): void;
36
39
  private closeSuggestListbox;
@@ -5,7 +5,7 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
5
5
  return c > 3 && r && Object.defineProperty(target, key, r), r;
6
6
  };
7
7
  import { html, nothing } from "lit";
8
- import { noTextInputDefaultClearButton, redux, screenReaderStyles } from "@fluid-topics/ft-wc-utils";
8
+ import { isTouchScreen, noTextInputDefaultClearButton, redux, screenReaderStyles, waitFor } from "@fluid-topics/ft-wc-utils";
9
9
  import { styles } from "./ft-search-input.styles";
10
10
  import { FtSearchComponent } from "@fluid-topics/ft-search-context/build/registration";
11
11
  import { withI18n } from "@fluid-topics/ft-i18n";
@@ -24,10 +24,12 @@ class FtSearchInput extends withI18n(FtSearchComponent) {
24
24
  this.displaySuggestListbox = false;
25
25
  this.useCustomSearchPath = false;
26
26
  this.triggerSearchOnClear = false;
27
+ this.focusOnDisplay = false;
27
28
  this.suggestions = new FtSearchInputSuggestionManager(this);
29
+ this.showSuggestionsOnFocus = true;
28
30
  this.closeSuggestListbox = (e) => {
29
31
  const path = e.composedPath();
30
- const inside = path.some(n => n === this || n === this.shadowRoot);
32
+ const inside = path.some((n) => n === this || n === this.shadowRoot);
31
33
  if (!inside) {
32
34
  this.displaySuggestListbox = false;
33
35
  this.selectedSuggestOptionId = undefined;
@@ -37,7 +39,7 @@ class FtSearchInput extends withI18n(FtSearchComponent) {
37
39
  }
38
40
  render() {
39
41
  var _a, _b, _c;
40
- let classes = {
42
+ const classes = {
41
43
  "ft-search-input": true,
42
44
  "ft-search-input--with-suggestions": (_b = (_a = this.suggestResults) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0 > 0,
43
45
  "ft-search-input--with-suggestions-closed": this.forceCloseSuggestion,
@@ -53,17 +55,17 @@ class FtSearchInput extends withI18n(FtSearchComponent) {
53
55
  part="input"
54
56
  type="search"
55
57
  placeholder="${searchInputContext.messages.placeholder()}"
56
- .value="${this.liveQuery}"
58
+ .value=${this.liveQuery}
57
59
  role="combobox"
58
60
  aria-autocomplete="list"
59
61
  aria-controls="${this.suggestions.listboxId}"
60
62
  aria-expanded="${this.displaySuggestListbox}"
61
63
  aria-activedescendant="${(_c = this.selectedSuggestOptionId) !== null && _c !== void 0 ? _c : nothing}"
62
- @input=${(e) => this.onInput(e)}
63
- @click="${() => this.onClick()}"
64
- @focus="${() => this.onFocus()}"
65
- @keydown=${(e) => this.onSearchBarKeyDown(e)}
66
- @keyup=${(e) => this.onSearchBarKeyUp(e)}>
64
+ @input=${this.onInput}
65
+ @click=${this.onClick}
66
+ @focus=${this.onFocus}
67
+ @keydown=${this.onSearchBarKeyDown}
68
+ @keyup=${this.onSearchBarKeyUp}>
67
69
  </div>
68
70
  <div class="sr-only" aria-live="polite" aria-atomic="true">
69
71
  ${this.renderLiveText()}
@@ -103,6 +105,7 @@ class FtSearchInput extends withI18n(FtSearchComponent) {
103
105
  }
104
106
  }
105
107
  onSearchBarKeyDown(e) {
108
+ this.forceCloseSuggestion = false;
106
109
  if (!["Escape", "Tab", "Shift"].includes(e.key)) {
107
110
  this.displaySuggestListbox = true;
108
111
  }
@@ -137,10 +140,11 @@ class FtSearchInput extends withI18n(FtSearchComponent) {
137
140
  this.suggestions.clearSelection();
138
141
  }
139
142
  break;
140
- case "Enter":
143
+ case "Enter": {
141
144
  const elementToClick = this.suggestions.selectedSuggestOption || this.launchSearchButton;
142
145
  elementToClick === null || elementToClick === void 0 ? void 0 : elementToClick.click();
143
146
  break;
147
+ }
144
148
  case "Backspace":
145
149
  e.stopPropagation();
146
150
  break;
@@ -163,7 +167,7 @@ class FtSearchInput extends withI18n(FtSearchComponent) {
163
167
  break;
164
168
  }
165
169
  }
166
- onInput(e) {
170
+ onInput() {
167
171
  var _a;
168
172
  (_a = this.stateManager) === null || _a === void 0 ? void 0 : _a.setLiveQuery(this.input.value);
169
173
  this.forceCloseSuggestion = false;
@@ -171,7 +175,9 @@ class FtSearchInput extends withI18n(FtSearchComponent) {
171
175
  onClearInput() {
172
176
  var _a;
173
177
  (_a = this.stateManager) === null || _a === void 0 ? void 0 : _a.setLiveQuery("");
174
- this.triggerSearchOnClear ? this.launchSearch("") : nothing;
178
+ if (this.triggerSearchOnClear) {
179
+ this.launchSearch("");
180
+ }
175
181
  this.input.focus();
176
182
  }
177
183
  launchSearch(query) {
@@ -187,17 +193,29 @@ class FtSearchInput extends withI18n(FtSearchComponent) {
187
193
  }
188
194
  get shouldDisplaySuggestions() {
189
195
  var _a;
190
- return this.displaySuggestListbox && ((_a = this.suggestResults) !== null && _a !== void 0 ? _a : []).length > 0;
196
+ return !this.forceCloseSuggestion && this.displaySuggestListbox && ((_a = this.suggestResults) !== null && _a !== void 0 ? _a : []).length > 0;
191
197
  }
192
198
  onClick() {
193
199
  this.onFocus();
194
200
  }
195
201
  onFocus() {
196
- this.displaySuggestListbox = true;
202
+ if (this.showSuggestionsOnFocus) {
203
+ this.displaySuggestListbox = true;
204
+ }
205
+ this.forceCloseSuggestion = false;
206
+ }
207
+ async focusInput(showSuggestions = true) {
208
+ this.showSuggestionsOnFocus = showSuggestions;
209
+ await waitFor(() => this.input, 50);
210
+ this.input.focus();
211
+ this.showSuggestionsOnFocus = true;
197
212
  }
198
213
  async connectedCallback() {
199
214
  super.connectedCallback();
200
215
  document.addEventListener("pointerdown", this.closeSuggestListbox);
216
+ if (this.focusOnDisplay && !isTouchScreen) {
217
+ this.focusInput(false);
218
+ }
201
219
  }
202
220
  disconnectedCallback() {
203
221
  super.disconnectedCallback();
@@ -213,7 +231,7 @@ FtSearchInput.styles = [
213
231
  noTextInputDefaultClearButton,
214
232
  styles,
215
233
  ...FtSearchInputSuggestionManager.styles,
216
- screenReaderStyles
234
+ screenReaderStyles,
217
235
  ];
218
236
  __decorate([
219
237
  redux()
@@ -242,6 +260,9 @@ __decorate([
242
260
  __decorate([
243
261
  property({ type: Boolean })
244
262
  ], FtSearchInput.prototype, "triggerSearchOnClear", void 0);
263
+ __decorate([
264
+ property({ type: Boolean })
265
+ ], FtSearchInput.prototype, "focusOnDisplay", void 0);
245
266
  __decorate([
246
267
  query(".ft-search-input--input")
247
268
  ], FtSearchInput.prototype, "input", void 0);