kr-elements 0.0.1-alpha.2 → 0.0.1-alpha.4

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('query');
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')) {
@@ -163,15 +170,16 @@ class ComboboxMarkup {
163
170
  [part="options"] {
164
171
  display: flex;
165
172
  flex-direction: column;
173
+ justify-content: start;
166
174
  gap: 2px;
167
175
  padding-block: .5rem;
168
176
  border-radius: inherit;
169
177
  }
170
178
 
171
179
  [part="options"] box-option {
180
+ display: flex;
172
181
  border-radius: inherit;
173
182
  content-visibility: auto;
174
- border: 1px solid cornflowerblue;
175
183
  }
176
184
 
177
185
  [part="options"] box-option[selected] {
@@ -195,6 +203,7 @@ class ComboboxMarkup {
195
203
  }
196
204
 
197
205
  #placeholder {
206
+ text-align: left;
198
207
  overflow: hidden;
199
208
  }
200
209
 
@@ -215,7 +224,7 @@ class ComboboxMarkup {
215
224
  border-radius: inherit;
216
225
  }
217
226
 
218
- [part="tag"] {
227
+ [part="box-tag"] {
219
228
  width: 100%;
220
229
  justify-self: start;
221
230
  font-size: inherit;
@@ -229,7 +238,7 @@ class ComboboxMarkup {
229
238
  gap: 5px;
230
239
  }
231
240
 
232
- :host([multiple]) [part="tag"] {
241
+ :host([multiple]) [part="box-tag"] {
233
242
  background-color: Highlight;
234
243
  width: fit-content;
235
244
  max-width: 100%;
@@ -291,7 +300,8 @@ class ComboboxMarkup {
291
300
  }
292
301
 
293
302
  :host:has(#tags:empty) [part="clear-all-button"] {
294
- /*display: none;*/
303
+ pointer-events: none;
304
+ color: darkgrey;
295
305
  }
296
306
 
297
307
  </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('query');
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')) {
@@ -160,15 +167,16 @@ export class ComboboxMarkup {
160
167
  [part="options"] {
161
168
  display: flex;
162
169
  flex-direction: column;
170
+ justify-content: start;
163
171
  gap: 2px;
164
172
  padding-block: .5rem;
165
173
  border-radius: inherit;
166
174
  }
167
175
 
168
176
  [part="options"] box-option {
177
+ display: flex;
169
178
  border-radius: inherit;
170
179
  content-visibility: auto;
171
- border: 1px solid cornflowerblue;
172
180
  }
173
181
 
174
182
  [part="options"] box-option[selected] {
@@ -192,6 +200,7 @@ export class ComboboxMarkup {
192
200
  }
193
201
 
194
202
  #placeholder {
203
+ text-align: left;
195
204
  overflow: hidden;
196
205
  }
197
206
 
@@ -212,7 +221,7 @@ export class ComboboxMarkup {
212
221
  border-radius: inherit;
213
222
  }
214
223
 
215
- [part="tag"] {
224
+ [part="box-tag"] {
216
225
  width: 100%;
217
226
  justify-self: start;
218
227
  font-size: inherit;
@@ -226,7 +235,7 @@ export class ComboboxMarkup {
226
235
  gap: 5px;
227
236
  }
228
237
 
229
- :host([multiple]) [part="tag"] {
238
+ :host([multiple]) [part="box-tag"] {
230
239
  background-color: Highlight;
231
240
  width: fit-content;
232
241
  max-width: 100%;
@@ -288,7 +297,8 @@ export class ComboboxMarkup {
288
297
  }
289
298
 
290
299
  :host:has(#tags:empty) [part="clear-all-button"] {
291
- /*display: none;*/
300
+ pointer-events: none;
301
+ color: darkgrey;
292
302
  }
293
303
 
294
304
  </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.4",
4
4
  "description": "Custom elements",
5
5
  "type": "module",
6
6
  "scripts": {