@dile/ui 3.20.2 → 3.21.1

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.
@@ -0,0 +1,288 @@
1
+ import { html, css, nothing } from 'lit';
2
+ import { addIcon } from '@dile/icons';
3
+ import '../../chip/chip.js';
4
+ import '../../icon/icon.js';
5
+ import { normalize } from '../../input-suggestions/src/normalize.js';
6
+
7
+ /**
8
+ * # DileInputTagsMixin
9
+ *
10
+ * Turns a suggestions field (DileInputSuggestions, or DileAjaxInputSuggestions from
11
+ * `@dile/crud`) into a tags editor: the assigned tags are shown with `dile-chip` above the
12
+ * field, and the typed text adds a new one, choosing a suggestion or typing it by hand.
13
+ *
14
+ * It is a **controlled** component: it never changes `tags` itself. It emits events to add or
15
+ * remove, and the consumer updates `tags` (e.g. after saving it on the server).
16
+ *
17
+ * ## Adding
18
+ * - Choosing a suggestion (click, or arrows + Enter) emits `dile-input-tags-add` with the object.
19
+ * - Enter with no highlighted suggestion, or the "+" button, emits `dile-input-tags-add` with the
20
+ * typed text and `item: null`.
21
+ * - Nothing is emitted if the text is empty or an equal tag already exists (ignoring case and
22
+ * accents). After emitting, the field is cleared.
23
+ *
24
+ * ## Removing
25
+ * - The button of each `dile-chip` (click, or Enter/Space/Delete/Backspace while focused) emits
26
+ * `dile-input-tags-remove`. Its accessible name is `removeLabel` + the tag text
27
+ * ("Remove Madrid"). Focus then goes back to the field.
28
+ * - Backspace with an empty field emits `dile-input-tags-remove` with the last tag.
29
+ *
30
+ * ## Properties
31
+ * - `tags`: array of assigned objects. Their text comes from `getOptionText` or
32
+ * `displayProperty`, same as the suggestions.
33
+ * - `colorProperty`: name of the property of each tag holding its color (e.g. `"color"`). When
34
+ * the tag has it, its chip uses it as background, with dark text and icon. Empty by default:
35
+ * every tag uses the `--dile-chip-*` colors. For other rules, override `tagChipStyle(tag)`,
36
+ * which returns the inline `style` of each chip.
37
+ * - `removeLabel`: text of each chip remove button, before the tag text ("Remove").
38
+ * - `addLabel`: accessible name of the "+" button ("Add tag").
39
+ * - `tagsLabel`: accessible name of the tags list ("Assigned tags").
40
+ * - `addedAnnouncement(text)` / `removedAnnouncement(text)`: texts announced when `tags` changes.
41
+ * - Plus every dile-input-suggestions property. `minLength` defaults to 1.
42
+ *
43
+ * ## Events
44
+ * - `dile-input-tags-add`: `detail: { name, text, item }`. `item` is the chosen suggestion, or
45
+ * `null` when typed by hand.
46
+ * - `dile-input-tags-remove`: `detail: { name, item }`.
47
+ * - It does not emit `dile-input-suggestions-selected`.
48
+ *
49
+ * ## CSS custom properties
50
+ * - `--dile-input-tags-gap` (0.4rem): space between tags.
51
+ * - `--dile-input-tags-margin-bottom` (0.5rem): space between the tags and the field.
52
+ * - `--dile-input-tags-add-color` (`--dile-input-color` or #303030) and
53
+ * `--dile-input-tags-add-size` (20px): icon of the "+" button.
54
+ * - Tags are styled with the `--dile-chip-*` properties.
55
+ * - `--dile-input-tags-colored-text-color` (#1f2937): text and icon of the tags with their own
56
+ * color (`colorProperty`).
57
+ */
58
+ export const DileInputTagsMixin = (superclass) =>
59
+ class extends superclass {
60
+ static get styles() {
61
+ return [
62
+ super.styles,
63
+ css`
64
+ .tags {
65
+ display: flex;
66
+ flex-wrap: wrap;
67
+ gap: var(--dile-input-tags-gap, 0.4rem);
68
+ margin: 0 0 var(--dile-input-tags-margin-bottom, 0.5rem);
69
+ padding: 0;
70
+ list-style: none;
71
+ }
72
+ .add-button {
73
+ display: flex;
74
+ align-items: center;
75
+ justify-content: center;
76
+ flex-shrink: 0;
77
+ padding: 0;
78
+ border: none;
79
+ background: none;
80
+ cursor: pointer;
81
+ --dile-icon-color: var(--dile-input-tags-add-color, var(--dile-input-color, #303030));
82
+ --dile-icon-size: var(--dile-input-tags-add-size, 20px);
83
+ }
84
+ .add-button:disabled {
85
+ cursor: default;
86
+ opacity: 0.4;
87
+ }
88
+ `,
89
+ ];
90
+ }
91
+
92
+ static get properties() {
93
+ return {
94
+ tags: { type: Array },
95
+ colorProperty: { type: String },
96
+ removeLabel: { type: String },
97
+ addLabel: { type: String },
98
+ tagsLabel: { type: String },
99
+ addedAnnouncement: { type: Object },
100
+ removedAnnouncement: { type: Object },
101
+ };
102
+ }
103
+
104
+ constructor() {
105
+ super();
106
+ this.tags = [];
107
+ this.minLength = 1;
108
+ this.colorProperty = '';
109
+ this.removeLabel = 'Remove';
110
+ this.addLabel = 'Add tag';
111
+ this.tagsLabel = 'Assigned tags';
112
+ this.addedAnnouncement = (text) => `Tag added: ${text}`;
113
+ this.removedAnnouncement = (text) => `Tag removed: ${text}`;
114
+ }
115
+
116
+ willUpdate(changedProperties) {
117
+ super.willUpdate?.(changedProperties);
118
+ if (changedProperties.has('tags')) {
119
+ const previous = changedProperties.get('tags');
120
+ if (Array.isArray(previous)) {
121
+ this.announceTagChanges(previous, this.tags ?? []);
122
+ }
123
+ }
124
+ }
125
+
126
+ announceTagChanges(previous, current) {
127
+ const previousTexts = previous.map((tag) => this.optionText(tag));
128
+ const currentTexts = current.map((tag) => this.optionText(tag));
129
+ const added = currentTexts.filter((text) => !previousTexts.includes(text));
130
+ const removed = previousTexts.filter((text) => !currentTexts.includes(text));
131
+ const messages = [
132
+ ...added.map((text) => this.addedAnnouncement(text)),
133
+ ...removed.map((text) => this.removedAnnouncement(text)),
134
+ ];
135
+ if (messages.length > 0) {
136
+ this._liveAnnouncement = messages.join('. ');
137
+ }
138
+ }
139
+
140
+ renderBeforeField() {
141
+ const tags = this.tags ?? [];
142
+ if (tags.length === 0) {
143
+ return nothing;
144
+ }
145
+ return html`
146
+ <ul class="tags" aria-label="${this.tagsLabel}" @dile-chip-icon-click=${this.onChipIconClick}>
147
+ ${tags.map(
148
+ (tag, index) =>
149
+ html`<li>
150
+ <dile-chip
151
+ name="${index}"
152
+ part="tag"
153
+ icon-label="${this.removeLabel}"
154
+ style="${this.tagChipStyle(tag)}"
155
+ >${this.optionText(tag)}</dile-chip
156
+ >
157
+ </li>`,
158
+ )}
159
+ </ul>
160
+ `;
161
+ }
162
+
163
+ /** Inline `style` of a tag chip: its color, when `colorProperty` points to one. */
164
+ tagChipStyle(tag) {
165
+ const color = this.colorProperty ? tag?.[this.colorProperty] : null;
166
+ if (!color) {
167
+ return '';
168
+ }
169
+ const text = 'var(--dile-input-tags-colored-text-color, #1f2937)';
170
+ return `--dile-chip-background-color: ${color}; --dile-chip-text-color: ${text}; --dile-chip-icon-color: ${text};`;
171
+ }
172
+
173
+ renderFieldEnd() {
174
+ return html`
175
+ <button
176
+ type="button"
177
+ class="add-button"
178
+ aria-label="${this.addLabel}"
179
+ title="${this.addLabel}"
180
+ ?disabled=${this.disabled || !this.typedText}
181
+ @click=${this.onAddClick}
182
+ >
183
+ <dile-icon .icon=${addIcon} aria-hidden="true"></dile-icon>
184
+ </button>
185
+ `;
186
+ }
187
+
188
+ get typedText() {
189
+ return String(this.value ?? '').trim();
190
+ }
191
+
192
+ /** Leaves the already assigned tags out of the suggestions. */
193
+ filterResults(data) {
194
+ return super.filterResults(data).filter((item) => !this.hasTag(this.optionText(item)));
195
+ }
196
+
197
+ hasTag(text) {
198
+ const needle = normalize(text);
199
+ return (this.tags ?? []).some((tag) => normalize(this.optionText(tag)) === needle);
200
+ }
201
+
202
+ onEnterWithoutSuggestion(e) {
203
+ e.preventDefault();
204
+ this.addTyped();
205
+ }
206
+
207
+ onAddClick() {
208
+ this.addTyped();
209
+ this.focus();
210
+ }
211
+
212
+ onKeydown(e) {
213
+ if (e.key === 'Backspace' && this.value === '' && (this.tags ?? []).length > 0) {
214
+ e.preventDefault();
215
+ this.requestRemove(this.tags[this.tags.length - 1]);
216
+ return;
217
+ }
218
+ super.onKeydown(e);
219
+ }
220
+
221
+ /** Adds the text typed by hand. */
222
+ addTyped() {
223
+ const text = this.typedText;
224
+ if (this.disabled || !text) return;
225
+ if (this.hasTag(text)) {
226
+ this.resetField();
227
+ return;
228
+ }
229
+ this.emitAdd(text, null);
230
+ }
231
+
232
+ /** Replaces dile-input-suggestions behavior: adds the tag instead of copying the text. */
233
+ selectItem(item) {
234
+ const text = this.optionText(item);
235
+ if (this.hasTag(text)) {
236
+ this.resetField();
237
+ return;
238
+ }
239
+ this.emitAdd(text, item);
240
+ }
241
+
242
+ emitAdd(text, item) {
243
+ this.resetField();
244
+ if (this.hideErrorOnInput && this.errored) {
245
+ this.clearError();
246
+ }
247
+ this.dispatchEvent(
248
+ new CustomEvent('dile-input-tags-add', {
249
+ bubbles: true,
250
+ composed: true,
251
+ detail: { name: this.name, text, item },
252
+ }),
253
+ );
254
+ }
255
+
256
+ onChipIconClick(e) {
257
+ e.stopPropagation();
258
+ const tag = (this.tags ?? [])[Number(e.detail?.name)];
259
+ if (tag !== undefined) {
260
+ this.requestRemove(tag);
261
+ // The chip is about to disappear: keep the focus from getting lost with it.
262
+ this.focus();
263
+ }
264
+ }
265
+
266
+ requestRemove(item) {
267
+ if (this.disabled) return;
268
+ this.dispatchEvent(
269
+ new CustomEvent('dile-input-tags-remove', {
270
+ bubbles: true,
271
+ composed: true,
272
+ detail: { name: this.name, item },
273
+ }),
274
+ );
275
+ }
276
+
277
+ /** Clears the field and closes the suggestions, discarding requests in progress. */
278
+ resetField() {
279
+ clearTimeout(this._debounceTimeout);
280
+ this._requestId++;
281
+ this.value = '';
282
+ this.keyword = '';
283
+ this.data = [];
284
+ this.loading = false;
285
+ this._keyboardHighlight = false;
286
+ this.select?.close();
287
+ }
288
+ };
@@ -1,5 +1,8 @@
1
1
  import { LitElement, html, css } from 'lit';
