@vaadin/select 23.1.0-alpha3 → 23.1.0-beta2

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/lit.d.ts ADDED
@@ -0,0 +1 @@
1
+ export * from './src/lit/renderer-directives.js';
package/lit.js ADDED
@@ -0,0 +1 @@
1
+ export * from './src/lit/renderer-directives.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vaadin/select",
3
- "version": "23.1.0-alpha3",
3
+ "version": "23.1.0-beta2",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -22,6 +22,8 @@
22
22
  "files": [
23
23
  "src",
24
24
  "theme",
25
+ "lit.js",
26
+ "lit.d.ts",
25
27
  "vaadin-*.d.ts",
26
28
  "vaadin-*.js"
27
29
  ],
@@ -34,24 +36,25 @@
34
36
  ],
35
37
  "dependencies": {
36
38
  "@polymer/polymer": "^3.2.0",
37
- "@vaadin/button": "23.1.0-alpha3",
38
- "@vaadin/component-base": "23.1.0-alpha3",
39
- "@vaadin/field-base": "23.1.0-alpha3",
40
- "@vaadin/input-container": "23.1.0-alpha3",
41
- "@vaadin/item": "23.1.0-alpha3",
42
- "@vaadin/list-box": "23.1.0-alpha3",
43
- "@vaadin/vaadin-list-mixin": "23.1.0-alpha3",
44
- "@vaadin/vaadin-lumo-styles": "23.1.0-alpha3",
45
- "@vaadin/vaadin-material-styles": "23.1.0-alpha3",
46
- "@vaadin/vaadin-overlay": "23.1.0-alpha3",
47
- "@vaadin/vaadin-themable-mixin": "23.1.0-alpha3"
39
+ "@vaadin/button": "23.1.0-beta2",
40
+ "@vaadin/component-base": "23.1.0-beta2",
41
+ "@vaadin/field-base": "23.1.0-beta2",
42
+ "@vaadin/input-container": "23.1.0-beta2",
43
+ "@vaadin/item": "23.1.0-beta2",
44
+ "@vaadin/list-box": "23.1.0-beta2",
45
+ "@vaadin/lit-renderer": "23.1.0-beta2",
46
+ "@vaadin/vaadin-list-mixin": "23.1.0-beta2",
47
+ "@vaadin/vaadin-lumo-styles": "23.1.0-beta2",
48
+ "@vaadin/vaadin-material-styles": "23.1.0-beta2",
49
+ "@vaadin/vaadin-overlay": "23.1.0-beta2",
50
+ "@vaadin/vaadin-themable-mixin": "23.1.0-beta2"
48
51
  },
49
52
  "devDependencies": {
50
53
  "@esm-bundle/chai": "^4.3.4",
51
- "@vaadin/polymer-legacy-adapter": "23.1.0-alpha3",
54
+ "@vaadin/polymer-legacy-adapter": "23.1.0-beta2",
52
55
  "@vaadin/testing-helpers": "^0.3.2",
53
56
  "lit": "^2.0.0",
54
57
  "sinon": "^13.0.2"
55
58
  },
56
- "gitHead": "8c9e64e8dfa158dd52a9bf6da351ff038c88ca85"
59
+ "gitHead": "f11f9245a0b5e6bf912725a501c27c24b74e7c8d"
57
60
  }
