@exmg/exm-search 1.0.0 → 1.0.2

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/index.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- export { ExmgSearch } from './src/exm-search.js';
2
- export { ExmgSearchBase } from './src/exm-search-base.js';
1
+ export { ExmSearch } from './src/exm-search.js';
2
+ export { ExmSearchBase } from './src/exm-search-base.js';
3
3
  export { style as exmgSearchStyles } from './src/styles/exm-search-css.js';
package/index.js CHANGED
@@ -1,4 +1,4 @@
1
- export { ExmgSearch } from './src/exm-search.js';
2
- export { ExmgSearchBase } from './src/exm-search-base.js';
1
+ export { ExmSearch } from './src/exm-search.js';
2
+ export { ExmSearchBase } from './src/exm-search-base.js';
3
3
  export { style as exmgSearchStyles } from './src/styles/exm-search-css.js';
4
4
  //# sourceMappingURL=index.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@exmg/exm-search",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "type": "module",
5
5
  "main": "index.js",
6
6
  "module": "index.js",
@@ -40,5 +40,5 @@
40
40
  "publishConfig": {
41
41
  "access": "public"
42
42
  },
43
- "gitHead": "0907b55c89325d59902b98a64c352bf6e1fc81ff"
43
+ "gitHead": "313ba6df520ba0a4f3ac614c1c3f8df970291b19"
44
44
  }
@@ -1,21 +1,25 @@
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';
5
- export declare class ExmgSearchBase extends ExmgElement {
6
+ export declare class ExmSearchBase extends ExmgElement {
6
7
  bubbles: boolean;
7
8
  _hasFocus: boolean;
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: CustomEvent): void;
22
+ _handleClear(e: Event): void;
18
23
  _handleKeyUp(e: KeyboardEvent): void;
19
- _handleInputBlur(): void;
20
24
  updated(changedProperties: Map<string, any>): void;
21
25
  }
@@ -6,7 +6,7 @@ import { classMap } from 'lit/directives/class-map.js';
6
6
  import '@material/web/icon/icon.js';
7
7
  import '@material/web/iconbutton/icon-button.js';
8
8
  import '@material/web/focus/md-focus-ring.js';
9
- export class ExmgSearchBase extends ExmgElement {
9
+ export class ExmSearchBase extends ExmgElement {
10
10
  constructor() {
11
11
  super();
12
12
  this.bubbles = false;
@@ -15,10 +15,6 @@ export class ExmgSearchBase 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 ExmgSearchBase 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 ExmgSearchBase 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 ExmgSearchBase extends ExmgElement {
54
69
  `
55
70
  : nothing}
56
71
  </div>
57
- <div class="mode-default" @click=${() => (this._hasFocus = true)}>
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 ExmgSearchBase 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 ExmgSearchBase 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
@@ -104,14 +119,14 @@ export class ExmgSearchBase extends ExmgElement {
104
119
  }
105
120
  __decorate([
106
121
  state()
107
- ], ExmgSearchBase.prototype, "_hasFocus", void 0);
122
+ ], ExmSearchBase.prototype, "_hasFocus", void 0);
108
123
  __decorate([
109
124
  property({ type: String })
110
- ], ExmgSearchBase.prototype, "filterValue", void 0);
125
+ ], ExmSearchBase.prototype, "filterValue", void 0);
111
126
  __decorate([
112
127
  property({ type: String })
113
- ], ExmgSearchBase.prototype, "placeHolder", void 0);
128
+ ], ExmSearchBase.prototype, "placeHolder", void 0);
114
129
  __decorate([
115
130
  query('#searchInput')
116
- ], ExmgSearchBase.prototype, "search", void 0);
131
+ ], ExmSearchBase.prototype, "search", void 0);
117
132
  //# sourceMappingURL=exm-search-base.js.map
@@ -1,10 +1,10 @@
1
1
  import '@material/web/progress/circular-progress.js';
2
- import { ExmgSearchBase } from './exm-search-base.js';
3
- export declare class ExmgSearch extends ExmgSearchBase {
2
+ import { ExmSearchBase } from './exm-search-base.js';
3
+ export declare class ExmSearch extends ExmSearchBase {
4
4
  static styles: import("lit").CSSResult[];
5
5
  }
6
6
  declare global {
7
7
  interface HTMLElementTagNameMap {
8
- 'exm-search': ExmgSearch;
8
+ 'exm-search': ExmSearch;
9
9
  }
10
10
  }
package/src/exm-search.js CHANGED
@@ -1,13 +1,13 @@
1
1
  import { __decorate } from "tslib";
2
2
  import { customElement } from 'lit/decorators/custom-element.js';
3
3
  import '@material/web/progress/circular-progress.js';
4
- import { ExmgSearchBase } from './exm-search-base.js';
4
+ import { ExmSearchBase } from './exm-search-base.js';
5
5
  import { style } from './styles/exm-search-css.js';
6
- let ExmgSearch = class ExmgSearch extends ExmgSearchBase {
6
+ let ExmSearch = class ExmSearch extends ExmSearchBase {
7
7
  };
8
- ExmgSearch.styles = [style];
9
- ExmgSearch = __decorate([
8
+ ExmSearch.styles = [style];
9
+ ExmSearch = __decorate([
10
10
  customElement('exm-search')
11
- ], ExmgSearch);
12
- export { ExmgSearch };
11
+ ], ExmSearch);
12
+ export { ExmSearch };
13
13
  //# sourceMappingURL=exm-search.js.map