@exmg/exm-search 1.0.1 → 1.0.3
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/package.json +3 -3
- package/src/exm-search-base.d.ts +6 -2
- package/src/exm-search-base.js +25 -10
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@exmg/exm-search",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.3",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"module": "index.js",
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
},
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@exmg/lit-base": "^2.0.1",
|
|
13
|
-
"@material/web": "^
|
|
13
|
+
"@material/web": "^2.2.0",
|
|
14
14
|
"lit": "^3.0.0",
|
|
15
15
|
"tslib": "^2.6.2"
|
|
16
16
|
},
|
|
@@ -40,5 +40,5 @@
|
|
|
40
40
|
"publishConfig": {
|
|
41
41
|
"access": "public"
|
|
42
42
|
},
|
|
43
|
-
"gitHead": "
|
|
43
|
+
"gitHead": "274f2fb879258487017192fcfe33c8cd23244dbb"
|
|
44
44
|
}
|
package/src/exm-search-base.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { ExmgElement } from '@exmg/lit-base';
|
|
2
|
+
import { PropertyValues } from 'lit';
|
|
2
3
|
import '@material/web/icon/icon.js';
|
|
3
4
|
import '@material/web/iconbutton/icon-button.js';
|
|
4
5
|
import '@material/web/focus/md-focus-ring.js';
|
|
@@ -8,14 +9,17 @@ export declare class ExmSearchBase extends ExmgElement {
|
|
|
8
9
|
filterValue?: string | null;
|
|
9
10
|
placeHolder: string;
|
|
10
11
|
search?: HTMLInputElement;
|
|
12
|
+
detectOutsideBind?: (e: Event) => void;
|
|
11
13
|
constructor();
|
|
12
14
|
protected fire<T>(eventName: string, detail?: T, bubbles?: boolean): void;
|
|
13
15
|
focus(): void;
|
|
16
|
+
protected firstUpdated(_changedProperties: PropertyValues): void;
|
|
17
|
+
disconnectedCallback(): void;
|
|
18
|
+
detectOutsideClick(e: Event): void;
|
|
14
19
|
render(): import("lit-html").TemplateResult<1>;
|
|
15
20
|
_getValue(): string;
|
|
16
21
|
_notifyChange(): void;
|
|
17
|
-
_handleClear(e:
|
|
22
|
+
_handleClear(e: Event): void;
|
|
18
23
|
_handleKeyUp(e: KeyboardEvent): void;
|
|
19
|
-
_handleInputBlur(): void;
|
|
20
24
|
updated(changedProperties: Map<string, any>): void;
|
|
21
25
|
}
|
package/src/exm-search-base.js
CHANGED
|
@@ -15,10 +15,6 @@ export class ExmSearchBase extends ExmgElement {
|
|
|
15
15
|
// Set default tabindex to 0
|
|
16
16
|
const tabindex = this.getAttribute('tabindex');
|
|
17
17
|
this.setAttribute('tabindex', tabindex || '0');
|
|
18
|
-
// Add focus event listener to focus input
|
|
19
|
-
this.addEventListener('focus', () => {
|
|
20
|
-
this.focus();
|
|
21
|
-
});
|
|
22
18
|
}
|
|
23
19
|
fire(eventName, detail, bubbles) {
|
|
24
20
|
this.dispatchEvent(new CustomEvent(eventName, {
|
|
@@ -30,13 +26,33 @@ export class ExmSearchBase extends ExmgElement {
|
|
|
30
26
|
focus() {
|
|
31
27
|
this._hasFocus = true;
|
|
32
28
|
}
|
|
29
|
+
firstUpdated(_changedProperties) {
|
|
30
|
+
this.detectOutsideBind = this.detectOutsideClick.bind(this);
|
|
31
|
+
document.addEventListener('click', this.detectOutsideBind);
|
|
32
|
+
}
|
|
33
|
+
disconnectedCallback() {
|
|
34
|
+
this.detectOutsideBind && document.removeEventListener('click', this.detectOutsideBind);
|
|
35
|
+
super.disconnectedCallback();
|
|
36
|
+
}
|
|
37
|
+
detectOutsideClick(e) {
|
|
38
|
+
const path = e.composedPath();
|
|
39
|
+
if (path.length > 0) {
|
|
40
|
+
// @ts-ignore
|
|
41
|
+
const container = path.find((el) => el.id === 'clickbox');
|
|
42
|
+
// const container = actualTarget.closest('#clickbox');
|
|
43
|
+
if (!container) {
|
|
44
|
+
// Clicked outside the box
|
|
45
|
+
this._hasFocus = false;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
33
49
|
render() {
|
|
34
50
|
const classMapValues = {
|
|
35
51
|
search: true,
|
|
36
52
|
hasFocus: this._hasFocus,
|
|
37
53
|
};
|
|
38
54
|
return html `
|
|
39
|
-
<div class=${classMap(classMapValues)}>
|
|
55
|
+
<div id="clickbox" class=${classMap(classMapValues)}>
|
|
40
56
|
<div class="mode-input">
|
|
41
57
|
<md-focus-ring for="searchInput" inward></md-focus-ring>
|
|
42
58
|
<md-icon class="search">search</md-icon>
|
|
@@ -46,7 +62,6 @@ export class ExmSearchBase extends ExmgElement {
|
|
|
46
62
|
value=${this.filterValue ? this.filterValue : ''}
|
|
47
63
|
onfocus="let value = this.value; this.value = null; this.value = value"
|
|
48
64
|
@keyup=${this._handleKeyUp}
|
|
49
|
-
@blur=${this._handleInputBlur}
|
|
50
65
|
/>
|
|
51
66
|
${this.filterValue
|
|
52
67
|
? html `
|
|
@@ -54,7 +69,7 @@ export class ExmSearchBase extends ExmgElement {
|
|
|
54
69
|
`
|
|
55
70
|
: nothing}
|
|
56
71
|
</div>
|
|
57
|
-
<div class="mode-default" @click=${() =>
|
|
72
|
+
<div class="mode-default" @click=${() => this.focus()}>
|
|
58
73
|
<md-icon class="search">search</md-icon>
|
|
59
74
|
<span class="interactive-content">${this._getValue()}</span>
|
|
60
75
|
${this.filterValue
|
|
@@ -73,12 +88,15 @@ export class ExmSearchBase extends ExmgElement {
|
|
|
73
88
|
this.fire('search-value-change', { value: this.filterValue }, this.bubbles);
|
|
74
89
|
}
|
|
75
90
|
_handleClear(e) {
|
|
91
|
+
var _a;
|
|
92
|
+
e.stopPropagation();
|
|
76
93
|
e.preventDefault();
|
|
77
94
|
this.filterValue = null;
|
|
78
95
|
if (this.search) {
|
|
79
96
|
this.search.value = '';
|
|
80
97
|
}
|
|
81
98
|
this._notifyChange();
|
|
99
|
+
(_a = this.search) === null || _a === void 0 ? void 0 : _a.focus();
|
|
82
100
|
}
|
|
83
101
|
_handleKeyUp(e) {
|
|
84
102
|
const input = e.target;
|
|
@@ -90,9 +108,6 @@ export class ExmSearchBase extends ExmgElement {
|
|
|
90
108
|
this._hasFocus = false;
|
|
91
109
|
}
|
|
92
110
|
}
|
|
93
|
-
_handleInputBlur() {
|
|
94
|
-
this._hasFocus = false;
|
|
95
|
-
}
|
|
96
111
|
updated(changedProperties) {
|
|
97
112
|
if (changedProperties.has('_hasFocus')) {
|
|
98
113
|
// after _hasFocus changed to true, focus the input
|