@fluid-topics/ft-search-selected-facets 1.2.49 → 1.2.51

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.
@@ -0,0 +1,7 @@
1
+ import { DefaultI18nMessages, I18nMessageContext, I18nMessages } from "@fluid-topics/ft-i18n";
2
+ export interface FtSearchSelectedFacetsMessages extends I18nMessages {
3
+ filterGroupLabel(): string;
4
+ removeFilterLabel(): string;
5
+ }
6
+ export declare const searchSelectedFacets: I18nMessageContext<FtSearchSelectedFacetsMessages>;
7
+ export declare const searchSelectedFacetsDefaultMessages: DefaultI18nMessages<FtSearchSelectedFacetsMessages>;
@@ -0,0 +1,6 @@
1
+ import { I18nMessageContext } from "@fluid-topics/ft-i18n";
2
+ export const searchSelectedFacets = I18nMessageContext.build("designedSearchSelectedFacets");
3
+ export const searchSelectedFacetsDefaultMessages = {
4
+ filterGroupLabel: "Filters enabled",
5
+ removeFilterLabel: "Remove filter"
6
+ };
@@ -15,6 +15,8 @@ export declare class FtSearchSelectedFacets extends FtSearchSelectedFacets_base
15
15
  constructor();
16
16
  protected render(): typeof nothing | import("lit-html").TemplateResult<1>;
17
17
  private renderFacet;
18
+ private getNextChipToFocusOn;
19
+ private determineAndApplyFocus;
18
20
  private getSelectedValues;
19
21
  private getLabelFromValue;
20
22
  private getBreadcrumbFromValue;
@@ -6,7 +6,7 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
6
6
  };
7
7
  import { html, nothing } from "lit";
8
8
  import { repeat } from "lit/directives/repeat.js";
9
- import { flatDeep, redux } from "@fluid-topics/ft-wc-utils";
9
+ import { flatDeep, FocusMainContentEvent, redux, shadowQuerySelectorAll } from "@fluid-topics/ft-wc-utils";
10
10
  import { styles } from "./ft-search-selected-facets.styles";
11
11
  import { FtSearchComponent } from "@fluid-topics/ft-search-context/build/registration";
12
12
  import { FtChip } from "@fluid-topics/ft-chip";
@@ -15,6 +15,7 @@ import { withI18n } from "@fluid-topics/ft-i18n";
15
15
  import { searchInDocumentTitlesOnlySelector } from "@fluid-topics/ft-search-context";
16
16
  import { searchTypeContext, searchTypeDefaultMessages } from "@fluid-topics/ft-search-type";
17
17
  import { periodFilterContext, periodFilterDefaultMessages } from "@fluid-topics/ft-search-period-filter";
