@kubex/zinc 1.1.34 → 1.1.36

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kubex/zinc",
3
- "version": "1.1.34",
3
+ "version": "1.1.36",
4
4
  "description": "A collection of web components for building web applications based off of @shoelace-style/Shoelace",
5
5
  "keywords": [
6
6
  "web components",
@@ -80,6 +80,9 @@ export default class ZnChatMessage extends ZincElement {
80
80
  /** Marks the message as initiated by an agent (affects styling and grouping). */
81
81
  @property({type: Boolean, reflect: true, attribute: 'agent-initiated'}) agentInitiated = false;
82
82
 
83
+ /** Hides the sender's name in the message header. */
84
+ @property({type: Boolean, reflect: true, attribute: 'hide-sender'}) hideSender = false;
85
+
83
86
  /** Whether any element is assigned to the `attachments` slot — drives the attachments row visibility. */
84
87
  @state() private hasAttachments = false;
85
88
 
@@ -199,7 +202,8 @@ export default class ZnChatMessage extends ZincElement {
199
202
  private renderHeader() {
200
203
  return html`
201
204
  <div part="header" class="message__header">
202
- <span class="message__sender">${this.sender || (this.customerInitiated ? 'Customer' : 'You')}</span>
205
+ ${this.hideSender ? nothing : html`
206
+ <span class="message__sender">${this.sender || (this.customerInitiated ? 'Customer' : 'You')}</span>`}
203
207
  ${this.time ? html`<span class="message__time">${this.getSentTime()}</span>` : nothing}
204
208
  ${this.actionType === 'internal' ? html`
205
209
  <zn-chip type="info">Internal Note</zn-chip>` : nothing}
@@ -1079,6 +1079,10 @@ export default class ZnSelect extends ZincElement implements ZincFormControl {
1079
1079
  } else {
1080
1080
  this.setSelectedOptions(initiallySelectedOptions[0]);
1081
1081
  }
1082
+
1083
+ if (!this.defaultValue || this.defaultValue.length === 0) {
1084
+ this.defaultValue = this.value;
1085
+ }
1082
1086
  }
1083
1087
  }
1084
1088
 
@@ -1096,6 +1100,8 @@ export default class ZnSelect extends ZincElement implements ZincFormControl {
1096
1100
  event.stopImmediatePropagation();
1097
1101
 
1098
1102
  if (!this.disabled) {
1103
+ this.valueHasChanged = true;
1104
+
1099
1105
  // Deselecting drops the backing element for free-text values via selectionChanged's cleanup.
1100
1106
  this.toggleOptionSelection(option, false);
1101
1107
 
@@ -231,6 +231,33 @@ describe('<zn-select>', () => {
231
231
  const chip = el.shadowRoot!.querySelector<HTMLElement>('.select__tags zn-chip')!;
232
232
  expect(getComputedStyle(chip).cursor).to.equal('default');
233
233
  });
234
+
235
+ it('removes a value when the tag remove icon is clicked before any other interaction', async () => {
236
+ const el = await fixture<ZnSelect>(html`
237
+ <zn-select multiple value="a b c">
238
+ <zn-option value="a">Option 1</zn-option>
239
+ <zn-option value="b">Option 2</zn-option>
240
+ <zn-option value="c">Option 3</zn-option>
241
+ </zn-select>
242
+ `);
243
+ await el.updateComplete;
244
+ expect(el.value).to.deep.equal(['a', 'b', 'c']);
245
+
246
+ let changed = false;
247
+ el.addEventListener('zn-change', () => {
248
+ changed = true;
249
+ });
250
+
251
+ const removeIcon = el.shadowRoot!.querySelector<HTMLElement>('.select__tags zn-icon[slot="action"]')!;
252
+ removeIcon.click();
253
+ await el.updateComplete;
254
+ // handleValueChange runs as a @watch on the next update cycle; give it a beat
255
+ await el.updateComplete;
256
+
257
+ expect(el.value).to.deep.equal(['b', 'c']);
258
+ expect(el.shadowRoot!.querySelectorAll('.select__tags zn-chip').length).to.equal(2);
259
+ expect(changed).to.be.true;
260
+ });
234
261
  });
235
262
 
236
263
  describe('free-text', () => {
@@ -15,6 +15,7 @@ interface SettingsContainerFilter {
15
15
  checked: boolean;
16
16
  label: string;
17
17
  itemSelector?: string;
18
+ toggleAttribute?: string;
18
19
  }
19
20
 
20
21
  /**
@@ -56,7 +57,9 @@ export default class ZnSettingsContainer extends ZincElement {
56
57
  config: {childList: true, subtree: true, attributes: true},
57
58
  callback: mutations => {
58
59
  for (const mutation of mutations) {
59
- if (mutation.type === 'attributes' && mutation.attributeName === 'hidden') {
60
+ if (mutation.type === 'attributes' &&
61
+ (mutation.attributeName === 'hidden' ||
62
+ this.filters.some(f => f.toggleAttribute === mutation.attributeName))) {
60
63
  continue;
61
64
  }
62
65
  this.scheduleUpdateFilters();
@@ -159,7 +162,8 @@ export default class ZnSettingsContainer extends ZincElement {
159
162
  const checked = existingChecked.has(attribute) ? !!existingChecked.get(attribute) : defaultChecked;
160
163
  const label = filter.textContent || 'Unnamed Filter';
161
164
  const itemSelector = filter.getAttribute('item-selector') || '*';
162
- nextFilters.push({attribute, checked, label, itemSelector});
165
+ const toggleAttribute = filter.getAttribute('toggle-attribute') || undefined;
166
+ nextFilters.push({attribute, checked, label, itemSelector, toggleAttribute});
163
167
  });
164
168
  this.filters = nextFilters;
165
169
  }
@@ -173,9 +177,18 @@ export default class ZnSettingsContainer extends ZincElement {
173
177
  items = this.querySelectorAll(filter.itemSelector + attrAppend);
174
178
  }
175
179
  items.forEach(item => {
180
+ if (filter.toggleAttribute) {
181
+ if (checked) {
182
+ item.removeAttribute(filter.toggleAttribute);
183
+ } else {
184
+ item.setAttribute(filter.toggleAttribute, 'true');
185
+ }
186
+ return;
187
+ }
188
+
176
189
  if (checked) {
177
190
  const shouldStayHidden = this.filters.some(f => {
178
- if (f.attribute === filter.attribute || f.checked) return false;
191
+ if (f.attribute === filter.attribute || f.checked || f.toggleAttribute) return false;
179
192
  const fAttrAppend = f.attribute === "*" ? `` : `[${f.attribute}]`;
180
193
  let fItems;
181
194
  if (f.itemSelector && f.itemSelector.startsWith('>')) {