@fluid-topics/ft-search-bar 0.2.17 → 0.2.20

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.
@@ -52,6 +52,9 @@ export const searchBarCss = css `
52
52
  right: ${FtSearchBarCssVariables.mobileOpenRight};
53
53
  z-index: ${FtSearchBarCssVariables.floatingZIndex};
54
54
  padding: 16px;
55
+ }
56
+
57
+ .ft-search-bar--mobile-menu-open:not(.ft-search-bar--forced-open) {
55
58
  background: ${FtSearchBarCssVariables.colorSurface};
56
59
  }
57
60
 
@@ -112,12 +115,12 @@ export const searchBarCss = css `
112
115
  flex-grow: 1;
113
116
  border: none;
114
117
  background-color: transparent;
118
+ color: ${FtSearchBarCssVariables.colorOnSurface};
115
119
  outline: none;
116
120
  }
117
121
 
118
- .ft-search-bar--desktop .ft-search-bar--input {
119
- flex-shrink: 0;
120
- min-width: 250px;
122
+ .ft-search-bar--input::placeholder {
123
+ color: ${FtSearchBarCssVariables.colorOnSurfaceMedium};
121
124
  }
122
125
 
123
126
  .ft-search-bar--actions {
@@ -387,12 +390,6 @@ export const suggestionsCss = css `
387
390
  display: block;
388
391
  }
389
392
 
390
- .ft-search-bar--no-suggestions {
391
- text-align: center;
392
- padding: 8px;
393
- color: ${FtSearchBarCssVariables.colorOnSurface};
394
- }
395
-
396
393
  .ft-search-bar--suggestion {
397
394
  text-decoration: none;
398
395
  position: relative;
@@ -18,7 +18,6 @@ export interface FtSearchBarLabels extends ParametrizedLabels {
18
18
  displayMoreFilterValuesButton?: string;
19
19
  noFilterValuesAvailable?: string;
20
20
  searchButton?: string;
21
- noSuggestions?: string;
22
21
  contentLocaleSelector?: string;
23
22
  presetsSelector?: string;
24
23
  removeRecentSearch?: string;
@@ -90,7 +89,6 @@ export declare class FtSearchBar extends FtLitElement implements FtSearchBarProp
90
89
  private lastSuggestion?;
91
90
  private updateFacetsDebouncer;
92
91
  private suggestDebouncer;
93
- private get recentSearchesStorageKey();
94
92
  private api?;
95
93
  get request(): FtSearchRequest;
96
94
  get facetsRequest(): Array<FtSearchFacetConf>;
@@ -101,6 +99,7 @@ export declare class FtSearchBar extends FtLitElement implements FtSearchBarProp
101
99
  private get hasPriors();
102
100
  private get hasLocaleSelector();
103
101
  focus(): void;
102
+ focusInput(): void;
104
103
  clear(): void;
105
104
  protected render(): import("lit-html").TemplateResult<1>;
106
105
  protected renderSearchBar(): import("lit-html").TemplateResult<1>;
@@ -135,6 +134,8 @@ export declare class FtSearchBar extends FtLitElement implements FtSearchBarProp
135
134
  private onSuggestKeyUp;
136
135
  private onSuggestSelected;
137
136
  private launchSearch;
137
+ private get recentSearchesStorageKey();
138
+ private initRecentSearches;
138
139
  private saveRecentSearches;
139
140
  private closeFloatingContainer;
140
141
  connectedCallback(): void;
@@ -36,7 +36,6 @@ export const DEFAULT_LABELS = {
36
36
  displayMoreFilterValuesButton: "More",
37
37
  noFilterValuesAvailable: "No values available",
38
38
  searchButton: "Search",
39
- noSuggestions: "No results found…",
40
39
  clearFilters: "Clear filters",
41
40
  contentLocaleSelector: "Lang",
42
41
  presetsSelector: "Preset",
@@ -107,9 +106,6 @@ export class FtSearchBar extends FtLitElement {
107
106
  get isMobileMenuOpen() {
108
107
  return this.isMobile && (this.forceMobileMenuOpen || this.forceMenuOpen || this.mobileMenuOpen);
109
108
  }
110
- get recentSearchesStorageKey() {
111
- return this.baseUrl + ":ft:recent-search-queries";
112
- }
113
109
  get request() {
114
110
  return {
115
111
  uiLocale: this.uiLocale,
@@ -123,7 +119,8 @@ export class FtSearchBar extends FtLitElement {
123
119
  };
124
120
  }
125
121
  get facetsRequest() {
126
- const fromFilters = this.searchFilters.filter(f => !this.displayedFilters.includes(f.key)).map(f => ({ id: f.key }));
122
+ const fromFilters = this.searchFilters.filter(f => f.values.length > 0 && !this.displayedFilters.includes(f.key))
123
+ .map(f => ({ id: f.key }));
127
124
  return [...this.displayedFilters.map(id => ({ id })), ...fromFilters];
128
125
  }
129
126
  get suggestRequest() {
@@ -160,6 +157,14 @@ export class FtSearchBar extends FtLitElement {
160
157
  var _a;
161
158
  (_a = this.container) === null || _a === void 0 ? void 0 : _a.focus();
162
159
  }
160
+ focusInput() {
161
+ if (this.input) {
162
+ this.input.focus();
163
+ }
164
+ else {
165
+ setTimeout(() => this.focusInput(), 50);
166
+ }
167
+ }
163
168
  clear() {
164
169
  this.query = "";
165
170
  this.searchFilters = [];
@@ -190,7 +195,8 @@ export class FtSearchBar extends FtLitElement {
190
195
  ${this.isMobile ? this.renderMobileSearchBar() : this.renderDesktopSearchBar()}
191
196
  </div>
192
197
  ` : html `
193
- <ft-skeleton class="ft-search-bar--skeleton" part="loader"></ft-skeleton>
198
+ <ft-skeleton class="ft-search-bar--container ft-search-bar--skeleton" part="loader"
199
+ tabindex="-1"></ft-skeleton>
194
200
  `;
195
201
  }
196
202
  renderMobileSearchBar() {
@@ -272,6 +278,7 @@ export class FtSearchBar extends FtLitElement {
272
278
  </ft-typography>
273
279
  </div>
274
280
  <ft-filter
281
+ id="ft:locale"
275
282
  part="filters filter-ft-locale"
276
283
  .exportpartsPrefixes=${["filter", "filter-ft-locale"]}
277
284
  class="ft-search-bar--content-locale"
@@ -323,7 +330,7 @@ export class FtSearchBar extends FtLitElement {
323
330
  return html `
324
331
  <div class="ft-search-bar" part="search-bar">
325
332
  ${(this.renderSearchBarLeftAction())}
326
- <div class="ft-search-bar--input-container" part="input-container">
333
+ <div class="ft-search-bar--input-container" part="input-container" tabindex="-1">
327
334
  <div class="ft-search-bar--input-outline" part="input-outline">
328
335
  ${this.dense ? this.renderSelectedFacets() : nothing}
329
336
  <input class="ft-search-bar--input ft-typography--body2"
@@ -339,6 +346,7 @@ export class FtSearchBar extends FtLitElement {
339
346
  ${this.renderDesktopSearchBarButtons()}
340
347
  ${this.forceMenuOpen ? nothing : html `
341
348
  <div class="ft-search-bar--floating-panel" @keyup=${this.onFloatingContainerKeyUp}
349
+ part="floating-panel"
342
350
  tabindex="-1">
343
351
  ${this.renderDesktopMenu()}
344
352
  </div>`}
@@ -383,7 +391,8 @@ export class FtSearchBar extends FtLitElement {
383
391
  return html `
384
392
  <ft-select outlined
385
393
  class="ft-search-bar--content-locale ft-search-bar--left-action"
386
- part="content-locale"
394
+ part="content-locale select-ft-locale"
395
+ .exportpartsPrefixes=${["content-locale", "select-ft-locale"]}
387
396
  @change=${(e) => this.contentLocale = e.detail == null ? undefined : e.detail}>
388
397
  ${repeat(this.availableContentLocales, l => l.lang, l => html `
389
398
  <ft-select-option .value=${l.lang}
@@ -462,13 +471,15 @@ export class FtSearchBar extends FtLitElement {
462
471
  part="filters-container"
463
472
  exportpartsPrefix="filters-container">
464
473
  ${this.hasLocaleSelector ? html `
465
- <ft-filter class="ft-search-bar--content-locale"
466
- part="filters filter-ft-locale"
467
- .exportpartsPrefixes=${["filter", "filter-ft-locale"]}
468
- label="${this.labelResolver.resolve("contentLocaleSelector")}"
469
- filterPlaceHolder="${this.labelResolver.resolve("filterInputPlaceHolder", this.labelResolver.resolve("contentLocaleSelector"))}"
470
- .options=${(this.contentLocalesAsFilterOptions())}
471
- @change=${(e) => this.contentLocale = e.detail[0]}
474
+ <ft-filter
475
+ id="ft:locale"
476
+ class="ft-search-bar--content-locale"
477
+ part="filters filter-ft-locale"
478
+ .exportpartsPrefixes=${["filter", "filter-ft-locale"]}
479
+ label="${this.labelResolver.resolve("contentLocaleSelector")}"
480
+ filterPlaceHolder="${this.labelResolver.resolve("filterInputPlaceHolder", this.labelResolver.resolve("contentLocaleSelector"))}"
481
+ .options=${(this.contentLocalesAsFilterOptions())}
482
+ @change=${(e) => this.contentLocale = e.detail[0]}
472
483
  ></ft-filter>
473
484
  ` : nothing}
474
485
  ${repeat(this.facets, facet => facet.key, facet => {
@@ -507,7 +518,9 @@ export class FtSearchBar extends FtLitElement {
507
518
  <ft-chip part="selected-filters selected-filter-ft-locale"
508
519
  ?dense=${this.dense && !this.isMobile}
509
520
  ?clickable=${this.isMobile}
510
- @click=${() => this.openMobileFilters("ft:contentLocale")}>
521
+ @click=${() => this.openMobileFilters("ft:contentLocale")}
522
+ data-key="ft:locale"
523
+ data-value="${this.contentLocale}">
511
524
  ${(this.getLocaleLabel(this.contentLocale))}
512
525
  </ft-chip>
513
526
  ` : null}
@@ -526,7 +539,9 @@ export class FtSearchBar extends FtLitElement {
526
539
  label="${label}"
527
540
  title=${useSnapScroll ? label : nothing}
528
541
  @click=${() => this.openMobileFilters(facet.key)}
529
- @icon-click=${() => this.setFilter(facet.key, values.filter(v => v !== value))}>
542
+ @icon-click=${() => this.setFilter(facet.key, values.filter(v => v !== value))}
543
+ data-key="${facet.key}"
544
+ data-value="${value}">
530
545
  ${getLabelFromValue(value)}
531
546
  </ft-chip>
532
547
  `;
@@ -566,9 +581,10 @@ export class FtSearchBar extends FtLitElement {
566
581
  }
567
582
  renderSuggestions() {
568
583
  const filteredRecentSearches = this.recentSearches.filter(q => q.toLowerCase().includes(this.query.toLowerCase()));
569
- const shouldDisplaySuggestions = this.query.length > 2 || filteredRecentSearches.length > 0;
584
+ const shouldDisplaySuggestions = this.suggestions.length > 0 || filteredRecentSearches.length > 0;
570
585
  return html `
571
586
  <div class="ft-search-bar--suggestions ${shouldDisplaySuggestions ? "ft-search-bar--suggestions-not-empty" : ""}"
587
+ part="suggestions-container"
572
588
  @keydown=${this.onSuggestKeyDown}>
573
589
  ${repeat(filteredRecentSearches.slice(0, 5), query => query, query => html `
574
590
  <a href="${this.searchRequestSerializer({ ...this.request, query: query })}"
@@ -599,13 +615,6 @@ export class FtSearchBar extends FtLitElement {
599
615
  <ft-typography variant="body1">${suggest.value}</ft-typography>
600
616
  </a>
601
617
  `)}
602
- ${filteredRecentSearches.length === 0 && this.suggestions.length === 0 && this.query.length > 2 && this.suggestionsLoaded
603
- ? html `
604
- <ft-typography class="ft-search-bar--no-suggestions" element="p"
605
- variant="body2">
606
- ${this.labelResolver.resolve("noSuggestions")}
607
- </ft-typography>
608
- ` : null}
609
618
  </div>
610
619
  `;
611
620
  }
@@ -639,9 +648,14 @@ export class FtSearchBar extends FtLitElement {
639
648
  async firstUpdated(props) {
640
649
  super.firstUpdated(props);
641
650
  this.initApi();
651
+ window.addEventListener("storage", (e) => {
652
+ if (e.key === this.recentSearchesStorageKey) {
653
+ this.initRecentSearches();
654
+ }
655
+ });
642
656
  }
643
657
  update(props) {
644
- var _a, _b, _c, _d, _e, _f;
658
+ var _a, _b, _c, _d, _e;
645
659
  if (props.has("labels")) {
646
660
  this.labelResolver = new ParametrizedLabelResolver(DEFAULT_LABELS, this.labels);
647
661
  }
@@ -660,13 +674,13 @@ export class FtSearchBar extends FtLitElement {
660
674
  if (this.baseUrl.endsWith("/")) {
661
675
  this.baseUrl = this.baseUrl.replace(/\/$/, "");
662
676
  }
663
- this.recentSearches = JSON.parse((_b = window.localStorage.getItem(this.recentSearchesStorageKey)) !== null && _b !== void 0 ? _b : "[]");
677
+ this.initRecentSearches();
664
678
  }
665
679
  if (props.has("presets")) {
666
- ((_c = this.presets) !== null && _c !== void 0 ? _c : []).forEach(preset => preset.filters.forEach(filter => filter.values = filter.values.map(v => unquote(v))));
680
+ ((_b = this.presets) !== null && _b !== void 0 ? _b : []).forEach(preset => preset.filters.forEach(filter => filter.values = filter.values.map(v => unquote(v))));
667
681
  }
668
682
  if (props.has("selectedPreset")) {
669
- const currentPreset = ((_d = this.presets) !== null && _d !== void 0 ? _d : []).find(p => p.name === this.selectedPreset);
683
+ const currentPreset = ((_c = this.presets) !== null && _c !== void 0 ? _c : []).find(p => p.name === this.selectedPreset);
670
684
  if (currentPreset && !this.compareRequests(this.request, currentPreset)) {
671
685
  this.setFiltersFromPreset(currentPreset);
672
686
  }
@@ -675,7 +689,7 @@ export class FtSearchBar extends FtLitElement {
675
689
  this.knownFacetLabels = new Map();
676
690
  }
677
691
  if (["contentLocale", "searchFilters"].some(p => props.has(p))) {
678
- this.selectedPreset = (_f = ((_e = this.presets) !== null && _e !== void 0 ? _e : []).find(p => this.compareRequests(p, this.request))) === null || _f === void 0 ? void 0 : _f.name;
692
+ this.selectedPreset = (_e = ((_d = this.presets) !== null && _d !== void 0 ? _d : []).find(p => this.compareRequests(p, this.request))) === null || _e === void 0 ? void 0 : _e.name;
679
693
  }
680
694
  if (["baseUrl", "apiIntegrationIdentifier"].some(p => props.has(p))) {
681
695
  this.api = undefined;
@@ -828,8 +842,22 @@ export class FtSearchBar extends FtLitElement {
828
842
  this.displayFacets = false;
829
843
  this.focus();
830
844
  }
845
+ get recentSearchesStorageKey() {
846
+ return this.baseUrl + ":ft:recent-search-queries";
847
+ }
848
+ initRecentSearches() {
849
+ var _a;
850
+ this.recentSearches = JSON.parse((_a = window.localStorage.getItem(this.recentSearchesStorageKey)) !== null && _a !== void 0 ? _a : "[]");
851
+ }
831
852
  saveRecentSearches() {
832
- window.localStorage.setItem(this.recentSearchesStorageKey, JSON.stringify(this.recentSearches));
853
+ const newValue = JSON.stringify(this.recentSearches);
854
+ window.localStorage.setItem(this.recentSearchesStorageKey, newValue);
855
+ window.dispatchEvent(new StorageEvent("storage", {
856
+ key: this.recentSearchesStorageKey,
857
+ newValue,
858
+ storageArea: window.localStorage,
859
+ url: window.location.href
860
+ }));
833
861
  }
834
862
  connectedCallback() {
835
863
  super.connectedCallback();