18
+ import { searchSelectedFacets, searchSelectedFacetsDefaultMessages } from "./FtSearchSelectedFacetsMessages";
18
19
  class FtSearchSelectedFacets extends withI18n(FtSearchComponent) {
19
20
  get hasSomethingToDisplay() {
20
21
  var _a, _b;
@@ -25,6 +26,7 @@ class FtSearchSelectedFacets extends withI18n(FtSearchComponent) {
25
26
  constructor() {
26
27
  super();
27
28
  this.addI18nContext(searchTypeContext, searchTypeDefaultMessages);
29
+ this.addI18nContext(searchSelectedFacets, searchSelectedFacetsDefaultMessages);
28
30
  this.addI18nContext(periodFilterContext, periodFilterDefaultMessages);
29
31
  }
30
32
  render() {
@@ -33,7 +35,7 @@ class FtSearchSelectedFacets extends withI18n(FtSearchComponent) {
33
35
  return nothing;
34
36
  }
35
37
  return html `
36
- <div class="ft-search-selected-facets--container">
38
+ <div role="group" class="ft-search-selected-facets--container" aria-label="${searchSelectedFacets.messages.filterGroupLabel()}">
37
39
  ${repeat(this.facets || [], facet => facet.key, facet => {
38
40
  const values = this.getSelectedValues(facet);
39
41
  return repeat(values, value => facet.key + "-" + value, value => this.renderFacet(facet.key, facet.label, values, value));
@@ -54,9 +56,14 @@ class FtSearchSelectedFacets extends withI18n(FtSearchComponent) {
54
56
  part="tooltips tooltip-${keyWithNoColumn}">
55
57
  <ft-chip
56
58
  part="ft-search-selected-facets ft-search-selected-facet-${keyWithNoColumn}"
57
- removable
59
+ removable hideIconTooltip
60
+ iconLabel="${searchSelectedFacets.messages.removeFilterLabel()}"
58
61
  label="${label}"
59
- @icon-click=${() => { var _a; return (_a = this.stateManager) === null || _a === void 0 ? void 0 : _a.setValueFilter(facetKey, selectedValues.filter(v => v !== value)); }}
62
+ @icon-click=${(e) => {
63
+ var _a;
64
+ (_a = this.stateManager) === null || _a === void 0 ? void 0 : _a.setValueFilter(facetKey, selectedValues.filter(v => v !== value));
65
+ this.determineAndApplyFocus(e);
66
+ }}
60
67
  data-key="${facetKey}"
61
68
  data-value="${value}">
62
69
  ${this.getLabelFromValue(value)}
@@ -64,6 +71,32 @@ class FtSearchSelectedFacets extends withI18n(FtSearchComponent) {
64
71
  </ft-tooltip>
65
72
  `;
66
73
  }
74
+ getNextChipToFocusOn(currentChip) {
75
+ const allChips = shadowQuerySelectorAll(this.shadowRoot, "ft-chip");
76
+ const currentIndex = allChips.indexOf(currentChip);
77
+ if (currentIndex === -1 || allChips.length <= 1) {
78
+ return null;
79
+ }
80
+ // If there's a next filter, focus it
81
+ if (currentIndex < allChips.length - 1) {
82
+ return allChips[currentIndex + 1];
83
+ }
84
+ // Otherwise focus the previous filter
85
+ return allChips[currentIndex - 1];
86
+ }
87
+ determineAndApplyFocus(e) {
88
+ const chipElement = e.currentTarget;
89
+ const elementToFocus = this.getNextChipToFocusOn(chipElement);
90
+ if (elementToFocus) {
91
+ elementToFocus.elementToFocus = {
92
+ selector: `ft-button`
93
+ };
94
+ }
95
+ else {
96
+ // No chip to focus on anymore, notify to focus main content
97
+ this.dispatchEvent(new FocusMainContentEvent());
98
+ }
99
+ }
67
100
  getSelectedValues(facet) {
68
101
  return flatDeep(facet.rootNodes, n => n.selected ? [] : n.childNodes)
69
102
  .filter(n => n.selected)
@@ -87,7 +120,8 @@ class FtSearchSelectedFacets extends withI18n(FtSearchComponent) {
87
120
  part="tooltips tooltip-search-in-document-titles-only">
88
121
  <ft-chip
89
122
  part="ft-search-selected-facets ft-search-selected-facet-search-in-document-titles-only"
90
- removable
123
+ removable hideIconTooltip
124
+ iconLabel="${searchSelectedFacets.messages.removeFilterLabel()}"
91
125
  @icon-click=${() => { var _a; return (_a = this.stateManager) === null || _a === void 0 ? void 0 : _a.setSearchInDocumentTitlesOnly(false); }}>
92
126
  ${searchTypeContext.messages.documentTitlesOnly()}
93
127
  </ft-chip>
@@ -109,8 +143,13 @@ class FtSearchSelectedFacets extends withI18n(FtSearchComponent) {
109
143
  part=" tooltips tooltip-search-period-filter">
110
144
  <ft-chip
111
145
  part="ft-search-selected-facets ft-search-selected-facet-period-filter"
112
- removable
113
- @icon-click=${() => { var _a; return (_a = this.stateManager) === null || _a === void 0 ? void 0 : _a.removeDateFilter(key); }}>
146
+ removable hideIconTooltip
147
+ iconLabel="${searchSelectedFacets.messages.removeFilterLabel()}"
148
+ @icon-click=${(e) => {
149
+ var _a;
150
+ (_a = this.stateManager) === null || _a === void 0 ? void 0 : _a.removeDateFilter(key);
151
+ this.determineAndApplyFocus(e);
152
+ }}>
114
153
  ${periodFilterContext.messages[dateFilter.type]()}
115
154
  </ft-chip>
116
155
  </ft-tooltip>`;
@@ -120,8 +159,13 @@ class FtSearchSelectedFacets extends withI18n(FtSearchComponent) {
120
159
  <ft-tooltip inline text="${periodFilterContext.messages.period(periodFilterContext.messages.customPeriod(rangeFilter.from, rangeFilter.to))}" part=" tooltips tooltip-search-period-filter">
121
160
  <ft-chip
122
161
  part="ft-search-selected-facets ft-search-selected-facet-period-filter"
123
- removable
124
- @icon-click=${() => { var _a; return (_a = this.stateManager) === null || _a === void 0 ? void 0 : _a.removeRangeFilter(key); }}>
162
+ removable hideIconTooltip
163
+ iconLabel="${searchSelectedFacets.messages.removeFilterLabel()}"
164
+ @icon-click=${(e) => {
165
+ var _a;
166
+ (_a = this.stateManager) === null || _a === void 0 ? void 0 : _a.removeRangeFilter(key);
167
+ this.determineAndApplyFocus(e);
168
+ }}>
125
169
  ${periodFilterContext.messages["CUSTOM"]()}
126
170
  </ft-chip>
127
171
  </ft-tooltip>`;