kr-elements 0.0.1-alpha.2 → 0.0.1-alpha.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.
@@ -11,6 +11,7 @@ class ComboboxMarkup {
11
11
  dropdown = null;
12
12
  placeholder = null;
13
13
  searchInput = null;
14
+ connected = false;
14
15
  constructor(shadowRoot, internals) {
15
16
  this.#shadowRoot = shadowRoot;
16
17
  this.#internals = internals;
@@ -21,12 +22,17 @@ class ComboboxMarkup {
21
22
  document.addEventListener('scroll', this.onPageScroll);
22
23
  }
23
24
  connect() {
25
+ const placeholder = this.#shadowRoot.host.getAttribute('placeholder') || '';
24
26
  this.tagsContainer = this.#shadowRoot.querySelector('#tags');
25
27
  this.optionsContainer = this.#shadowRoot.querySelector('[part="options"]');
26
28
  this.clearAllButton = this.#shadowRoot.querySelector('[part="clear-all-button"]');
27
29
  this.dropdown = this.#shadowRoot.querySelector('#dropdown');
28
30
  this.placeholder = this.#shadowRoot.querySelector('#placeholder');
31
+ this.placeholder.innerText = placeholder;
29
32
  this.searchInput = this.#shadowRoot.querySelector('[part="search-input"]');
33
+ this.searchInput.value = this.#shadowRoot.host.getAttribute('value');
34
+ this.searchInput.placeholder = placeholder;
35
+ this.connected = true;
30
36
  }
31
37
  sort(query) {
32
38
  const regex = new RegExp(query, 'i');
@@ -49,6 +55,7 @@ class ComboboxMarkup {
49
55
  this.#shadowRoot.host.removeEventListener('click', this.showDropdown);
50
56
  document.removeEventListener('click', this.hideDropdown);
51
57
  document.removeEventListener('scroll', this.onPageScroll);
58
+ this.connected = false;
52
59
  }
53
60
  onPageScroll = () => {
54
61
  if (this.dropdown.matches(':popover-open')) {
@@ -169,9 +176,9 @@ class ComboboxMarkup {
169
176
  }
170
177
 
171
178
  [part="options"] box-option {
179
+ display: flex;
172
180
  border-radius: inherit;
173
181
  content-visibility: auto;
174
- border: 1px solid cornflowerblue;
175
182
  }
176
183
 
177
184
  [part="options"] box-option[selected] {
@@ -215,7 +222,7 @@ class ComboboxMarkup {
215
222
  border-radius: inherit;
216
223
  }
217
224
 
218
- [part="tag"] {
225
+ [part="box-tag"] {
219
226
  width: 100%;
220
227
  justify-self: start;
221
228
  font-size: inherit;
@@ -229,7 +236,7 @@ class ComboboxMarkup {
229
236
  gap: 5px;
230
237
  }
231
238
 
232
- :host([multiple]) [part="tag"] {
239
+ :host([multiple]) [part="box-tag"] {
233
240
  background-color: Highlight;
234
241
  width: fit-content;
235
242
  max-width: 100%;
@@ -291,7 +298,8 @@ class ComboboxMarkup {
291
298
  }
292
299
 
293
300
  :host:has(#tags:empty) [part="clear-all-button"] {
294
- /*display: none;*/
301
+ pointer-events: none;
302
+ color: darkgrey;
295
303
  }
296
304
 
297
305
  </style>
@@ -96,59 +96,63 @@ class HTMLComboboxElement extends HTMLElement {
96
96
  });
97
97
  }
98
98
  get query() {
99
- return this.#markup.searchInput.value;
99
+ return this.getAttribute('query');
100
100
  }
101
101
  set query(value) {
102
102
  if (value === this.query)
103
103
  return;
104
- this.#markup.searchInput.value = value;
105
104
  super.setAttribute('query', value);
105
+ if (this.#markup.connected) {
106
+ this.#markup.searchInput.value = value;
107
+ }
106
108
  }
107
109
  get clearable() {
108
110
  return this.hasAttribute('clearable');
109
111
  }
110
112
  set clearable(value) {
111
- super.toggleAttribute('clearable', value);
113
+ super.toggleAttribute('clearable', (0, Boolean_attribute_value_normalizer_js_1.toBoolean)(value));
112
114
  }
113
115
  get multiple() {
114
116
  return this.hasAttribute('multiple');
115
117
  }
116
118
  set multiple(value) {
117
- super.toggleAttribute('multiple', value);
119
+ super.toggleAttribute('multiple', (0, Boolean_attribute_value_normalizer_js_1.toBoolean)(value));
118
120
  }
119
121
  get filterable() {
120
122
  return this.hasAttribute('filterable');
121
123
  }
122
124
  set filterable(value) {
123
- super.toggleAttribute('filterable', value);
125
+ super.toggleAttribute('filterable', (0, Boolean_attribute_value_normalizer_js_1.toBoolean)(value));
124
126
  }
125
127
  get searchable() {
126
128
  return this.hasAttribute('searchable');
127
129
  }
128
130
  set searchable(value) {
129
- super.toggleAttribute('searchable', value);
131
+ super.toggleAttribute('searchable', (0, Boolean_attribute_value_normalizer_js_1.toBoolean)(value));
130
132
  }
131
133
  get disabled() {
132
134
  return this.hasAttribute('disabled');
133
135
  }
134
136
  set disabled(value) {
135
137
  this.internals.ariaDisabled = String(value);
136
- super.toggleAttribute('disabled', value);
138
+ super.toggleAttribute('disabled', (0, Boolean_attribute_value_normalizer_js_1.toBoolean)(value));
137
139
  }
138
140
  get required() {
139
141
  return this.hasAttribute('required');
140
142
  }
141
143
  set required(value) {
142
144
  this.internals.ariaRequired = String(value);
143
- super.toggleAttribute('required', value);
145
+ super.toggleAttribute('required', (0, Boolean_attribute_value_normalizer_js_1.toBoolean)(value));
144
146
  }
145
147
  get placeholder() {
146
- return this.#markup.searchInput.placeholder;
148
+ return this.getAttribute('placeholder');
147
149
  }
148
150
  set placeholder(value) {
149
- this.#markup.placeholder.innerText = value;
150
- this.#markup.searchInput.placeholder = value;
151
151
  super.setAttribute('placeholder', value);
152
+ if (this.#markup.connected) {
153
+ this.#markup.placeholder.innerText = value;
154
+ this.#markup.searchInput.placeholder = value;
155
+ }
152
156
  }
153
157
  setAttribute(name, value) {
154
158
  if (HTMLComboboxElement.booleanAttributes.has(name)) {
@@ -8,6 +8,7 @@ export class ComboboxMarkup {
8
8
  dropdown = null;
9
9
  placeholder = null;
10
10
  searchInput = null;
11
+ connected = false;
11
12
  constructor(shadowRoot, internals) {
12
13
  this.#shadowRoot = shadowRoot;
13
14
  this.#internals = internals;
@@ -18,12 +19,17 @@ export class ComboboxMarkup {
18
19
  document.addEventListener('scroll', this.onPageScroll);
19
20
  }
20
21
  connect() {
22
+ const placeholder = this.#shadowRoot.host.getAttribute('placeholder') || '';
21
23
  this.tagsContainer = this.#shadowRoot.querySelector('#tags');
22
24
  this.optionsContainer = this.#shadowRoot.querySelector('[part="options"]');
23
25
  this.clearAllButton = this.#shadowRoot.querySelector('[part="clear-all-button"]');
24
26
  this.dropdown = this.#shadowRoot.querySelector('#dropdown');
25
27
  this.placeholder = this.#shadowRoot.querySelector('#placeholder');
28
+ this.placeholder.innerText = placeholder;
26
29
  this.searchInput = this.#shadowRoot.querySelector('[part="search-input"]');
30
+ this.searchInput.value = this.#shadowRoot.host.getAttribute('value');
31
+ this.searchInput.placeholder = placeholder;
32
+ this.connected = true;
27
33
  }
28
34
  sort(query) {
29
35
  const regex = new RegExp(query, 'i');
@@ -46,6 +52,7 @@ export class ComboboxMarkup {
46
52
  this.#shadowRoot.host.removeEventListener('click', this.showDropdown);
47
53
  document.removeEventListener('click', this.hideDropdown);
48
54
  document.removeEventListener('scroll', this.onPageScroll);
55
+ this.connected = false;
49
56
  }
50
57
  onPageScroll = () => {
51
58
  if (this.dropdown.matches(':popover-open')) {
@@ -166,9 +173,9 @@ export class ComboboxMarkup {
166
173
  }
167
174
 
168
175
  [part="options"] box-option {
176
+ display: flex;
169
177
  border-radius: inherit;
170
178
  content-visibility: auto;
171
- border: 1px solid cornflowerblue;
172
179
  }
173
180
 
174
181
  [part="options"] box-option[selected] {
@@ -212,7 +219,7 @@ export class ComboboxMarkup {
212
219
  border-radius: inherit;
213
220
  }
214
221
 
215
- [part="tag"] {
222
+ [part="box-tag"] {
216
223
  width: 100%;
217
224
  justify-self: start;
218
225
  font-size: inherit;
@@ -226,7 +233,7 @@ export class ComboboxMarkup {
226
233
  gap: 5px;
227
234
  }
228
235
 
229
- :host([multiple]) [part="tag"] {
236
+ :host([multiple]) [part="box-tag"] {
230
237
  background-color: Highlight;
231
238
  width: fit-content;
232
239
  max-width: 100%;
@@ -288,7 +295,8 @@ export class ComboboxMarkup {
288
295
  }
289
296
 
290
297
  :host:has(#tags:empty) [part="clear-all-button"] {
291
- /*display: none;*/
298
+ pointer-events: none;
299
+ color: darkgrey;
292
300
  }
293
301
 
294
302
  </style>
@@ -93,59 +93,63 @@ export class HTMLComboboxElement extends HTMLElement {
93
93
  });
94
94
  }
95
95
  get query() {
96
- return this.#markup.searchInput.value;
96
+ return this.getAttribute('query');
97
97
  }
98
98
  set query(value) {
99
99
  if (value === this.query)
100
100
  return;
101
- this.#markup.searchInput.value = value;
102
101
  super.setAttribute('query', value);
102
+ if (this.#markup.connected) {
103
+ this.#markup.searchInput.value = value;
104
+ }
103
105
  }
104
106
  get clearable() {
105
107
  return this.hasAttribute('clearable');
106
108
  }
107
109
  set clearable(value) {
108
- super.toggleAttribute('clearable', value);
110
+ super.toggleAttribute('clearable', toBoolean(value));
109
111
  }
110
112
  get multiple() {
111
113
  return this.hasAttribute('multiple');
112
114
  }
113
115
  set multiple(value) {
114
- super.toggleAttribute('multiple', value);
116
+ super.toggleAttribute('multiple', toBoolean(value));
115
117
  }
116
118
  get filterable() {
117
119
  return this.hasAttribute('filterable');
118
120
  }
119
121
  set filterable(value) {
120
- super.toggleAttribute('filterable', value);
122
+ super.toggleAttribute('filterable', toBoolean(value));
121
123
  }
122
124
  get searchable() {
123
125
  return this.hasAttribute('searchable');
124
126
  }
125
127
  set searchable(value) {
126
- super.toggleAttribute('searchable', value);
128
+ super.toggleAttribute('searchable', toBoolean(value));
127
129
  }
128
130
  get disabled() {
129
131
  return this.hasAttribute('disabled');
130
132
  }
131
133
  set disabled(value) {
132
134
  this.internals.ariaDisabled = String(value);
133
- super.toggleAttribute('disabled', value);
135
+ super.toggleAttribute('disabled', toBoolean(value));
134
136
  }
135
137
  get required() {
136
138
  return this.hasAttribute('required');
137
139
  }
138
140
  set required(value) {
139
141
  this.internals.ariaRequired = String(value);
140
- super.toggleAttribute('required', value);
142
+ super.toggleAttribute('required', toBoolean(value));
141
143
  }
142
144
  get placeholder() {
143
- return this.#markup.searchInput.placeholder;
145
+ return this.getAttribute('placeholder');
144
146
  }
145
147
  set placeholder(value) {
146
- this.#markup.placeholder.innerText = value;
147
- this.#markup.searchInput.placeholder = value;
148
148
  super.setAttribute('placeholder', value);
149
+ if (this.#markup.connected) {
150
+ this.#markup.placeholder.innerText = value;
151
+ this.#markup.searchInput.placeholder = value;
152
+ }
149
153
  }
150
154
  setAttribute(name, value) {
151
155
  if (HTMLComboboxElement.booleanAttributes.has(name)) {
@@ -8,6 +8,7 @@ export declare class ComboboxMarkup {
8
8
  dropdown: HTMLDivElement | null;
9
9
  placeholder: HTMLDivElement | null;
10
10
  searchInput: HTMLInputElement | null;
11
+ connected: boolean;
11
12
  constructor(shadowRoot: ShadowRoot, internals: ElementInternals);
12
13
  connect(): void;
13
14
  sort(query: string): void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "kr-elements",
3
- "version": "0.0.1-alpha.2",
3
+ "version": "0.0.1-alpha.3",
4
4
  "description": "Custom elements",
5
5
  "type": "module",
6
6
  "scripts": {