@@ -0,0 +1,59 @@
1
+ /**
2
+ * @license
3
+ * Copyright (c) 2017 - 2022 Vaadin Ltd.
4
+ * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
+ */
6
+ import { TemplateResult } from 'lit';
7
+ import { DirectiveResult } from 'lit/directive.js';
8
+ import { LitRendererDirective } from '@vaadin/lit-renderer';
9
+ import { Select } from '../vaadin-select.js';
10
+
11
+ export type SelectLitRenderer = (select: Select) => TemplateResult;
12
+
13
+ export class SelectRendererDirective extends LitRendererDirective<Select, SelectLitRenderer> {
14
+ /**
15
+ * Adds the renderer callback to the select.
16
+ */
17
+ addRenderer(): void;
18
+
19
+ /**
20
+ * Runs the renderer callback on the select.
21
+ */
22
+ runRenderer(): void;
23
+
24
+ /**
25
+ * Removes the renderer callback from the select.
26
+ */
27
+ removeRenderer(): void;
28
+ }
29
+
30
+ /**
31
+ * A Lit directive for populating the content of the `<vaadin-select-overlay>` element.
32
+ *
33
+ * The directive accepts a renderer callback returning a Lit template and assigns it to the select
34
+ * via the `renderer` property. The renderer is called once to populate the content when assigned
35
+ * and whenever a single dependency or an array of dependencies changes.
36
+ * It is not guaranteed that the renderer will be called immediately (synchronously) in both cases.
37
+ *
38
+ * Dependencies can be a single value or an array of values.
39
+ * Values are checked against previous values with strict equality (`===`),
40
+ * so the check won't detect nested property changes inside objects or arrays.
41
+ * When dependencies are provided as an array, each item is checked against the previous value
42
+ * at the same index with strict equality. Nested arrays are also checked only by strict
43
+ * equality.
44
+ *
45
+ * Example of usage:
46
+ * ```js
47
+ * `<vaadin-select
48
+ * ${selectRenderer((select) => html`...`)}
49
+ * ></vaadin-select>`
50
+ * ```
51
+ *
52
+ * @param renderer the renderer callback that returns a Lit template.
53
+ * @param dependencies a single dependency or an array of dependencies
54
+ * which trigger a re-render when changed.
55
+ */
56
+ export declare function selectRenderer(
57
+ renderer: SelectLitRenderer,
58
+ dependencies?: unknown,
59
+ ): DirectiveResult<typeof SelectRendererDirective>;
@@ -0,0 +1,60 @@
1
+ /**
2
+ * @license
3
+ * Copyright (c) 2017 - 2022 Vaadin Ltd.
4
+ * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
+ */
6
+ import { directive } from 'lit/directive.js';
7
+ import { LitRendererDirective } from '@vaadin/lit-renderer';
8
+
9
+ export class SelectRendererDirective extends LitRendererDirective {
10
+ /**
11
+ * Adds the renderer callback to the select.
12
+ */
13
+ addRenderer() {
14
+ this.element.renderer = (root, select) => {
15
+ this.renderRenderer(root, select);
16
+ };
17
+ }
18
+
19
+ /**
20
+ * Runs the renderer callback on the select.
21
+ */
22
+ runRenderer() {
23
+ this.element.requestContentUpdate();
24
+ }
25
+
26
+ /**
27
+ * Removes the renderer callback from the select.
28
+ */
29
+ removeRenderer() {
30
+ this.element.renderer = null;
31
+ }
32
+ }
33
+
34
+ /**
35
+ * A Lit directive for populating the content of the `<vaadin-select-overlay>` element.
36
+ *
37
+ * The directive accepts a renderer callback returning a Lit template and assigns it to the select
38
+ * via the `renderer` property. The renderer is called once to populate the content when assigned
39
+ * and whenever a single dependency or an array of dependencies changes.
40
+ * It is not guaranteed that the renderer will be called immediately (synchronously) in both cases.
41
+ *
42
+ * Dependencies can be a single value or an array of values.
43
+ * Values are checked against previous values with strict equality (`===`),
44
+ * so the check won't detect nested property changes inside objects or arrays.
45
+ * When dependencies are provided as an array, each item is checked against the previous value
46
+ * at the same index with strict equality. Nested arrays are also checked only by strict
47
+ * equality.
48
+ *
49
+ * Example of usage:
50
+ * ```js
51
+ * `<vaadin-select
52
+ * ${selectRenderer((select) => html`...`)}
53
+ * ></vaadin-select>`
54
+ * ```
55
+ *
56
+ * @param renderer the renderer callback that returns a Lit template.
57
+ * @param dependencies a single dependency or an array of dependencies
58
+ * which trigger a re-render when changed.
59
+ */
60
+ export const selectRenderer = directive(SelectRendererDirective);
@@ -15,7 +15,7 @@ registerStyles(
15
15
  justify-content: flex-start;
16
16
  }
