@nectary/components 3.0.1 → 3.1.0

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.
@@ -10,6 +10,7 @@ const template = document.createElement('template');
10
10
  template.innerHTML = templateHTML;
11
11
  (0, _utils.defineCustomElement)('sinch-dialog', class extends _utils.NectaryElement {
12
12
  #$dialog;
13
+ #$dialogContent;
13
14
  #$closeButton;
14
15
  #$caption;
15
16
  #$actionWrapper;
@@ -20,6 +21,7 @@ template.innerHTML = templateHTML;
20
21
  const shadowRoot = this.attachShadow();
21
22
  shadowRoot.appendChild(template.content.cloneNode(true));
22
23
  this.#$dialog = shadowRoot.querySelector('#dialog');
24
+ this.#$dialogContent = shadowRoot.querySelector('#content');
23
25
  this.#$closeButton = shadowRoot.querySelector('#close');
24
26
  this.#$caption = shadowRoot.querySelector('#caption');
25
27
  this.#$actionWrapper = shadowRoot.querySelector('#action');
@@ -141,6 +143,7 @@ template.innerHTML = templateHTML;
141
143
  if (!this.#$dialog.open) {
142
144
  return;
143
145
  }
146
+ this.#$dialogContent.scrollTo(0, 0);
144
147
  this.#$dialog.close?.();
145
148
  (0, _utils2.enableScroll)();
146
149
  }
@@ -17,6 +17,7 @@ template.innerHTML = templateHTML;
17
17
  #$notFound;
18
18
  #controller = null;
19
19
  #searchDebounce;
20
+ #userManagedSearch = false;
20
21
  constructor() {
21
22
  super();
22
23
  const shadowRoot = this.attachShadow();
@@ -26,7 +27,7 @@ template.innerHTML = templateHTML;
26
27
  this.#$search = shadowRoot.querySelector('#search');
27
28
  this.#$searchClear = shadowRoot.querySelector('#search-clear');
28
29
  this.#$notFound = shadowRoot.querySelector('#not-found');
29
- this.#searchDebounce = (0, _utils.debounceTimeout)(200)(this.#updateSearch);
30
+ this.#searchDebounce = (0, _utils.debounceTimeout)(200)(this.#updateSearchValue);
30
31
  }
31
32
  connectedCallback() {
32
33
  this.#controller = new AbortController();
@@ -54,7 +55,7 @@ template.innerHTML = templateHTML;
54
55
  this.#controller = null;
55
56
  }
56
57
  static get observedAttributes() {
57
- return ['value', 'rows', 'multiple', 'search-placeholder'];
58
+ return ['value', 'rows', 'multiple', 'search-value', 'search-placeholder'];
58
59
  }
59
60
  attributeChangedCallback(name, oldVal, newVal) {
60
61
  switch (name) {
@@ -82,6 +83,13 @@ template.innerHTML = templateHTML;
82
83
  (0, _utils.updateAttribute)(this.#$search, 'placeholder', newVal);
83
84
  break;
84
85
  }
86
+ case 'search-value':
87
+ {
88
+ (0, _utils.updateAttribute)(this.#$search, 'value', newVal);
89
+ this.#userManagedSearch = true;
90
+ this.#updateSearchList(newVal !== null ? newVal : '');
91
+ break;
92
+ }
85
93
  }
86
94
  }
87
95
  set value(value) {
@@ -115,6 +123,13 @@ template.innerHTML = templateHTML;
115
123
  get 'search-placeholder'() {
116
124
  return (0, _utils.getAttribute)(this.#$search, 'placeholder', '');
117
125
  }
126
+ set 'search-value'(value) {
127
+ (0, _utils.updateAttribute)(this, 'search-value', value);
128
+ this.#userManagedSearch = true;
129
+ }
130
+ get 'search-value'() {
131
+ return (0, _utils.getAttribute)(this, 'search-value', '');
132
+ }
118
133
  get focusable() {
119
134
  return true;
120
135
  }
@@ -136,35 +151,46 @@ template.innerHTML = templateHTML;
136
151
  }
137
152
  };
138
153
  #onSearchChange = e => {
139
- this.#$search.value = e.detail;
140
- this.#searchDebounce.fn();
154
+ if (!this.#userManagedSearch) {
155
+ this.#$search.value = e.detail;
156
+ this.#searchDebounce.fn();
157
+ } else {
158
+ this.#updateSearchValue(e.detail);
159
+ }
141
160
  (0, _utils.setClass)(this.#$searchClear, 'active', e.detail.length > 0);
142
161
  };
143
162
  #onSearchClearClick = () => {
144
- this.#$search.value = '';
163
+ if (!this.#userManagedSearch) {
164
+ this.#$search.value = '';
165
+ this.#searchDebounce.fn();
166
+ } else {
167
+ this.#updateSearchValue('');
168
+ }
145
169
  this.#$search.focus();
146
- this.#searchDebounce.fn();
147
170
  (0, _utils.setClass)(this.#$searchClear, 'active', false);
148
171
  };
149
- #updateSearch = () => {
150
- const searchValue = this.#$search.value.toLowerCase();
172
+ #updateSearchValue = newValue => {
173
+ const searchValue = newValue === undefined ? this.#$search.value.toLowerCase() : newValue;
151
174
  const searchChangedEvent = new CustomEvent('-search-change', {
152
- detail: searchValue,
175
+ detail: newValue,
153
176
  cancelable: true
154
177
  });
155
178
  this.dispatchEvent(searchChangedEvent);
156
179
  if (!searchChangedEvent.defaultPrevented) {
157
- const $options = this.#getOptionElements();
158
- let someFound = false;
159
- for (const $opt of $options) {
160
- const isHidden = searchValue.length > 0 && !$opt.matchesSearch(searchValue);
161
- someFound ||= !isHidden;
162
- (0, _utils.setClass)($opt, 'hidden', isHidden);
163
- }
164
- (0, _utils.setClass)(this.#$notFound, 'active', !someFound);
165
- this.#selectOption(null);
180
+ this.#updateSearchList(searchValue);
166
181
  }
167
182
  };
183
+ #updateSearchList = searchValue => {
184
+ const $options = this.#getOptionElements();
185
+ let someFound = false;
186
+ for (const $opt of $options) {
187
+ const isHidden = searchValue.length > 0 && !$opt.matchesSearch(searchValue);
188
+ someFound ||= !isHidden;
189
+ (0, _utils.setClass)($opt, 'hidden', isHidden);
190
+ }
191
+ (0, _utils.setClass)(this.#$notFound, 'active', !someFound);
192
+ this.#selectOption(null);
193
+ };
168
194
  #onContextKeyDown = e => {
169
195
  this.#handleKeydown(e.detail);
170
196
  };
@@ -10,6 +10,8 @@ export type TSinchSelectMenuElement = HTMLElement & {
10
10
  searchable: boolean | null;
11
11
  /** Text for search bar's placeholder */
12
12
  'search-placeholder': string;
13
+ /** Optionally control search value manually */
14
+ 'search-value': string;
13
15
  /** Change value event */
14
16
  addEventListener(type: '-change', listener: (e: CustomEvent<string>) => void): void;
15
17
  /** Change value event */
@@ -36,6 +38,8 @@ export type TSinchSelectMenuReact = TSinchElementReact<TSinchSelectMenuElement>
36
38
  'aria-label': string;
37
39
  /** Change value handler */
38
40
  'on-search-change'?: (e: CustomEvent<string>) => void;
41
+ /** Optionally control search value manually */
42
+ 'search-value'?: string;
39
43
  /** Change value handler */
40
44
  'on-change'?: (e: CustomEvent<string>) => void;
41
45
  };
@@ -65,7 +65,7 @@ class SelectMenuOption extends _utils.NectaryElement {
65
65
  return (0, _utils.getBooleanAttribute)(this, 'disabled');
66
66
  }
67
67
  matchesSearch(searchValue) {
68
- return this.text.toLowerCase().includes(searchValue);
68
+ return this.text.toLowerCase().includes(searchValue.toLowerCase());
69
69
  }
70
70
  }
