@fluid-topics/ft-search-input 1.2.61 → 1.2.63
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.
- package/build/SearchInputMessages.d.ts +2 -0
- package/build/ft-search-input-suggestion.d.ts +12 -10
- package/build/ft-search-input-suggestion.js +68 -69
- package/build/ft-search-input-suggestion.styles.js +12 -2
- package/build/ft-search-input.d.ts +17 -6
- package/build/ft-search-input.js +93 -15
- package/build/ft-search-input.light.js +2844 -449
- package/build/ft-search-input.min.js +2841 -446
- package/build/ft-search-input.styles.js +7 -8
- package/package.json +10 -10
- package/build/ft-search-input-suggestion.properties.d.ts +0 -2
- package/build/ft-search-input-suggestion.properties.js +0 -1
|
@@ -3,5 +3,7 @@ export interface SearchInputMessages extends I18nMessages {
|
|
|
3
3
|
placeholder(): string;
|
|
4
4
|
searchButton(): string;
|
|
5
5
|
clearButton(): string;
|
|
6
|
+
suggestionsLabel(): string;
|
|
7
|
+
ariaLiveSuggestions(resultCount: number): string;
|
|
6
8
|
}
|
|
7
9
|
export declare const searchInputContext: I18nMessageContext<SearchInputMessages>;
|
|
@@ -1,23 +1,25 @@
|
|
|
1
1
|
import { ElementDefinitionsMap } from "@fluid-topics/ft-wc-utils";
|
|
2
|
-
import {
|
|
3
|
-
import { FtSearchComponent } from "@fluid-topics/ft-search-context/build/registration";
|
|
2
|
+
import { FtSearchInput } from "./ft-search-input";
|
|
4
3
|
export declare class SuggestionSelectedEvent extends CustomEvent<string> {
|
|
5
4
|
constructor(value: string);
|
|
6
5
|
}
|
|
7
|
-
export declare class
|
|
6
|
+
export declare class FtSearchInputSuggestionManager {
|
|
7
|
+
private ftSearchInput;
|
|
8
8
|
static elementDefinitions: ElementDefinitionsMap;
|
|
9
9
|
static styles: import("lit").CSSResult[];
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
launchSearchPath?: string;
|
|
10
|
+
constructor(ftSearchInput: FtSearchInput);
|
|
11
|
+
listboxId: string;
|
|
13
12
|
render(): import("lit-html").TemplateResult<1>;
|
|
14
13
|
private renderSuggestion;
|
|
15
|
-
private onSuggestKeyDown;
|
|
16
|
-
private onSuggestKeyUp;
|
|
17
14
|
private onSuggestSelected;
|
|
18
15
|
private getIcon;
|
|
19
|
-
|
|
16
|
+
get selectedSuggestOption(): HTMLElement | null;
|
|
20
17
|
private getLastSuggestionElement;
|
|
21
18
|
private getFirstSuggestionElement;
|
|
22
|
-
|
|
19
|
+
private nextSuggestionElement;
|
|
20
|
+
private previousSuggestionElement;
|
|
21
|
+
private selectSuggestion;
|
|
22
|
+
selectNextSuggestion(): void;
|
|
23
|
+
selectPreviousSuggestion(): void;
|
|
24
|
+
clearSelection(): void;
|
|
23
25
|
}
|
|
@@ -1,90 +1,74 @@
|
|
|
1
|
-
|
|
2
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
-
};
|
|
7
|
-
import { redux, wordWrap } from "@fluid-topics/ft-wc-utils";
|
|
1
|
+
import { wordWrap } from "@fluid-topics/ft-wc-utils";
|
|
8
2
|
import { html } from "lit";
|
|
9
|
-
import { customElement, property } from "lit/decorators.js";
|
|
10
3
|
import { suggestionStyles } from "./ft-search-input-suggestion.styles";
|
|
11
4
|
import { repeat } from "lit/directives/repeat.js";
|
|
12
5
|
import { FtIcon, FtIcons, FtIconVariants, resolveFileFormatIcon } from "@fluid-topics/ft-icon";
|
|
13
6
|
import { FtRipple } from "@fluid-topics/ft-ripple";
|
|
14
7
|
import { FtTypography } from "@fluid-topics/ft-typography";
|
|
15
|
-
import { FtSearchComponent } from "@fluid-topics/ft-search-context/build/registration";
|
|
16
8
|
import { SearchPlaceConverterProvider } from "@fluid-topics/ft-app-context";
|
|
9
|
+
import { searchInputContext } from "./SearchInputMessages";
|
|
17
10
|
export class SuggestionSelectedEvent extends CustomEvent {
|
|
18
11
|
constructor(value) {
|
|
19
12
|
super("suggestion-selected", { detail: value });
|
|
20
13
|
}
|
|
21
14
|
}
|
|
22
|
-
|
|
15
|
+
class FtSearchInputSuggestionManager {
|
|
16
|
+
constructor(ftSearchInput) {
|
|
17
|
+
this.ftSearchInput = ftSearchInput;
|
|
18
|
+
this.listboxId = "ft-search-input-suggestion";
|
|
19
|
+
}
|
|
23
20
|
render() {
|
|
24
21
|
const searchPlaceConverter = SearchPlaceConverterProvider.get();
|
|
25
22
|
return html `
|
|
26
23
|
<div class="ft-search-input-suggestion ft-word-wrap"
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
24
|
+
id="${this.listboxId}"
|
|
25
|
+
role="listbox"
|
|
26
|
+
aria-label="${searchInputContext.messages.suggestionsLabel()}"
|
|
27
|
+
part="container">
|
|
28
|
+
${repeat(this.ftSearchInput.suggestResults || [], suggest => suggest.value, (suggest, index) => {
|
|
29
|
+
return this.renderSuggestion(index, suggest, searchPlaceConverter);
|
|
31
30
|
})}
|
|
32
31
|
</div>
|
|
33
32
|
`;
|
|
34
33
|
}
|
|
35
|
-
renderSuggestion(suggest, searchPlaceConverter) {
|
|
34
|
+
renderSuggestion(index, suggest, searchPlaceConverter) {
|
|
35
|
+
const id = `suggestion-${index}`;
|
|
36
36
|
const content = html `
|
|
37
|
-
<ft-ripple></ft-ripple>
|
|
37
|
+
<ft-ripple ?activated=${this.ftSearchInput.selectedSuggestOptionId === id}></ft-ripple>
|
|
38
38
|
${this.getIcon(suggest)}
|
|
39
39
|
<ft-typography variant="body1">${suggest.value}</ft-typography>
|
|
40
40
|
`;
|
|
41
|
-
if (this.launchSearchPath) {
|
|
42
|
-
const suggestRequest = { ...this.request, query: suggest.value };
|
|
43
|
-
const launchSuggestUrl = searchPlaceConverter.serializeToCurrentPageIfPossible(suggestRequest, this.launchSearchPath);
|
|
41
|
+
if (this.ftSearchInput.launchSearchPath) {
|
|
42
|
+
const suggestRequest = { ...this.ftSearchInput.request, query: suggest.value };
|
|
43
|
+
const launchSuggestUrl = searchPlaceConverter.serializeToCurrentPageIfPossible(suggestRequest, this.ftSearchInput.launchSearchPath);
|
|
44
44
|
return html `
|
|
45
45
|
<a href="${launchSuggestUrl}"
|
|
46
46
|
part="suggestion"
|
|
47
47
|
class="ft-search-input-suggestion--suggestion"
|
|
48
|
-
|
|
48
|
+
role="option"
|
|
49
|
+
id="${id}"
|
|
50
|
+
aria-selected="${this.ftSearchInput.selectedSuggestOptionId === id}"
|
|
51
|
+
tabindex="-1"
|
|
52
|
+
aria-label="${content}"
|
|
49
53
|
@click=${() => this.onSuggestSelected(suggest.value)}>
|
|
50
54
|
${content}
|
|
51
55
|
</a>
|
|
52
56
|
`;
|
|
53
57
|
}
|
|
54
58
|
return html `
|
|
55
|
-
<div
|
|
56
|
-
part="suggestion"
|
|
59
|
+
<div part="suggestion"
|
|
57
60
|
class="ft-search-input-suggestion--suggestion"
|
|
58
|
-
|
|
61
|
+
role="option"
|
|
62
|
+
id="${id}"
|
|
63
|
+
aria-selected="${this.ftSearchInput.selectedSuggestOptionId === id}"
|
|
64
|
+
tabindex="-1"
|
|
59
65
|
@click=${() => this.onSuggestSelected(suggest.value)}>
|
|
60
66
|
${content}
|
|
61
67
|
</div>
|
|
62
68
|
`;
|
|
63
69
|
}
|
|
64
|
-
onSuggestKeyDown(e) {
|
|
65
|
-
var _a, _b, _c, _d, _e, _f;
|
|
66
|
-
switch (e.key) {
|
|
67
|
-
case "ArrowUp":
|
|
68
|
-
(_c = ((_b = (_a = this.getFocusedSuggestionElement()) === null || _a === void 0 ? void 0 : _a.previousElementSibling) !== null && _b !== void 0 ? _b : this.getLastSuggestionElement())) === null || _c === void 0 ? void 0 : _c.focus();
|
|
69
|
-
e.preventDefault();
|
|
70
|
-
e.stopPropagation();
|
|
71
|
-
break;
|
|
72
|
-
case "ArrowDown":
|
|
73
|
-
(_f = ((_e = (_d = this.getFocusedSuggestionElement()) === null || _d === void 0 ? void 0 : _d.nextElementSibling) !== null && _e !== void 0 ? _e : this.getFirstSuggestionElement())) === null || _f === void 0 ? void 0 : _f.focus();
|
|
74
|
-
e.preventDefault();
|
|
75
|
-
e.stopPropagation();
|
|
76
|
-
break;
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
onSuggestKeyUp(e) {
|
|
80
|
-
if (e.key === "Enter" || e.key === " ") {
|
|
81
|
-
e.preventDefault();
|
|
82
|
-
e.stopPropagation();
|
|
83
|
-
e.target.click();
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
70
|
onSuggestSelected(suggest) {
|
|
87
|
-
this.
|
|
71
|
+
this.ftSearchInput.onSuggestionSelected(suggest);
|
|
88
72
|
}
|
|
89
73
|
getIcon(suggest) {
|
|
90
74
|
const iconVariant = suggest.type === "DOCUMENT" ? FtIconVariants.file_format : FtIconVariants.fluid_topics;
|
|
@@ -104,40 +88,55 @@ let FtSearchInputSuggestion = class FtSearchInputSuggestion extends FtSearchComp
|
|
|
104
88
|
<ft-icon .variant="${iconVariant}" .value="${icon}" part="suggestion-icon"></ft-icon>
|
|
105
89
|
`;
|
|
106
90
|
}
|
|
107
|
-
|
|
108
|
-
return this.shadowRoot.querySelector(
|
|
91
|
+
get selectedSuggestOption() {
|
|
92
|
+
return this.ftSearchInput.shadowRoot.querySelector(`#${this.ftSearchInput.selectedSuggestOptionId}`);
|
|
109
93
|
}
|
|
110
94
|
getLastSuggestionElement() {
|
|
111
|
-
let suggestions = this.shadowRoot.querySelectorAll("
|
|
95
|
+
let suggestions = this.ftSearchInput.shadowRoot.querySelectorAll("[role=option]");
|
|
112
96
|
return suggestions.length > 0 ? suggestions[suggestions.length - 1] : null;
|
|
113
97
|
}
|
|
114
98
|
getFirstSuggestionElement() {
|
|
115
|
-
return this.shadowRoot.querySelector("
|
|
99
|
+
return this.ftSearchInput.shadowRoot.querySelector("[role=option]");
|
|
116
100
|
}
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
101
|
+
nextSuggestionElement() {
|
|
102
|
+
const divElement = this.selectedSuggestOption;
|
|
103
|
+
if (!divElement) {
|
|
104
|
+
return this.getFirstSuggestionElement();
|
|
105
|
+
}
|
|
106
|
+
return divElement === null || divElement === void 0 ? void 0 : divElement.nextElementSibling;
|
|
120
107
|
}
|
|
121
|
-
|
|
122
|
-
|
|
108
|
+
previousSuggestionElement() {
|
|
109
|
+
const divElement = this.selectedSuggestOption;
|
|
110
|
+
if (!divElement) {
|
|
111
|
+
return this.getLastSuggestionElement();
|
|
112
|
+
}
|
|
113
|
+
return divElement === null || divElement === void 0 ? void 0 : divElement.previousElementSibling;
|
|
114
|
+
}
|
|
115
|
+
selectSuggestion(element) {
|
|
116
|
+
if (element) {
|
|
117
|
+
this.ftSearchInput.selectedSuggestOptionId = element.id;
|
|
118
|
+
}
|
|
119
|
+
else {
|
|
120
|
+
this.ftSearchInput.selectedSuggestOptionId = undefined;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
selectNextSuggestion() {
|
|
124
|
+
this.selectSuggestion(this.nextSuggestionElement());
|
|
125
|
+
}
|
|
126
|
+
selectPreviousSuggestion() {
|
|
127
|
+
this.selectSuggestion(this.previousSuggestionElement());
|
|
128
|
+
}
|
|
129
|
+
clearSelection() {
|
|
130
|
+
this.selectSuggestion(null);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
FtSearchInputSuggestionManager.elementDefinitions = {
|
|
123
134
|
"ft-ripple": FtRipple,
|
|
124
135
|
"ft-typography": FtTypography,
|
|
125
136
|
"ft-icon": FtIcon,
|
|
126
137
|
};
|
|
127
|
-
|
|
138
|
+
FtSearchInputSuggestionManager.styles = [
|
|
128
139
|
wordWrap,
|
|
129
140
|
suggestionStyles,
|
|
130
141
|
];
|
|
131
|
-
|
|
132
|
-
redux()
|
|
133
|
-
], FtSearchInputSuggestion.prototype, "request", void 0);
|
|
134
|
-
__decorate([
|
|
135
|
-
redux()
|
|
136
|
-
], FtSearchInputSuggestion.prototype, "suggestResults", void 0);
|
|
137
|
-
__decorate([
|
|
138
|
-
property()
|
|
139
|
-
], FtSearchInputSuggestion.prototype, "launchSearchPath", void 0);
|
|
140
|
-
FtSearchInputSuggestion = __decorate([
|
|
141
|
-
customElement("ft-search-input-suggestion")
|
|
142
|
-
], FtSearchInputSuggestion);
|
|
143
|
-
export { FtSearchInputSuggestion };
|
|
142
|
+
export { FtSearchInputSuggestionManager };
|
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
import { css } from "lit";
|
|
2
2
|
import { FtSearchInputCssVariables } from "./ft-search-input.styles";
|
|
3
|
+
import { setVariable } from "@fluid-topics/ft-wc-utils";
|
|
4
|
+
import { FtRippleCssVariables } from "@fluid-topics/ft-ripple";
|
|
5
|
+
import { FtSearchBarCssVariables } from "@fluid-topics/ft-search-bar";
|
|
3
6
|
// language=CSS
|
|
4
7
|
export const suggestionStyles = css `
|
|
5
8
|
* {
|
|
6
9
|
box-sizing: border-box;
|
|
7
10
|
}
|
|
8
|
-
|
|
11
|
+
|
|
9
12
|
.ft-search-input-suggestion {
|
|
10
13
|
position: absolute;
|
|
11
14
|
z-index: ${FtSearchInputCssVariables.floatingZIndex};
|
|
@@ -34,8 +37,11 @@ export const suggestionStyles = css `
|
|
|
34
37
|
position: relative;
|
|
35
38
|
}
|
|
36
39
|
|
|
37
|
-
.ft-search-input-suggestion--suggestion
|
|
40
|
+
.ft-search-input-suggestion--suggestion[aria-selected="true"],
|
|
41
|
+
.ft-search-input-suggestion--suggestion:hover {
|
|
38
42
|
outline: none;
|
|
43
|
+
box-shadow: inset 3px 0 0 ${FtSearchBarCssVariables.activeItemBorderColor};
|
|
44
|
+
|
|
39
45
|
}
|
|
40
46
|
|
|
41
47
|
.ft-search-input-suggestion--suggestion ft-typography {
|
|
@@ -43,4 +49,8 @@ export const suggestionStyles = css `
|
|
|
43
49
|
flex-grow: 1;
|
|
44
50
|
flex-shrink: 1;
|
|
45
51
|
}
|
|
52
|
+
|
|
53
|
+
ft-ripple {
|
|
54
|
+
${setVariable(FtRippleCssVariables.opacityContentOnSurfaceHover, FtRippleCssVariables.opacityContentOnSurfaceSelected)}
|
|
55
|
+
}
|
|
46
56
|
`;
|
|
@@ -1,27 +1,38 @@
|
|
|
1
1
|
import { ElementDefinitionsMap } from "@fluid-topics/ft-wc-utils";
|
|
2
2
|
import { FtSearchInputProperties } from "./ft-search-input.properties";
|
|
3
3
|
import { FtSearchComponent } from "@fluid-topics/ft-search-context/build/registration";
|
|
4
|
+
import { FtSearchRequest, FtSuggestResult } from "@fluid-topics/public-api";
|
|
5
|
+
import { FtSearchInputSuggestionManager } from "./ft-search-input-suggestion";
|
|
4
6
|
declare const FtSearchInput_base: typeof FtSearchComponent & import("@fluid-topics/ft-wc-utils").Constructor<import("@fluid-topics/ft-i18n").FtLitElementWithI18nInterface>;
|
|
5
7
|
export declare class FtSearchInput extends FtSearchInput_base implements FtSearchInputProperties {
|
|
6
8
|
static elementDefinitions: ElementDefinitionsMap;
|
|
7
9
|
static styles: import("lit").CSSResult[];
|
|
8
10
|
constructor();
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
11
|
+
request?: FtSearchRequest;
|
|
12
|
+
liveQuery: string;
|
|
13
|
+
suggestResults?: Array<FtSuggestResult>;
|
|
12
14
|
private forceCloseSuggestion;
|
|
15
|
+
displaySuggestListbox: boolean;
|
|
16
|
+
selectedSuggestOptionId?: string;
|
|
13
17
|
launchSearchPath?: string;
|
|
14
18
|
useCustomSearchPath: boolean;
|
|
15
19
|
triggerSearchOnClear: boolean;
|
|
16
|
-
|
|
17
|
-
private suggestion;
|
|
20
|
+
input: HTMLInputElement;
|
|
18
21
|
private launchSearchButton;
|
|
22
|
+
suggestions: FtSearchInputSuggestionManager;
|
|
19
23
|
protected render(): import("lit-html").TemplateResult<1>;
|
|
24
|
+
private renderLiveText;
|
|
20
25
|
private onSearchBarKeyDown;
|
|
21
26
|
private onSearchBarKeyUp;
|
|
22
27
|
private onInput;
|
|
23
28
|
private onClearInput;
|
|
24
29
|
private launchSearch;
|
|
25
|
-
|
|
30
|
+
onSuggestionSelected(value: string): void;
|
|
31
|
+
get shouldDisplaySuggestions(): boolean;
|
|
32
|
+
private onClick;
|
|
33
|
+
private onFocus;
|
|
34
|
+
connectedCallback(): Promise<void>;
|
|
35
|
+
disconnectedCallback(): void;
|
|
36
|
+
private closeSuggestListbox;
|
|
26
37
|
}
|
|
27
38
|
export {};
|
package/build/ft-search-input.js
CHANGED
|
@@ -12,7 +12,7 @@ import { withI18n } from "@fluid-topics/ft-i18n";
|
|
|
12
12
|
import { searchInputContext } from "./SearchInputMessages";
|
|
13
13
|
import { property, query, state } from "lit/decorators.js";
|
|
14
14
|
import { classMap } from "lit/directives/class-map.js";
|
|
15
|
-
import {
|
|
15
|
+
import { FtSearchInputSuggestionManager } from "./ft-search-input-suggestion";
|
|
16
16
|
import { FtButton } from "@fluid-topics/ft-button";
|
|
17
17
|
import { FtTypographyBody2 } from "@fluid-topics/ft-typography";
|
|
18
18
|
import { SearchPlaceConverterProvider } from "@fluid-topics/ft-app-context";
|
|
@@ -21,12 +21,22 @@ class FtSearchInput extends withI18n(FtSearchComponent) {
|
|
|
21
21
|
super();
|
|
22
22
|
this.liveQuery = "";
|
|
23
23
|
this.forceCloseSuggestion = false;
|
|
24
|
+
this.displaySuggestListbox = false;
|
|
24
25
|
this.useCustomSearchPath = false;
|
|
25
26
|
this.triggerSearchOnClear = false;
|
|
27
|
+
this.suggestions = new FtSearchInputSuggestionManager(this);
|
|
28
|
+
this.closeSuggestListbox = (e) => {
|
|
29
|
+
const path = e.composedPath();
|
|
30
|
+
const inside = path.some(n => n === this || n === this.shadowRoot);
|
|
31
|
+
if (!inside) {
|
|
32
|
+
this.displaySuggestListbox = false;
|
|
33
|
+
this.selectedSuggestOptionId = undefined;
|
|
34
|
+
}
|
|
35
|
+
};
|
|
26
36
|
this.addI18nContext(searchInputContext);
|
|
27
37
|
}
|
|
28
38
|
render() {
|
|
29
|
-
var _a, _b;
|
|
39
|
+
var _a, _b, _c;
|
|
30
40
|
let classes = {
|
|
31
41
|
"ft-search-input": true,
|
|
32
42
|
"ft-search-input--with-suggestions": (_b = (_a = this.suggestResults) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0 > 0,
|
|
@@ -44,15 +54,21 @@ class FtSearchInput extends withI18n(FtSearchComponent) {
|
|
|
44
54
|
type="search"
|
|
45
55
|
placeholder="${searchInputContext.messages.placeholder()}"
|
|
46
56
|
.value="${this.liveQuery}"
|
|
57
|
+
role="combobox"
|
|
58
|
+
aria-autocomplete="list"
|
|
59
|
+
aria-controls="${this.suggestions.listboxId}"
|
|
60
|
+
aria-expanded="${this.displaySuggestListbox}"
|
|
61
|
+
aria-activedescendant="${(_c = this.selectedSuggestOptionId) !== null && _c !== void 0 ? _c : nothing}"
|
|
47
62
|
@input=${(e) => this.onInput(e)}
|
|
63
|
+
@click="${() => this.onClick()}"
|
|
64
|
+
@focus="${() => this.onFocus()}"
|
|
48
65
|
@keydown=${(e) => this.onSearchBarKeyDown(e)}
|
|
49
66
|
@keyup=${(e) => this.onSearchBarKeyUp(e)}>
|
|
50
67
|
</div>
|
|
51
|
-
<ft-search-input-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
></ft-search-input-suggestion>
|
|
68
|
+
<div class="ft-search-input--aria-live" aria-live="polite" aria-atomic="true">
|
|
69
|
+
${this.renderLiveText()}
|
|
70
|
+
</div>
|
|
71
|
+
${this.shouldDisplaySuggestions ? this.suggestions.render() : nothing}
|
|
56
72
|
</div>
|
|
57
73
|
<div class="ft-search-input--actions" part="actions">
|
|
58
74
|
${this.liveQuery ? html `
|
|
@@ -78,12 +94,52 @@ class FtSearchInput extends withI18n(FtSearchComponent) {
|
|
|
78
94
|
</div>
|
|
79
95
|
`;
|
|
80
96
|
}
|
|
97
|
+
renderLiveText() {
|
|
98
|
+
if (this.shouldDisplaySuggestions) {
|
|
99
|
+
return searchInputContext.messages.ariaLiveSuggestions(this.suggestResults.length);
|
|
100
|
+
}
|
|
101
|
+
else {
|
|
102
|
+
return "";
|
|
103
|
+
}
|
|
104
|
+
}
|
|
81
105
|
onSearchBarKeyDown(e) {
|
|
106
|
+
if (!["Escape", "Tab", "Shift"].includes(e.key)) {
|
|
107
|
+
this.displaySuggestListbox = true;
|
|
108
|
+
}
|
|
82
109
|
switch (e.key) {
|
|
110
|
+
case "Tab":
|
|
111
|
+
this.displaySuggestListbox = false;
|
|
112
|
+
this.selectedSuggestOptionId = undefined;
|
|
113
|
+
break;
|
|
114
|
+
case "Escape":
|
|
115
|
+
if (this.shouldDisplaySuggestions) {
|
|
116
|
+
e.stopPropagation();
|
|
117
|
+
e.preventDefault();
|
|
118
|
+
this.displaySuggestListbox = false;
|
|
119
|
+
this.selectedSuggestOptionId = undefined;
|
|
120
|
+
}
|
|
121
|
+
break;
|
|
83
122
|
case "ArrowDown":
|
|
84
123
|
e.stopPropagation();
|
|
85
124
|
e.preventDefault();
|
|
86
|
-
this.
|
|
125
|
+
this.suggestions.selectNextSuggestion();
|
|
126
|
+
break;
|
|
127
|
+
case "ArrowUp":
|
|
128
|
+
e.stopPropagation();
|
|
129
|
+
e.preventDefault();
|
|
130
|
+
this.suggestions.selectPreviousSuggestion();
|
|
131
|
+
break;
|
|
132
|
+
case "ArrowLeft":
|
|
133
|
+
case "ArrowRight":
|
|
134
|
+
if (this.selectedSuggestOptionId) {
|
|
135
|
+
e.stopPropagation();
|
|
136
|
+
e.preventDefault();
|
|
137
|
+
this.suggestions.clearSelection();
|
|
138
|
+
}
|
|
139
|
+
break;
|
|
140
|
+
case "Enter":
|
|
141
|
+
const elementToClick = this.suggestions.selectedSuggestOption || this.launchSearchButton;
|
|
142
|
+
elementToClick === null || elementToClick === void 0 ? void 0 : elementToClick.click();
|
|
87
143
|
break;
|
|
88
144
|
case "Backspace":
|
|
89
145
|
e.stopPropagation();
|
|
@@ -124,20 +180,39 @@ class FtSearchInput extends withI18n(FtSearchComponent) {
|
|
|
124
180
|
this.dispatchEvent(new CustomEvent("change", { detail: query }));
|
|
125
181
|
(_a = this.stateManager) === null || _a === void 0 ? void 0 : _a.setQuery(query);
|
|
126
182
|
}
|
|
127
|
-
onSuggestionSelected(
|
|
183
|
+
onSuggestionSelected(value) {
|
|
184
|
+
this.launchSearch(value);
|
|
185
|
+
this.displaySuggestListbox = false;
|
|
186
|
+
this.suggestions.clearSelection();
|
|
187
|
+
}
|
|
188
|
+
get shouldDisplaySuggestions() {
|
|
128
189
|
var _a;
|
|
129
|
-
(_a = this.
|
|
130
|
-
|
|
190
|
+
return this.displaySuggestListbox && ((_a = this.suggestResults) !== null && _a !== void 0 ? _a : []).length > 0;
|
|
191
|
+
}
|
|
192
|
+
onClick() {
|
|
193
|
+
this.onFocus();
|
|
194
|
+
}
|
|
195
|
+
onFocus() {
|
|
196
|
+
this.displaySuggestListbox = true;
|
|
197
|
+
}
|
|
198
|
+
async connectedCallback() {
|
|
199
|
+
super.connectedCallback();
|
|
200
|
+
document.addEventListener("pointerdown", this.closeSuggestListbox);
|
|
201
|
+
}
|
|
202
|
+
disconnectedCallback() {
|
|
203
|
+
super.disconnectedCallback();
|
|
204
|
+
document.removeEventListener("pointerdown", this.closeSuggestListbox);
|
|
131
205
|
}
|
|
132
206
|
}
|
|
133
207
|
FtSearchInput.elementDefinitions = {
|
|
134
|
-
"ft-search-input-suggestion": FtSearchInputSuggestion,
|
|
135
208
|
"ft-button": FtButton,
|
|
209
|
+
...FtSearchInputSuggestionManager.elementDefinitions,
|
|
136
210
|
};
|
|
137
211
|
FtSearchInput.styles = [
|
|
138
212
|
FtTypographyBody2,
|
|
139
213
|
noTextInputDefaultClearButton,
|
|
140
214
|
styles,
|
|
215
|
+
...FtSearchInputSuggestionManager.styles,
|
|
141
216
|
];
|
|
142
217
|
__decorate([
|
|
143
218
|
redux()
|
|
@@ -151,6 +226,12 @@ __decorate([
|
|
|
151
226
|
__decorate([
|
|
152
227
|
state()
|
|
153
228
|
], FtSearchInput.prototype, "forceCloseSuggestion", void 0);
|
|
229
|
+
__decorate([
|
|
230
|
+
state()
|
|
231
|
+
], FtSearchInput.prototype, "displaySuggestListbox", void 0);
|
|
232
|
+
__decorate([
|
|
233
|
+
state()
|
|
234
|
+
], FtSearchInput.prototype, "selectedSuggestOptionId", void 0);
|
|
154
235
|
__decorate([
|
|
155
236
|
property()
|
|
156
237
|
], FtSearchInput.prototype, "launchSearchPath", void 0);
|
|
@@ -163,9 +244,6 @@ __decorate([
|
|
|
163
244
|
__decorate([
|
|
164
245
|
query(".ft-search-input--input")
|
|
165
246
|
], FtSearchInput.prototype, "input", void 0);
|
|
166
|
-
__decorate([
|
|
167
|
-
query("ft-search-input-suggestion")
|
|
168
|
-
], FtSearchInput.prototype, "suggestion", void 0);
|
|
169
247
|
__decorate([
|
|
170
248
|
query(`[part="launch-search-in-input"]`)
|
|
171
249
|
], FtSearchInput.prototype, "launchSearchButton", void 0);
|