2
2
 
3
+ let idCounter = 0;
4
+ const generateId = (prefix) => `${prefix}-${++idCounter}`;
5
+
3
6
  export class DilePages extends LitElement {
4
7
  static get properties() {
5
8
  return {
@@ -11,6 +14,8 @@ export class DilePages extends LitElement {
11
14
  selectorId: { type: String },
12
15
  /** Display to the element that is shown */
13
16
  showDisplay: { type: String },
17
+ /** Tabs mode: marks each page as role="tabpanel" and links it with its dile-tab (same selectorId) */
18
+ tabpanels: { type: Boolean },
14
19
  };
15
20
  }
16
21
  render() {
@@ -26,6 +31,9 @@ export class DilePages extends LitElement {
26
31
  this._pageInitialization();
27
32
  this._onSelectorIdChangedHandler = this._onSelectorIdChanged.bind(this);
28
33
  this.showDisplay = 'block';
34
+ this.tabpanels = false;
35
+ this._ariaPages = new Set();
36
+ this._ariaTabs = new Set();
29
37
  }
30
38
 
31
39
  static get styles() {
@@ -60,6 +68,7 @@ export class DilePages extends LitElement {
60
68
  initializeExternalPages(htmlElements) {
61
69
  this.innerHTML = htmlElements;
62
70
  this._pageInitialization();
71
+ this.linkTabs();
63
72
  }
64
73
 
65
74
  /**
@@ -75,6 +84,7 @@ export class DilePages extends LitElement {
75
84
  if(this.selectorId) {
76
85
  document.addEventListener('dile-selected-changed', this._onSelectorIdChangedHandler);
77
86
  }
87
+ this._linkTabsWhenReady();
78
88
  }
79
89
 
80
90
  disconnectedCallback() {
@@ -96,6 +106,9 @@ export class DilePages extends LitElement {
96
106
  this.hidePage(lastSelected, lastAttrForSelected);
97
107
  }
98
108
  this._showCurrentPage();
109
+ if (this.hasUpdated && (changedProperties.has('tabpanels') || changedProperties.has('attrForSelected') || changedProperties.has('selectorId'))) {
110
+ this.linkTabs();
111
+ }
99
112
  }
100
113
 
101
114
  /**
@@ -175,4 +188,67 @@ export class DilePages extends LitElement {
175
188
  this.selected = e.detail.selected;
176
189
  }
177
190
  }
191
+
192
+ async _linkTabsWhenReady() {
193
+ this.linkTabs();
194
+ const tabs = this._findTabs();
195
+ if (tabs) {
196
+ await customElements.whenDefined('dile-tabs');
197
+ await tabs.updateComplete;
198
+ this.linkTabs();
199
+ }
200
+ }
201
+
202
+ _findTabs() {
203
+ if (!this.selectorId) {
204
+ return null;
205
+ }
206
+ const root = this.getRootNode();
207
+ return [...root.querySelectorAll('dile-tabs')]
208
+ .find((tabs) => tabs.selectorId === this.selectorId || tabs.getAttribute('selectorid') === this.selectorId) ?? null;
209
+ }
210
+
211
+ /**
212
+ * Applies (tabpanels mode) or removes the tab panel semantics on the pages: role="tabpanel",
213
+ * aria-labelledby pointing to the dile-tab and aria-controls from the tab to the page.
214
+ *
215
+ * @return {void}
216
+ */
217
+ linkTabs() {
218
+ this._unlinkTabs();
219
+ if (!this.tabpanels) {
220
+ return;
221
+ }
222
+ const tabs = this._findTabs();
223
+ const tabItems = tabs?.hasUpdated ? tabs.getItems() : [];
224
+ this.pages.forEach((page, index) => {
225
+ page.setAttribute('role', 'tabpanel');
226
+ if (!page.id) {
227
+ page.id = generateId('dile-tabpanel');
228
+ }
229
+ this._ariaPages.add(page);
230
+ const pageValue = this.attrForSelected ? page.getAttribute(this.attrForSelected) : index;
231
+ const tab = tabItems.find((item, tabIndex) => tabs.getItemValueComputed(item, tabIndex) == pageValue);
232
+ if (tab) {
233
+ if (!tab.id) {
234
+ tab.id = generateId('dile-tab');
235
+ }
236
+ page.setAttribute('aria-labelledby', tab.id);
237
+ tab.controlsElement = page;
238
+ this._ariaTabs.add(tab);
239
+ }
240
+ });
241
+ }
242
+
243
+ _unlinkTabs() {
244
+ this._ariaPages.forEach((page) => {
245
+ page.removeAttribute('role');
246
+ page.removeAttribute('aria-labelledby');
247
+ });
248
+ this._ariaTabs.forEach((tab) => {
249
+ tab.controlsElement = undefined;
250
+ });
251
+ this._ariaPages.clear();
252
+ this._ariaTabs.clear();
253
+ }
178
254
  }
@@ -0,0 +1,5 @@
1
+ import { DileColorSelect } from './src/DileColorSelect.js';
2
+
3
+ if (!customElements.get('dile-color-select')) {
4
+ customElements.define('dile-color-select', DileColorSelect);
5
+ }
@@ -5,3 +5,4 @@ export { DileSelectOverlay } from './src/DileSelectOverlay.js';
5
5
  export { DileSelectAjaxOverlay } from './src/DileSelectAjaxOverlay.js';
6
6
  export { DileSelectSearch } from './src/DileSelectSearch.js';
7
7
  export { DileSelectSearchableBase } from './src/DileSelectSearchableBase.js';
8
+ export { DileColorSelect } from './src/DileColorSelect.js';
@@ -0,0 +1,104 @@
1
+ import { html, css } from 'lit';
2
+ import { DileSelectOverlay } from './DileSelectOverlay.js';
3
+
4
+ /**
5
+ * # dile-color-select
6
+ *
7
+ * Select of a color from a closed list. It looks like the other dile-components selects and,
8
+ * like dile-select-overlay (which it extends), shows its options in an overlay: each option
9
+ * displays a swatch of the color and its name. Its `value` is the chosen color (any CSS color
10
+ * string: hex, rgb()...), or `''` when there is no color.
11
+ *
12
+ * Keyboard, ARIA combobox + listbox pattern, form association and the `element-changed` event
13
+ * are inherited from dile-select-overlay. Instead of a slotted `<select>`, the options come from
14
+ * the `colors` property.
15
+ *
16
+ * ## Properties
17
+ * - `colors`: `[{ value: '#fde68a', name: 'Yellow' }, ...]`.
18
+ * - `emptyLabel`: when set, adds a first "no color" option with this name and value `''`.
19
+ * - `value`: the chosen color. It must match one of the `colors` values exactly.
20
+ * - Plus dile-select-overlay's `label`, `name`, `placeholder`, `disabled`, `errored`, `message`,
21
+ * `hideErrorOnInput`, `quietOnStart`, `accessibleLabel`...
22
+ *
23
+ * ## CSS custom properties
24
+ * - `--dile-color-select-swatch-size` (1rem): swatch side.
25
+ * - `--dile-color-select-swatch-border-radius` (50%): swatch radius (50% circle, 0 square).
26
+ * - `--dile-color-select-swatch-border-color` (rgba(0, 0, 0, 0.25)): swatch border.
27
+ * - Plus dile-select-overlay's ones (`--dile-input-*`, `--dile-select-overlay-*`...).
28
+ */
29
+ export class DileColorSelect extends DileSelectOverlay {
30
+ static get styles() {
31
+ return [
32
+ super.styles,
33
+ css`
34
+ .swatch {
35
+ flex: none;
36
+ width: var(--dile-color-select-swatch-size, 1rem);
37
+ height: var(--dile-color-select-swatch-size, 1rem);
38
+ border-radius: var(--dile-color-select-swatch-border-radius, 50%);
39
+ border: 1px solid var(--dile-color-select-swatch-border-color, rgba(0, 0, 0, 0.25));
40
+ }
41
+ .swatch.empty {
42
+ background: linear-gradient(
43
+ to top right,
44
+ transparent calc(50% - 1px),
45
+ var(--dile-color-select-swatch-border-color, rgba(0, 0, 0, 0.25)),
46
+ transparent calc(50% + 1px)
47
+ );
48
+ }
49
+ .option {
50
+ gap: 0.5rem;
51
+ }
52
+ @media (forced-colors: active) {
53
+ .swatch {
54
+ forced-color-adjust: none;
55
+ }
56
+ }
57
+ `,
58
+ ];
59
+ }
60
+
61
+ static get properties() {
62
+ return {
63
+ colors: { type: Array },
64
+ emptyLabel: { type: String },
65
+ };
66
+ }
67
+
68
+ constructor() {
69
+ super();
70
+ this.value = '';
71
+ this.colors = [];
72
+ this.emptyLabel = '';
73
+ }
74
+
75
+ get usesSelectElement() {
76
+ return false;
77
+ }
78
+
79
+ /** The "no color" option (when `emptyLabel` is set) followed by `colors`. */
80
+ get options() {
81
+ const colors = (this.colors ?? []).map((color) => ({ value: color.value, text: color.name }));
82
+ return this.emptyLabel ? [{ value: '', text: this.emptyLabel }, ...colors] : colors;
83
+ }
84
+
85
+ triggerContentTemplate(selected) {
86
+ if (!selected) {
87
+ return super.triggerContentTemplate(selected);
88
+ }
89
+ return html`${this.swatchTemplate(selected.value)}<span class="trigger-label">${selected.text}</span>`;
90
+ }
91
+
92
+ optionContentTemplate(opt, index) {
93
+ if (typeof this.optionRenderer === 'function') {
94
+ return super.optionContentTemplate(opt, index);
95
+ }
96
+ return html`${this.swatchTemplate(opt.value)}<span>${opt.text}</span>`;
97
+ }
98
+
99
+ swatchTemplate(color) {
100
+ return color
101
+ ? html`<span class="swatch" part="swatch" style="background-color: ${color}" aria-hidden="true"></span>`
102
+ : html`<span class="swatch empty" part="swatch" aria-hidden="true"></span>`;
103
+ }
104
+ }
@@ -229,6 +229,15 @@ export class DileSelectOverlay extends DileOverlay(DileCloseDocumentClick(DileEm
229
229
  return this._overlayClass === 'opened' || this._opening;
230
230
  }
231
231
 
232
+ /**
233
+ * Whether the options come from the native `<select>` in the "select" slot (the default).
234
+ * Subclasses that build `options` another way (e.g. dile-color-select, from a `colors`
235
+ * array) return false, so the slotted `<select>` is not required nor observed.
236
+ */
237
+ get usesSelectElement() {
238
+ return true;
239
+ }
240
+
232
241
  get options() {
233
242
  return this.elselect
234
243
  ? Array.from(this.elselect.options).map(o => ({ value: o.value, text: o.textContent, icon: o.dataset.icon || this.elselect.dataset.icon, element: o }))
@@ -241,6 +250,9 @@ export class DileSelectOverlay extends DileOverlay(DileCloseDocumentClick(DileEm
241
250
 
242
251
  connectedCallback() {
243
252
  super.connectedCallback();
253
+ if (!this.usesSelectElement) {
254
+ return;
255
+ }
244
256
  if (!this.elselect) {
245
257
  throw new Error('Use dile-select-overlay with a select element in the slot "select"');
246
258
  }
@@ -279,6 +291,9 @@ export class DileSelectOverlay extends DileOverlay(DileCloseDocumentClick(DileEm
279
291
  firstUpdated() {
280
292
  super.firstUpdated();
281
293
  this.quiet = this.quietOnStart;
294
+ if (!this.elselect) {
295
+ return;
296
+ }
282
297
  if (this.value) {
283
298
  this.elselect.value = this.value;
284
299
  } else {
@@ -363,10 +378,7 @@ export class DileSelectOverlay extends DileOverlay(DileCloseDocumentClick(DileEm
363
378
  @click="${this._onTriggerClick}"
364
379
  @keydown="${this.handleExternalKeydown}"
365
380
  >
366
- <span class="trigger-text ${selected ? '' : 'placeholder'}">
367
- ${selected && selected.icon ? html`<span class="option-icon">${this.renderIconlibIcon(selected.icon)}</span>` : ''}
368
- <span class="trigger-label">${selected ? selected.text : this.placeholder}</span>
369
- </span>
381
+ <span class="trigger-text ${selected ? '' : 'placeholder'}">${this.triggerContentTemplate(selected)}</span>
370
382
  <span class="arrow-icon" aria-hidden="true">
371
383
  <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 256 448" enable-background="new 0 0 256 448">
372
384
  <path d="M255.9 168c0-4.2-1.6-7.9-4.8-11.2-3.2-3.2-6.9-4.8-11.2-4.8H16c-4.2 0-7.9 1.6-11.2 4.8S0 163.8 0 168c0 4.4 1.6 8.2 4.8 11.4l112 112c3.1 3.1 6.8 4.6 11.2 4.6 4.4 0 8.2-1.5 11.4-4.6l112-112c3-3.2 4.5-7 4.5-11.4z"></path>
@@ -401,6 +413,14 @@ export class DileSelectOverlay extends DileOverlay(DileCloseDocumentClick(DileEm
401
413
  `;
402
414
  }
403
415
 
416
+ /**
417
+ * Content of the trigger: the selected option (icon + text) or the placeholder. Subclasses
418
+ * can override it to show the selected option differently (e.g. a color swatch).
419
+ */
420
+ triggerContentTemplate(selected) {
421
+ return html`${selected && selected.icon ? html`<span class="option-icon">${this.renderIconlibIcon(selected.icon)}</span>` : ''}<span class="trigger-label">${selected ? selected.text : this.placeholder}</span>`;
422
+ }
423
+
404
424
  /** Content of each <li role="option">: optionRenderer's output when set, icon + text otherwise. */
405
425
  optionContentTemplate(opt, index) {
406
426
  if (typeof this.optionRenderer === 'function') {
@@ -569,6 +589,7 @@ export class DileSelectOverlay extends DileOverlay(DileCloseDocumentClick(DileEm
569
589
  close() {
570
590
  super.close();
571
591
  this._activeIndex = -1;
592
+ this.highlightedText = '';
572
593
  }
573
594
 
574
595
  clear() {
@@ -576,6 +597,9 @@ export class DileSelectOverlay extends DileOverlay(DileCloseDocumentClick(DileEm
576
597
  }
577
598
 
578
599
  getOptionByValue(id) {
600
+ if (!this.elselect) {
601
+ return undefined;
602
+ }
579
603
  let options = this.elselect.options;
580
604
  for (let i = 0; i < options.length; i++) {
581
605
  if (options[i].value === id) {
@@ -0,0 +1 @@
1
+ export { DileSortable, moveItem } from './src/DileSortable.js';
@@ -0,0 +1,5 @@
1
+ import { DileSortable } from './src/DileSortable.js';
2
+
3
+ if (!customElements.get('dile-sortable')) {
4
+ customElements.define('dile-sortable', DileSortable);
5
+ }