71
71
  exports.SelectMenuOption = SelectMenuOption;
@@ -8,6 +8,7 @@ const template = document.createElement('template');
8
8
  template.innerHTML = templateHTML;
9
9
  defineCustomElement('sinch-dialog', class extends NectaryElement {
10
10
  #$dialog;
11
+ #$dialogContent;
11
12
  #$closeButton;
12
13
  #$caption;
13
14
  #$actionWrapper;
@@ -18,6 +19,7 @@ defineCustomElement('sinch-dialog', class extends NectaryElement {
18
19
  const shadowRoot = this.attachShadow();
19
20
  shadowRoot.appendChild(template.content.cloneNode(true));
20
21
  this.#$dialog = shadowRoot.querySelector('#dialog');
22
+ this.#$dialogContent = shadowRoot.querySelector('#content');
21
23
  this.#$closeButton = shadowRoot.querySelector('#close');
22
24
  this.#$caption = shadowRoot.querySelector('#caption');
23
25
  this.#$actionWrapper = shadowRoot.querySelector('#action');
@@ -139,6 +141,7 @@ defineCustomElement('sinch-dialog', class extends NectaryElement {
139
141
  if (!this.#$dialog.open) {
140
142
  return;
141
143
  }
144
+ this.#$dialogContent.scrollTo(0, 0);
142
145
  this.#$dialog.close?.();
143
146
  enableScroll();
144
147
  }
@@ -15,6 +15,7 @@ defineCustomElement('sinch-select-menu', class extends NectaryElement {
15
15
  #$notFound;
16
16
  #controller = null;
17
17
  #searchDebounce;
18
+ #userManagedSearch = false;
18
19
  constructor() {
19
20
  super();
20
21
  const shadowRoot = this.attachShadow();
@@ -24,7 +25,7 @@ defineCustomElement('sinch-select-menu', class extends NectaryElement {
24
25
  this.#$search = shadowRoot.querySelector('#search');
25
26
  this.#$searchClear = shadowRoot.querySelector('#search-clear');
26
27
  this.#$notFound = shadowRoot.querySelector('#not-found');
27
- this.#searchDebounce = debounceTimeout(200)(this.#updateSearch);
28
+ this.#searchDebounce = debounceTimeout(200)(this.#updateSearchValue);
28
29
  }
29
30
  connectedCallback() {
30
31
  this.#controller = new AbortController();
@@ -52,7 +53,7 @@ defineCustomElement('sinch-select-menu', class extends NectaryElement {
52
53
  this.#controller = null;
53
54
  }
54
55
  static get observedAttributes() {
55
- return ['value', 'rows', 'multiple', 'search-placeholder'];
56
+ return ['value', 'rows', 'multiple', 'search-value', 'search-placeholder'];
56
57
  }
57
58
  attributeChangedCallback(name, oldVal, newVal) {
58
59
  switch (name) {
@@ -80,6 +81,13 @@ defineCustomElement('sinch-select-menu', class extends NectaryElement {
80
81
  updateAttribute(this.#$search, 'placeholder', newVal);
81
82
  break;
82
83
  }
84
+ case 'search-value':
85
+ {
86
+ updateAttribute(this.#$search, 'value', newVal);
87
+ this.#userManagedSearch = true;
88
+ this.#updateSearchList(newVal !== null ? newVal : '');
89
+ break;
90
+ }
83
91
  }
84
92
  }
85
93
  set value(value) {
@@ -113,6 +121,13 @@ defineCustomElement('sinch-select-menu', class extends NectaryElement {
113
121
  get 'search-placeholder'() {
114
122
  return getAttribute(this.#$search, 'placeholder', '');
115
123
  }
124
+ set 'search-value'(value) {
125
+ updateAttribute(this, 'search-value', value);
126
+ this.#userManagedSearch = true;
127
+ }
128
+ get 'search-value'() {
129
+ return getAttribute(this, 'search-value', '');
130
+ }
116
131
  get focusable() {
117
132
  return true;
118
133
  }
@@ -134,35 +149,46 @@ defineCustomElement('sinch-select-menu', class extends NectaryElement {
134
149
  }
135
150
  };
136
151
  #onSearchChange = e => {
137
- this.#$search.value = e.detail;
138
- this.#searchDebounce.fn();
152
+ if (!this.#userManagedSearch) {
153
+ this.#$search.value = e.detail;
154
+ this.#searchDebounce.fn();
155
+ } else {
156
+ this.#updateSearchValue(e.detail);
157
+ }
139
158
  setClass(this.#$searchClear, 'active', e.detail.length > 0);
140
159
  };
141
160
  #onSearchClearClick = () => {
142
- this.#$search.value = '';
161
+ if (!this.#userManagedSearch) {
162
+ this.#$search.value = '';
163
+ this.#searchDebounce.fn();
164
+ } else {
165
+ this.#updateSearchValue('');
166
+ }
143
167
  this.#$search.focus();
144
- this.#searchDebounce.fn();
145
168
  setClass(this.#$searchClear, 'active', false);
146
169
  };
147
- #updateSearch = () => {
148
- const searchValue = this.#$search.value.toLowerCase();
170
+ #updateSearchValue = newValue => {
171
+ const searchValue = newValue === undefined ? this.#$search.value.toLowerCase() : newValue;
149
172
  const searchChangedEvent = new CustomEvent('-search-change', {
150
- detail: searchValue,
173
+ detail: newValue,
151
174
  cancelable: true
152
175
  });
153
176
  this.dispatchEvent(searchChangedEvent);
154
177
  if (!searchChangedEvent.defaultPrevented) {
155
- const $options = this.#getOptionElements();
156
- let someFound = false;
157
- for (const $opt of $options) {
158
- const isHidden = searchValue.length > 0 && !$opt.matchesSearch(searchValue);
159
- someFound ||= !isHidden;
160
- setClass($opt, 'hidden', isHidden);
161
- }
162
- setClass(this.#$notFound, 'active', !someFound);
163
- this.#selectOption(null);
178
+ this.#updateSearchList(searchValue);
164
179
  }
165
180
  };
181
+ #updateSearchList = searchValue => {
182
+ const $options = this.#getOptionElements();
183
+ let someFound = false;
184
+ for (const $opt of $options) {
185
+ const isHidden = searchValue.length > 0 && !$opt.matchesSearch(searchValue);
186
+ someFound ||= !isHidden;
187
+ setClass($opt, 'hidden', isHidden);
188
+ }
189
+ setClass(this.#$notFound, 'active', !someFound);
190
+ this.#selectOption(null);
191
+ };
166
192
  #onContextKeyDown = e => {
167
193
  this.#handleKeydown(e.detail);
168
194
  };
@@ -10,6 +10,8 @@ export type TSinchSelectMenuElement = HTMLElement & {
10
10
  searchable: boolean | null;
11
11
  /** Text for search bar's placeholder */
12
12
  'search-placeholder': string;
13
+ /** Optionally control search value manually */
14
+ 'search-value': string;
13
15
  /** Change value event */
14
16
  addEventListener(type: '-change', listener: (e: CustomEvent<string>) => void): void;
15
17
  /** Change value event */
@@ -36,6 +38,8 @@ export type TSinchSelectMenuReact = TSinchElementReact<TSinchSelectMenuElement>
36
38
  'aria-label': string;
37
39
  /** Change value handler */
38
40
  'on-search-change'?: (e: CustomEvent<string>) => void;
41
+ /** Optionally control search value manually */
42
+ 'search-value'?: string;
39
43
  /** Change value handler */
40
44
  'on-change'?: (e: CustomEvent<string>) => void;
41
45
  };
@@ -59,7 +59,7 @@ export class SelectMenuOption extends NectaryElement {
59
59
  return getBooleanAttribute(this, 'disabled');
60
60
  }
61
61
  matchesSearch(searchValue) {
62
- return this.text.toLowerCase().includes(searchValue);
62
+ return this.text.toLowerCase().includes(searchValue.toLowerCase());
63
63
  }
64
64
  }
65
65
  defineCustomElement('sinch-select-menu-option', SelectMenuOption);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nectary/components",
3
- "version": "3.0.1",
3
+ "version": "3.1.0",
4
4
  "files": [
5
5
  "lib"
6
6
  ],