@fluid-topics/ft-select 1.2.64 → 1.2.65
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/ft-select.d.ts +5 -0
- package/build/ft-select.js +48 -5
- package/build/ft-select.light.js +71 -69
- package/build/ft-select.min.js +36 -34
- package/build/ft-select.styles.js +1 -1
- package/package.json +7 -7
package/build/ft-select.d.ts
CHANGED
|
@@ -11,6 +11,7 @@ export declare class FtSelectOption extends FtLitElement implements FtSelectOpti
|
|
|
11
11
|
}
|
|
12
12
|
export declare class FtSelect extends FtLitElement implements FtSelectProperties {
|
|
13
13
|
static elementDefinitions: ElementDefinitionsMap;
|
|
14
|
+
static searchTimeoutMilliseconds: number;
|
|
14
15
|
static styles: import("lit").CSSResult[];
|
|
15
16
|
label: string;
|
|
16
17
|
ariaLabel: string;
|
|
@@ -23,6 +24,8 @@ export declare class FtSelect extends FtLitElement implements FtSelectProperties
|
|
|
23
24
|
selectedOption?: FtSelectOptionProperties;
|
|
24
25
|
private optionsDisplayed;
|
|
25
26
|
private focusOptions;
|
|
27
|
+
private currentSearch;
|
|
28
|
+
private lastSearchInputDate;
|
|
26
29
|
private container?;
|
|
27
30
|
private optionsMenu?;
|
|
28
31
|
private mainPanel;
|
|
@@ -40,6 +43,8 @@ export declare class FtSelect extends FtLitElement implements FtSelectProperties
|
|
|
40
43
|
private updateOptionsFromSlot;
|
|
41
44
|
private onMainPanelKeyDown;
|
|
42
45
|
private onOptionsKeyDown;
|
|
46
|
+
private isKeyAlphanumeric;
|
|
47
|
+
private handleAlphanumericPress;
|
|
43
48
|
private onOptionKeyDown;
|
|
44
49
|
private selectOption;
|
|
45
50
|
private hideOptions;
|
package/build/ft-select.js
CHANGED
|
@@ -4,7 +4,7 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
4
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
5
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
6
|
};
|
|
7
|
-
import { html } from "lit";
|
|
7
|
+
import { html, nothing } from "lit";
|
|
8
8
|
import { property, query, state } from "lit/decorators.js";
|
|
9
9
|
import { classMap } from "lit/directives/class-map.js";
|
|
10
10
|
import { repeat } from "lit/directives/repeat.js";
|
|
@@ -53,6 +53,8 @@ class FtSelect extends FtLitElement {
|
|
|
53
53
|
this.options = [];
|
|
54
54
|
this.optionsDisplayed = false;
|
|
55
55
|
this.focusOptions = false;
|
|
56
|
+
this.currentSearch = "";
|
|
57
|
+
this.lastSearchInputDate = new Date("01/01/1970");
|
|
56
58
|
this.hideOptions = (e) => this.optionsDisplayed = this.optionsDisplayed && e.composedPath().includes(this.container);
|
|
57
59
|
}
|
|
58
60
|
render() {
|
|
@@ -106,9 +108,11 @@ class FtSelect extends FtLitElement {
|
|
|
106
108
|
${repeat(this.options, option => option.value, option => this.renderOption(option))}
|
|
107
109
|
</div>
|
|
108
110
|
</div>
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
111
|
+
<slot name="helper" part="helper">
|
|
112
|
+
${this.helper ? html `
|
|
113
|
+
<ft-typography class="ft-select--helper-text" variant="caption">${this.helper}
|
|
114
|
+
</ft-typography>` : nothing}
|
|
115
|
+
</slot>
|
|
112
116
|
</div>
|
|
113
117
|
<slot @slotchange=${this.updateOptionsFromSlot}
|
|
114
118
|
@option-change=${this.updateOptionsFromSlot}
|
|
@@ -215,9 +219,41 @@ class FtSelect extends FtLitElement {
|
|
|
215
219
|
e.stopPropagation();
|
|
216
220
|
optionToFocus = (_e = (_d = this.focusedOption) === null || _d === void 0 ? void 0 : _d.nextElementSibling) !== null && _e !== void 0 ? _e : this.firstOption;
|
|
217
221
|
break;
|
|
222
|
+
default:
|
|
223
|
+
if (e.key.length != 1) {
|
|
224
|
+
break;
|
|
225
|
+
}
|
|
226
|
+
if (this.isKeyAlphanumeric(e.key)) {
|
|
227
|
+
optionToFocus = this.handleAlphanumericPress(e.key);
|
|
228
|
+
}
|
|
229
|
+
break;
|
|
218
230
|
}
|
|
219
231
|
optionToFocus === null || optionToFocus === void 0 ? void 0 : optionToFocus.focus();
|
|
220
232
|
}
|
|
233
|
+
isKeyAlphanumeric(key) {
|
|
234
|
+
let charCode = key.charCodeAt(0);
|
|
235
|
+
return (charCode > 47 && charCode < 58) || // numeric (0-9)
|
|
236
|
+
(charCode > 64 && charCode < 91) || // upper alpha (A-Z)
|
|
237
|
+
(charCode > 96 && charCode < 123); // lower alpha (a-z)
|
|
238
|
+
}
|
|
239
|
+
handleAlphanumericPress(c) {
|
|
240
|
+
var _a, _b;
|
|
241
|
+
let currentDate = new Date();
|
|
242
|
+
// Resetting current search if timeout elapsed
|
|
243
|
+
if (currentDate.getTime() - this.lastSearchInputDate.getTime() > FtSelect.searchTimeoutMilliseconds) {
|
|
244
|
+
this.currentSearch = "";
|
|
245
|
+
}
|
|
246
|
+
this.currentSearch += c.toLowerCase();
|
|
247
|
+
// Searching for option
|
|
248
|
+
let foundOption = this.options.find((opt) => { var _a; return ((_a = opt.label) === null || _a === void 0 ? void 0 : _a.toLowerCase().substring(0, this.currentSearch.length)) === this.currentSearch; });
|
|
249
|
+
if (foundOption === undefined) {
|
|
250
|
+
this.lastSearchInputDate = currentDate;
|
|
251
|
+
return undefined;
|
|
252
|
+
}
|
|
253
|
+
let optionElement = (_b = (_a = this.optionsMenu) === null || _a === void 0 ? void 0 : _a.querySelector(`[data-value="${foundOption.value}"]`)) !== null && _b !== void 0 ? _b : undefined;
|
|
254
|
+
this.lastSearchInputDate = currentDate;
|
|
255
|
+
return optionElement;
|
|
256
|
+
}
|
|
221
257
|
onOptionKeyDown(e, option) {
|
|
222
258
|
var _a;
|
|
223
259
|
if (e.key === "Enter" || e.key === " ") {
|
|
@@ -254,6 +290,7 @@ FtSelect.elementDefinitions = {
|
|
|
254
290
|
"ft-ripple": FtRipple,
|
|
255
291
|
"ft-icon": FtIcon,
|
|
256
292
|
};
|
|
293
|
+
FtSelect.searchTimeoutMilliseconds = 2000;
|
|
257
294
|
FtSelect.styles = [
|
|
258
295
|
FtTypographyBody2,
|
|
259
296
|
FtTypographyCaption,
|
|
@@ -292,6 +329,12 @@ __decorate([
|
|
|
292
329
|
__decorate([
|
|
293
330
|
state()
|
|
294
331
|
], FtSelect.prototype, "focusOptions", void 0);
|
|
332
|
+
__decorate([
|
|
333
|
+
state()
|
|
334
|
+
], FtSelect.prototype, "currentSearch", void 0);
|
|
335
|
+
__decorate([
|
|
336
|
+
state()
|
|
337
|
+
], FtSelect.prototype, "lastSearchInputDate", void 0);
|
|
295
338
|
__decorate([
|
|
296
339
|
query(".ft-select")
|
|
297
340
|
], FtSelect.prototype, "container", void 0);
|
|
@@ -314,6 +357,6 @@ __decorate([
|
|
|
314
357
|
query(".ft-select--option:last-child")
|
|
315
358
|
], FtSelect.prototype, "lastOption", void 0);
|
|
316
359
|
__decorate([
|
|
317
|
-
query("slot")
|
|
360
|
+
query("slot:not([name])")
|
|
318
361
|
], FtSelect.prototype, "optionsSlot", void 0);
|
|
319
362
|
export { FtSelect };
|