@vaadin/multi-select-combo-box 23.1.0-alpha2

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,34 @@
1
+ /**
2
+ * @license
3
+ * Copyright (c) 2021 - 2022 Vaadin Ltd.
4
+ * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
+ */
6
+ import { ComboBoxOverlay } from '@vaadin/combo-box/src/vaadin-combo-box-overlay.js';
7
+ import { css, registerStyles } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mixin.js';
8
+
9
+ registerStyles(
10
+ 'vaadin-multi-select-combo-box-overlay',
11
+ css`
12
+ #overlay {
13
+ width: var(
14
+ --vaadin-multi-select-combo-box-overlay-width,
15
+ var(--_vaadin-multi-select-combo-box-overlay-default-width, auto)
16
+ );
17
+ }
18
+ `,
19
+ { moduleId: 'vaadin-multi-select-combo-box-overlay-styles' }
20
+ );
21
+
22
+ /**
23
+ * An element used internally by `<vaadin-multi-select-combo-box>`. Not intended to be used separately.
24
+ *
25
+ * @extends ComboBoxOverlay
26
+ * @private
27
+ */
28
+ class MultiSelectComboBoxOverlay extends ComboBoxOverlay {
29
+ static get is() {
30
+ return 'vaadin-multi-select-combo-box-overlay';
31
+ }
32
+ }
33
+
34
+ customElements.define(MultiSelectComboBoxOverlay.is, MultiSelectComboBoxOverlay);
@@ -0,0 +1,31 @@
1
+ /**
2
+ * @license
3
+ * Copyright (c) 2021 - 2022 Vaadin Ltd.
4
+ * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
+ */
6
+ import { ComboBoxPlaceholder } from '@vaadin/combo-box/src/vaadin-combo-box-placeholder.js';
7
+ import { ComboBoxScroller } from '@vaadin/combo-box/src/vaadin-combo-box-scroller.js';
8
+
9
+ /**
10
+ * An element used internally by `<vaadin-multi-select-combo-box>`. Not intended to be used separately.
11
+ *
12
+ * @extends ComboBoxScroller
13
+ * @private
14
+ */
15
+ class MultiSelectComboBoxScroller extends ComboBoxScroller {
16
+ static get is() {
17
+ return 'vaadin-multi-select-combo-box-scroller';
18
+ }
19
+
20
+ /** @private */
21
+ __isItemSelected(item, _selectedItem, itemIdPath) {
22
+ if (item instanceof ComboBoxPlaceholder) {
23
+ return false;
24
+ }
25
+
26
+ const host = this.comboBox.getRootNode().host;
27
+ return host._findIndex(item, host.selectedItems, itemIdPath) > -1;
28
+ }
29
+ }
30
+
31
+ customElements.define(MultiSelectComboBoxScroller.is, MultiSelectComboBoxScroller);
@@ -0,0 +1,254 @@
1
+ /**
2
+ * @license
3
+ * Copyright (c) 2021 - 2022 Vaadin Ltd.
4
+ * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
+ */
6
+ import { ComboBoxDataProvider, ComboBoxDefaultItem, ComboBoxRenderer } from '@vaadin/combo-box/src/vaadin-combo-box.js';
7
+ import { ControllerMixinClass } from '@vaadin/component-base/src/controller-mixin.js';
8
+ import { DisabledMixinClass } from '@vaadin/component-base/src/disabled-mixin.js';
9
+ import { ElementMixinClass } from '@vaadin/component-base/src/element-mixin.js';
10
+ import { FocusMixinClass } from '@vaadin/component-base/src/focus-mixin.js';
11
+ import { KeyboardMixinClass } from '@vaadin/component-base/src/keyboard-mixin.js';
12
+ import { DelegateFocusMixinClass } from '@vaadin/field-base/src/delegate-focus-mixin.js';
13
+ import { DelegateStateMixinClass } from '@vaadin/field-base/src/delegate-state-mixin.js';
14
+ import { FieldMixinClass } from '@vaadin/field-base/src/field-mixin.js';
15
+ import { InputConstraintsMixinClass } from '@vaadin/field-base/src/input-constraints-mixin.js';
16
+ import { InputControlMixinClass } from '@vaadin/field-base/src/input-control-mixin.js';
17
+ import { InputMixinClass } from '@vaadin/field-base/src/input-mixin.js';
18
+ import { LabelMixinClass } from '@vaadin/field-base/src/label-mixin.js';
19
+ import { ValidateMixinClass } from '@vaadin/field-base/src/validate-mixin.js';
20
+ import { ThemableMixinClass } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mixin.js';
21
+
22
+ /**
23
+ * Fired when the user commits a value change.
24
+ */
25
+ export type MultiSelectComboBoxChangeEvent<TItem> = Event & {
26
+ target: MultiSelectComboBox<TItem>;
27
+ };
28
+
29
+ /**
30
+ * Fired when the user sets a custom value.
31
+ */
32
+ export type MultiSelectComboBoxCustomValuesSetEvent = CustomEvent<string>;
33
+
34
+ /**
35
+ * Fired when the `filter` property changes.
36
+ */
37
+ export type MultiSelectComboBoxFilterChangedEvent = CustomEvent<{ value: string }>;
38
+
39
+ /**
40
+ * Fired when the `invalid` property changes.
41
+ */
42
+ export type MultiSelectComboBoxInvalidChangedEvent = CustomEvent<{ value: boolean }>;
43
+
44
+ /**
45
+ * Fired when the `selectedItems` property changes.
46
+ */
47
+ export type MultiSelectComboBoxSelectedItemsChangedEvent<TItem> = CustomEvent<{ value: Array<TItem> }>;
48
+
49
+ export interface MultiSelectComboBoxEventMap<TItem> extends HTMLElementEventMap {
50
+ change: MultiSelectComboBoxChangeEvent<TItem>;
51
+
52
+ 'custom-values-set': MultiSelectComboBoxCustomValuesSetEvent;
53
+
54
+ 'filter-changed': MultiSelectComboBoxFilterChangedEvent;
55
+
56
+ 'invalid-changed': MultiSelectComboBoxInvalidChangedEvent;
57
+
58
+ 'selected-items-changed': MultiSelectComboBoxSelectedItemsChangedEvent<TItem>;
59
+ }
60
+
61
+ /**
62
+ * `<vaadin-multi-select-combo-box>` is a web component that wraps `<vaadin-combo-box>` and extends
63
+ * its functionality to allow selecting multiple items, in addition to basic features.
64
+ *
65
+ * ```html
66
+ * <vaadin-multi-select-combo-box id="comboBox"></vaadin-multi-select-combo-box>
67
+ * ```
68
+ *
69
+ * ```js
70
+ * const comboBox = document.querySelector('#comboBox');
71
+ * comboBox.items = ['apple', 'banana', 'lemon', 'orange'];
72
+ * comboBox.selectedItems = ['lemon', 'orange'];
73
+ * ```
74
+ *
75
+ * ### Styling
76
+ *
77
+ * The following shadow DOM parts are available for styling:
78
+ *
79
+ * Part name | Description
80
+ * -----------------------|----------------
81
+ * `chip` | Chip shown for every selected item
82
+ * `label` | The label element
83
+ * `input-field` | The element that wraps prefix, value and suffix
84
+ * `clear-button` | The clear button
85
+ * `error-message` | The error message element
86
+ * `helper-text` | The helper text element wrapper
87
+ * `required-indicator` | The `required` state indicator element
88
+ * `toggle-button` | The toggle button
89
+ *
90
+ * The following state attributes are available for styling:
91
+ *
92
+ * Attribute | Description
93
+ * -----------------------|-----------------
94
+ * `disabled` | Set to a disabled element
95
+ * `has-value` | Set when the element has a value
96
+ * `has-label` | Set when the element has a label
97
+ * `has-helper` | Set when the element has helper text or slot
98
+ * `has-error-message` | Set when the element has an error message
99
+ * `invalid` | Set when the element is invalid
100
+ * `focused` | Set when the element is focused
101
+ * `focus-ring` | Set when the element is keyboard focused
102
+ * `opened` | Set when the dropdown is open
103
+ * `readonly` | Set to a readonly element
104
+ *
105
+ * ### Internal components
106
+ *
107
+ * In addition to `<vaadin-multi-select-combo-box>` itself, the following internal
108
+ * components are themable:
109
+ *
110
+ * - `<vaadin-multi-select-combo-box-overlay>` - has the same API as `<vaadin-overlay>`.
111
+ * - `<vaadin-multi-select-combo-box-item>` - has the same API as `<vaadin-item>`.
112
+ * - `<vaadin-multi-select-combo-box-container>` - has the same API as `<vaadin-input-container>`.
113
+ *
114
+ * Note: the `theme` attribute value set on `<vaadin-multi-select-combo-box>` is
115
+ * propagated to these components.
116
+ *
117
+ * See [Styling Components](https://vaadin.com/docs/latest/ds/customization/styling-components) documentation.
118
+ *
119
+ * @fires {Event} change - Fired when the user commits a value change.
120
+ * @fires {CustomEvent} custom-values-set - Fired when the user sets a custom value.
121
+ * @fires {CustomEvent} filter-changed - Fired when the `filter` property changes.
122
+ * @fires {CustomEvent} invalid-changed - Fired when the `invalid` property changes.
123
+ * @fires {CustomEvent} selected-items-changed - Fired when the `selectedItems` property changes.
124
+ */
125
+ declare class MultiSelectComboBox<TItem = ComboBoxDefaultItem> extends HTMLElement {
126
+ /**
127
+ * When true, the user can input a value that is not present in the items list.
128
+ * @attr {boolean} allow-custom-values
129
+ */
130
+ allowCustomValues: boolean;
131
+
132
+ /**
133
+ * Set true to prevent the overlay from opening automatically.
134
+ * @attr {boolean} auto-open-disabled
135
+ */
136
+ autoOpenDisabled: boolean;
137
+
138
+ /**
139
+ * Function that provides items lazily. Receives two arguments:
140
+ *
141
+ * - `params` - Object with the following properties:
142
+ * - `params.page` Requested page index
143
+ * - `params.pageSize` Current page size
144
+ * - `params.filter` Currently applied filter
145
+ *
146
+ * - `callback(items, size)` - Callback function with arguments:
147
+ * - `items` Current page of items
148
+ * - `size` Total number of items.
149
+ */
150
+ dataProvider: ComboBoxDataProvider<TItem> | null | undefined;
151
+
152
+ /**
153
+ * A subset of items, filtered based on the user input. Filtered items
154
+ * can be assigned directly to omit the internal filtering functionality.
155
+ * The items can be of either `String` or `Object` type.
156
+ */
157
+ filteredItems: Array<TItem> | undefined;
158
+
159
+ /**
160
+ * Filtering string the user has typed into the input field.
161
+ */
162
+ filter: string;
163
+
164
+ /**
165
+ * A full set of items to filter the visible options from.
166
+ * The items can be of either `String` or `Object` type.
167
+ */
168
+ items: Array<TItem> | undefined;
169
+
170
+ /**
171
+ * The item property used for a visual representation of the item.
172
+ * @attr {string} item-label-path
173
+ */
174
+ itemLabelPath: string;
175
+
176
+ /**
177
+ * Path for the id of the item, used to detect whether the item is selected.
178
+ * @attr {string} item-id-path
179
+ */
180
+ itemIdPath: string;
181
+
182
+ /**
183
+ * Path for the value of the item. If `items` is an array of objects,
184
+ * this property is used as a string value for the selected item.
185
+ * @attr {string} item-value-path
186
+ */
187
+ itemValuePath: string;
188
+
189
+ /**
190
+ * True if the dropdown is open, false otherwise.
191
+ */
192
+ opened: boolean;
193
+
194
+ /**
195
+ * Number of items fetched at a time from the data provider.
196
+ * @attr {number} page-size
197
+ */
198
+ pageSize: number;
199
+
200
+ /**
201
+ * Custom function for rendering the content of every item.
202
+ * Receives three arguments:
203
+ *
204
+ * - `root` The `<vaadin-multi-select-combo-box-item>` internal container DOM element.
205
+ * - `comboBox` The reference to the `<vaadin-combo-box>` element.
206
+ * - `model` The object with the properties related with the rendered
207
+ * item, contains:
208
+ * - `model.index` The index of the rendered item.
209
+ * - `model.item` The item.
210
+ */
211
+ renderer: ComboBoxRenderer<TItem> | null | undefined;
212
+
213
+ /**
214
+ * The list of selected items.
215
+ * Note: modifying the selected items creates a new array each time.
216
+ */
217
+ selectedItems: Array<TItem>;
218
+
219
+ addEventListener<K extends keyof MultiSelectComboBoxEventMap<TItem>>(
220
+ type: K,
221
+ listener: (this: MultiSelectComboBox<TItem>, ev: MultiSelectComboBoxEventMap<TItem>[K]) => void,
222
+ options?: boolean | AddEventListenerOptions
223
+ ): void;
224
+
225
+ removeEventListener<K extends keyof MultiSelectComboBoxEventMap<TItem>>(
226
+ type: K,
227
+ listener: (this: MultiSelectComboBox<TItem>, ev: MultiSelectComboBoxEventMap<TItem>[K]) => void,
228
+ options?: boolean | EventListenerOptions
229
+ ): void;
230
+ }
231
+
232
+ interface MultiSelectComboBox
233
+ extends ValidateMixinClass,
234
+ LabelMixinClass,
235
+ KeyboardMixinClass,
236
+ InputMixinClass,
237
+ InputControlMixinClass,
238
+ InputConstraintsMixinClass,
239
+ FocusMixinClass,
240
+ FieldMixinClass,
241
+ DisabledMixinClass,
242
+ DelegateStateMixinClass,
243
+ DelegateFocusMixinClass,
244
+ ThemableMixinClass,
245
+ ElementMixinClass,
246
+ ControllerMixinClass {}
247
+
248
+ declare global {
249
+ interface HTMLElementTagNameMap {
250
+ 'vaadin-multi-select-combo-box': MultiSelectComboBox;
251
+ }
252
+ }
253
+
254
+ export { MultiSelectComboBox };