17
17
  `,
18
- { moduleId: 'vaadin-select-overlay-styles' }
18
+ { moduleId: 'vaadin-select-overlay-styles' },
19
19
  );
20
20
 
21
21
  /**
@@ -255,13 +255,13 @@ declare class Select extends DelegateFocusMixin(FieldMixin(SlotMixin(ElementMixi
255
255
  addEventListener<K extends keyof SelectEventMap>(
256
256
  type: K,
257
257
  listener: (this: Select, ev: SelectEventMap[K]) => void,
258
- options?: boolean | AddEventListenerOptions
258
+ options?: boolean | AddEventListenerOptions,
259
259
  ): void;
260
260
 
261
261
  removeEventListener<K extends keyof SelectEventMap>(
262
262
  type: K,
263
263
  listener: (this: Select, ev: SelectEventMap[K]) => void,
264
- options?: boolean | EventListenerOptions
264
+ options?: boolean | EventListenerOptions,
265
265
  ): void;
266
266
  }
267
267
 
@@ -208,7 +208,7 @@ class Select extends DelegateFocusMixin(FieldMixin(SlotMixin(ElementMixin(Themab
208
208
  */
209
209
  items: {
210
210
  type: Array,
211
- observer: '__itemsChanged'
211
+ observer: '__itemsChanged',
212
212
  },
213
213
 
214
214
  /**
@@ -220,7 +220,7 @@ class Select extends DelegateFocusMixin(FieldMixin(SlotMixin(ElementMixin(Themab
220
220
  value: false,
221
221
  notify: true,
222
222
  reflectToAttribute: true,
223
- observer: '_openedChanged'
223
+ observer: '_openedChanged',
224
224
  },
225
225
 
226
226
  /**
@@ -252,14 +252,14 @@ class Select extends DelegateFocusMixin(FieldMixin(SlotMixin(ElementMixin(Themab
252
252
  type: String,
253
253
  value: '',
254
254
  notify: true,
255
- observer: '_valueChanged'
255
+ observer: '_valueChanged',
256
256
  },
257
257
 
258
258
  /**
259
259
  * The name of this element.
260
260
  */
261
261
  name: {
262
- type: String
262
+ type: String,
263
263
  },
264
264
 
265
265
  /**
@@ -270,7 +270,7 @@ class Select extends DelegateFocusMixin(FieldMixin(SlotMixin(ElementMixin(Themab
270
270
  * DOM content is empty.
271
271
  */
272
272
  placeholder: {
273
- type: String
273
+ type: String,
274
274
  },
275
275
 
276
276
  /**
@@ -280,7 +280,7 @@ class Select extends DelegateFocusMixin(FieldMixin(SlotMixin(ElementMixin(Themab
280
280
  readonly: {
281
281
  type: Boolean,
282
282
  value: false,
283
- reflectToAttribute: true
283
+ reflectToAttribute: true,
284
284
  },
285
285
 
286
286
  /** @private */
@@ -288,7 +288,7 @@ class Select extends DelegateFocusMixin(FieldMixin(SlotMixin(ElementMixin(Themab
288
288
 
289
289
  /** @private */
290
290
  _phoneMediaQuery: {
291
- value: '(max-width: 420px), (max-height: 420px)'
291
+ value: '(max-width: 420px), (max-height: 420px)',
292
292
  },
293
293
 
294
294
  /** @private */
@@ -298,7 +298,7 @@ class Select extends DelegateFocusMixin(FieldMixin(SlotMixin(ElementMixin(Themab
298
298
  _inputContainer: Object,
299
299
 
300
300
  /** @private */
301
- _items: Object
301
+ _items: Object,
302
302
  };
303
303
  }
304
304
 
@@ -307,7 +307,7 @@ class Select extends DelegateFocusMixin(FieldMixin(SlotMixin(ElementMixin(Themab
307
307
  '_updateAriaExpanded(opened)',
308
308
  '_updateAriaRequired(required)',
309
309
  '_updateSelectedItem(value, _items, placeholder)',
310
- '_rendererChanged(renderer, _overlayElement)'
310
+ '_rendererChanged(renderer, _overlayElement)',
311
311
  ];
312
312
  }
313
313
 
@@ -319,7 +319,7 @@ class Select extends DelegateFocusMixin(FieldMixin(SlotMixin(ElementMixin(Themab
319
319
  const button = document.createElement('vaadin-select-value-button');
320
320
  button.setAttribute('aria-haspopup', 'listbox');
321
321
  return button;
322
- }
322
+ },
323
323
  };
324
324
  }
325
325
 
@@ -375,7 +375,7 @@ class Select extends DelegateFocusMixin(FieldMixin(SlotMixin(ElementMixin(Themab
375
375
  this.addController(
376
376
  new MediaQueryController(this._phoneMediaQuery, (matches) => {
377
377
  this._phone = matches;
378
- })
378
+ }),
379
379
  );
380
380
 
381
381
  processTemplates(this);
@@ -450,7 +450,7 @@ class Select extends DelegateFocusMixin(FieldMixin(SlotMixin(ElementMixin(Themab
450
450
  this.__userInteraction = true;
451
451
  this.opened = false;
452
452
  },
453
- true
453
+ true,
454
454
  );
455
455
 
456
456
  menuElement.setAttribute('role', 'listbox');
@@ -535,7 +535,7 @@ class Select extends DelegateFocusMixin(FieldMixin(SlotMixin(ElementMixin(Themab
535
535
 
536
536
  this._overlayElement.style.setProperty(
537
537
  '--vaadin-select-text-field-width',
538
- this._inputContainer.offsetWidth + 'px'
538
+ `${this._inputContainer.offsetWidth}px`,
539
539
  );
540
540
 
541
541
  // Preserve focus-ring to restore it later
@@ -593,12 +593,12 @@ class Select extends DelegateFocusMixin(FieldMixin(SlotMixin(ElementMixin(Themab
593
593
  labelItem = selected.cloneNode(true);
594
594
  }
595
595
 
596
- // store reference to the original item
596
+ // Store reference to the original item
597
597
  labelItem._sourceItem = selected;
598
598
 
599
599
  this.__appendValueItemElement(labelItem);
600
600
 
601
- // ensure the item gets proper styles
601
+ // Ensure the item gets proper styles
602
602
  labelItem.selected = true;
603
603
  }
604
604
 
@@ -76,7 +76,7 @@ registerStyles(
76
76
  background-color: transparent;
77
77
  }
78
78
  `,
79
- { moduleId: 'lumo-select-value-button' }
79
+ { moduleId: 'lumo-select-value-button' },
80
80
  );
81
81
 
82
82
  const selectOverlay = css`
@@ -58,7 +58,7 @@ registerStyles(
58
58
  background-color: transparent;
59
59
  }
60
60
  `,
61
- { moduleId: 'material-select-value-button' }
61
+ { moduleId: 'material-select-value-button' },
62
62
  );
63
63
 
64
64
  const selectOverlay = css`