ngx-virtual-select-field-filterable 1.4.0
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/README.md +363 -0
- package/fesm2022/ngx-virtual-select-field-filterable.mjs +877 -0
- package/fesm2022/ngx-virtual-select-field-filterable.mjs.map +1 -0
- package/index.d.ts +1 -0
- package/lib/virtual-select-field/index.d.ts +10 -0
- package/lib/virtual-select-field/keycodes.d.ts +7 -0
- package/lib/virtual-select-field/virtual-select-field-option/index.d.ts +3 -0
- package/lib/virtual-select-field/virtual-select-field-option/virtual-select-field-option.component.d.ts +36 -0
- package/lib/virtual-select-field/virtual-select-field-option/virtual-select-field-option.models.d.ts +5 -0
- package/lib/virtual-select-field/virtual-select-field-option-for/index.d.ts +2 -0
- package/lib/virtual-select-field/virtual-select-field-option-for/virtual-select-field-option-for.directive.d.ts +17 -0
- package/lib/virtual-select-field/virtual-select-field-option-for/virtual-select-field-option-for.models.d.ts +14 -0
- package/lib/virtual-select-field/virtual-select-field-trigger/index.d.ts +1 -0
- package/lib/virtual-select-field/virtual-select-field-trigger/virtual-select-field-trigger.directive.d.ts +7 -0
- package/lib/virtual-select-field/virtual-select-field.component.d.ts +187 -0
- package/lib/virtual-select-field/virtual-select-field.constants.d.ts +8 -0
- package/lib/virtual-select-field/virtual-select-field.models.d.ts +18 -0
- package/package.json +54 -0
- package/theme/index.scss +151 -0
package/README.md
ADDED
|
@@ -0,0 +1,363 @@
|
|
|
1
|
+
<span><a href="https://www.npmjs.com/package/ngx-virtual-select-field" title="View this project on NPM">
|
|
2
|
+
</a></span>
|
|
3
|
+
<span><a href="https://github.com/Vizer/ngx-virtual-select-field/actions/workflows/node.js.yml" title="View this project workflow">
|
|
4
|
+
</a></span>
|
|
5
|
+
|
|
6
|
+
# Virtual Select component for Angular Material Form Field
|
|
7
|
+
|
|
8
|
+
## Table of contents
|
|
9
|
+
|
|
10
|
+
- [Description](#description)
|
|
11
|
+
- [Getting started](#getting-started)
|
|
12
|
+
- [Examples](#examples)
|
|
13
|
+
- [Customization](#customization)
|
|
14
|
+
- [API](#api)
|
|
15
|
+
- [NgxVirtualSelectFieldComponent<TValue>](#ngxvirtualselectfieldcomponenttvalue)
|
|
16
|
+
- [NgxVirtualSelectFieldOptionComponent<TValue>](#ngxvirtualselectfieldoptioncomponenttvalue)
|
|
17
|
+
- [NgxVirtualSelectFieldOptionSelectionChangeEvent<TValue>](#ngxvirtualselectfieldoptionselectionchangetvalue)
|
|
18
|
+
- [NgxVirtualSelectFieldTriggerComponent](#ngxvirtualselectfieldtriggercomponent)
|
|
19
|
+
- [NgxVirtualSelectFieldOptionForDirective](#ngxvirtualselectfieldoptionfordirective)
|
|
20
|
+
- [NgxVirtualSelectFieldOptionModel<TValue>](#ngxvirtualselectfieldoptionmodeltvalue)
|
|
21
|
+
- [NGX_VIRTUAL_SELECT_FIELD_CONFIG](#ngx_virtual_select_field_config)
|
|
22
|
+
- [NgxVirtualSelectFieldConfig](#ngxvirtualselectfieldconfig)
|
|
23
|
+
- [CSS variables](#css-variables)
|
|
24
|
+
|
|
25
|
+
## Description
|
|
26
|
+
|
|
27
|
+
This package replicates the Angular Material Select component with virtual scroll capabilities with help of cdk-virtual-scroll. It provides most major features of the original Angular Material Select component. The goal of this package is to provide similar api and features as the original Angular Material Select component but with virtual scroll capabilities. One major difference is that this package does not support option groups at the moment. Also, this requires own structural directive to be used for options in order to provide virtual scroll capabilities and custom template.
|
|
28
|
+
|
|
29
|
+
Features:
|
|
30
|
+
|
|
31
|
+
- Virtual scroll
|
|
32
|
+
- Multi select
|
|
33
|
+
- Single select
|
|
34
|
+
- Filterable options with search input
|
|
35
|
+
- Integrates with Angular Material Form Field
|
|
36
|
+
- Custom trigger template
|
|
37
|
+
- Custom option template
|
|
38
|
+
- Keyboard navigation and shortcuts
|
|
39
|
+
- Theming trough css variables
|
|
40
|
+
|
|
41
|
+
Not Supported Features for now:
|
|
42
|
+
|
|
43
|
+
- Animations
|
|
44
|
+
- Custom Error state mather
|
|
45
|
+
- Custom scroll strategy
|
|
46
|
+
- Accessibility
|
|
47
|
+
- Option groups
|
|
48
|
+
|
|
49
|
+
[Demo](https://stackblitz.com/edit/demo-ngx-virtual-select-field)
|
|
50
|
+
|
|
51
|
+
## Getting started
|
|
52
|
+
|
|
53
|
+
1. Install package
|
|
54
|
+
|
|
55
|
+
```bash
|
|
56
|
+
npm install ngx-virtual-select-field-filterable
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
1. Import bundle into your component
|
|
60
|
+
|
|
61
|
+
```typescript
|
|
62
|
+
import { NgxVirtualSelectFieldBundle } from 'ngx-virtual-select-field-filterable';
|
|
63
|
+
...
|
|
64
|
+
@Component({
|
|
65
|
+
imports: [
|
|
66
|
+
NgxVirtualSelectFieldBundle,
|
|
67
|
+
...
|
|
68
|
+
],
|
|
69
|
+
...
|
|
70
|
+
})
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
1. Create options collection in component. Options collection should be an array of objects with `value` and `label` properties. Optionally, you can add `disabled` property to disable specific options and `getLabel()` fot type ahead search.
|
|
74
|
+
|
|
75
|
+
```typescript
|
|
76
|
+
...
|
|
77
|
+
protected options: NgxVirtualSelectFieldOptionModel<number>[]
|
|
78
|
+
|
|
79
|
+
constructor() {
|
|
80
|
+
this.options = new Array(100000)
|
|
81
|
+
.fill(null)
|
|
82
|
+
.map((_, index) => ({
|
|
83
|
+
value: index,
|
|
84
|
+
label: `${index} Option`,
|
|
85
|
+
disabled: index % 5 === 0,
|
|
86
|
+
}));
|
|
87
|
+
}
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
1. Setup template markup. `ngxVirtualSelectFieldOptionFor` directive should be user to pass options collection to the component and provide custom option template.
|
|
91
|
+
|
|
92
|
+
```html
|
|
93
|
+
<mat-form-field>
|
|
94
|
+
<mat-label>Virtual Select Field Example</mat-label>
|
|
95
|
+
<ngx-virtual-select-field [value]="value">
|
|
96
|
+
<ngx-virtual-select-field-option
|
|
97
|
+
*ngxVirtualSelectFieldOptionFor="let option of options"
|
|
98
|
+
[value]="option.value"
|
|
99
|
+
[disabled]="option.disabled">
|
|
100
|
+
{{ option.label }}
|
|
101
|
+
</ngx-virtual-select-field-option>
|
|
102
|
+
</ngx-virtual-select-field>
|
|
103
|
+
</mat-form-field>
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
1. Include theme styles. You can define your own theme with help of [CSS variables](#css-variables) or inherit from material theme.
|
|
107
|
+
```scss
|
|
108
|
+
@use 'ngx-virtual-select-field-filterable/theme' as theme;
|
|
109
|
+
|
|
110
|
+
@include theme.inherit-material-theme(); // this will inherit css variables from material theme
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
## Examples
|
|
114
|
+
|
|
115
|
+
Basic setup with value input and output binding
|
|
116
|
+
|
|
117
|
+
```html
|
|
118
|
+
<mat-form-field>
|
|
119
|
+
<mat-label>Example</mat-label>
|
|
120
|
+
<ngx-virtual-select-field [value]="value" (valueChange)="onValueChange($event)">
|
|
121
|
+
<ngx-virtual-select-field-option
|
|
122
|
+
*ngxVirtualSelectFieldOptionFor="let option of options" [value]="option.value">
|
|
123
|
+
{{ option.label }}
|
|
124
|
+
</ngx-virtual-select-field-option>
|
|
125
|
+
</ngx-virtual-select-field>
|
|
126
|
+
</mat-form-field>
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
Form control integration
|
|
130
|
+
|
|
131
|
+
```html
|
|
132
|
+
<mat-form-field>
|
|
133
|
+
<mat-label>Form Control Example</mat-label>
|
|
134
|
+
<ngx-virtual-select-field [formControl]="formControl">
|
|
135
|
+
<ngx-virtual-select-field-option
|
|
136
|
+
*ngxVirtualSelectFieldOptionFor="let option of options" [value]="option.value">
|
|
137
|
+
{{ option.label }}
|
|
138
|
+
</ngx-virtual-select-field-option>
|
|
139
|
+
</ngx-virtual-select-field>
|
|
140
|
+
</mat-form-field>
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
Multi select
|
|
144
|
+
|
|
145
|
+
```html
|
|
146
|
+
<mat-form-field>
|
|
147
|
+
<mat-label>Multi Select Example</mat-label>
|
|
148
|
+
<ngx-virtual-select-field [value]="value" multiple (valueChange)="onValueChange($event)">
|
|
149
|
+
<ngx-virtual-select-field-option
|
|
150
|
+
*ngxVirtualSelectFieldOptionFor="let option of options"
|
|
151
|
+
[value]="option.value">
|
|
152
|
+
{{ option.label }}
|
|
153
|
+
</ngx-virtual-select-field-option>
|
|
154
|
+
</ngx-virtual-select-field>
|
|
155
|
+
</mat-form-field>
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
Custom trigger template
|
|
159
|
+
|
|
160
|
+
```html
|
|
161
|
+
<mat-form-field class="field">
|
|
162
|
+
<mat-label>Custom Trigger Example</mat-label>
|
|
163
|
+
<ngx-virtual-select-field multiple [(value)]="value">
|
|
164
|
+
<ngx-virtual-select-field-trigger>
|
|
165
|
+
{{ value.length }} selected
|
|
166
|
+
</ngx-virtual-select-field-trigger>
|
|
167
|
+
<ngx-virtual-select-field-option
|
|
168
|
+
*ngxVirtualSelectFieldOptionFor="let option of options"
|
|
169
|
+
[value]="option.value">
|
|
170
|
+
{{ option.label }}
|
|
171
|
+
</ngx-virtual-select-field-option>
|
|
172
|
+
</ngx-virtual-select-field>
|
|
173
|
+
</mat-form-field>
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
Filterable select with search input
|
|
177
|
+
|
|
178
|
+
```html
|
|
179
|
+
<mat-form-field>
|
|
180
|
+
<mat-label>Filterable Example</mat-label>
|
|
181
|
+
<ngx-virtual-select-field
|
|
182
|
+
[value]="value"
|
|
183
|
+
[filterable]="true"
|
|
184
|
+
filterPlaceholder="Type to filter..."
|
|
185
|
+
(valueChange)="onValueChange($event)">
|
|
186
|
+
<ngx-virtual-select-field-option
|
|
187
|
+
*ngxVirtualSelectFieldOptionFor="let option of options"
|
|
188
|
+
[value]="option.value">
|
|
189
|
+
{{ option.label }}
|
|
190
|
+
</ngx-virtual-select-field-option>
|
|
191
|
+
</ngx-virtual-select-field>
|
|
192
|
+
</mat-form-field>
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
## Customization
|
|
196
|
+
|
|
197
|
+
Components supports custom templates for trigger and option elements. You can use `ngx-virtual-select-field-trigger` and `ngx-virtual-select-field-option` components to define custom templates.
|
|
198
|
+
|
|
199
|
+
There are number of input parameters available to specify specific behavior of the component.
|
|
200
|
+
|
|
201
|
+
Injection tokens might be used to customize all component instances
|
|
202
|
+
|
|
203
|
+
All styles are defined with css variables, so you can easily override them in your own styles.
|
|
204
|
+
|
|
205
|
+
See more in API section below.
|
|
206
|
+
|
|
207
|
+
## API
|
|
208
|
+
|
|
209
|
+
### NgxVirtualSelectFieldComponent<TValue>
|
|
210
|
+
|
|
211
|
+
selector: `ngx-virtual-select-field`
|
|
212
|
+
Component to define select field
|
|
213
|
+
|
|
214
|
+
| Input | Type | Default | Description |
|
|
215
|
+
| ------------------------- | ---------------------------- | ------------ | ------------------------------------------------------------------------------ |
|
|
216
|
+
| panelWidth | `string\|number \|null` | `auto` | Width for overlay panel |
|
|
217
|
+
| optionHeight | `number` | `48` | Height for an option element |
|
|
218
|
+
| panelViewportPageSize | `number` | `8` | Amount of visible items in list |
|
|
219
|
+
| multiple | `boolean` | `false` | Enable multiple selection |
|
|
220
|
+
| tabIndex | `number` | `0` | Tab index for keyboard navigation |
|
|
221
|
+
| typeaheadDebounceInterval | `number` | `300` | Milliseconds to wait before navigating to active element after keyboard search |
|
|
222
|
+
| panelClass | `string \| string[] \| null` | `null` | CSS class to be added to the panel element |
|
|
223
|
+
| filterable | `boolean` | `false` | Enable filtering of options with search input |
|
|
224
|
+
| filterPlaceholder | `string` | `'Search...'`| Placeholder text for the filter input |
|
|
225
|
+
| value | `TValue[] \| TValue \| null` | `null` | Value of the select field |
|
|
226
|
+
| placeholder | `string` | none | Placeholder for the select field |
|
|
227
|
+
| required | `boolean` | `false` | Define if fields is required |
|
|
228
|
+
| disabled | `boolean` | `false` | Define if fields is disabled |
|
|
229
|
+
|
|
230
|
+
| Output | Type | Description |
|
|
231
|
+
| --------------- | ----------------------------- | -------------------------- |
|
|
232
|
+
| valueChange | `TValue \| TValue[]` | Value change output |
|
|
233
|
+
| selectionChange | `NgxVirtualSelectFieldChange` | Selecten change output |
|
|
234
|
+
|
|
235
|
+
|
|
236
|
+
### NgxVirtualSelectFieldOptionComponent<TValue>
|
|
237
|
+
|
|
238
|
+
selector: `ngx-virtual-select-field-option`
|
|
239
|
+
Component to define option element
|
|
240
|
+
|
|
241
|
+
| Input | Type | Default | Description |
|
|
242
|
+
| ---------------- | --------- | ------- | ------------------------------ |
|
|
243
|
+
| value (required) | `TValue` | | Value of the option |
|
|
244
|
+
| disabled | `boolean` | `false` | Whether the option is disabled |
|
|
245
|
+
|
|
246
|
+
| Output | Type | Description |
|
|
247
|
+
| -------------- | --------------------------------------------------------- | ---------------------------- |
|
|
248
|
+
| selectedChange | `NgxVirtualSelectFieldOptionSelectionChangeEvent<TValue>` | Option selected value change |
|
|
249
|
+
|
|
250
|
+
### NgxVirtualSelectFieldOptionSelectionChangeEvent<TValue>
|
|
251
|
+
|
|
252
|
+
Interface to define option selection change event contract
|
|
253
|
+
Properties:
|
|
254
|
+
| Name | Type | Description |
|
|
255
|
+
|----------|-----------------------------------------------------------|----------------------------|
|
|
256
|
+
| source | `NgxVirtualSelectFieldOptionComponent<TValue>` | Option component instance |
|
|
257
|
+
| value | `TValue` | Value of the option |
|
|
258
|
+
| selected | `boolean` | Whether the option is selected |
|
|
259
|
+
|
|
260
|
+
### NgxVirtualSelectFieldTriggerComponent
|
|
261
|
+
|
|
262
|
+
selector: `ngx-virtual-select-field-trigger`
|
|
263
|
+
Directive to define custom trigger template
|
|
264
|
+
|
|
265
|
+
### NgxVirtualSelectFieldOptionForDirective
|
|
266
|
+
|
|
267
|
+
selector: `*ngxVirtualSelectFieldOptionFor`
|
|
268
|
+
Directive to define custom option template and iterate over options
|
|
269
|
+
| Input | Type | Description |
|
|
270
|
+
|----------------------------------|----------------------------------------------|---------------------|
|
|
271
|
+
| of (required) | `NgxVirtualSelectFieldOptionModel<TValue>[]` | Options collection |
|
|
272
|
+
|
|
273
|
+
### NgxVirtualSelectFieldOptionModel<TValue>
|
|
274
|
+
|
|
275
|
+
Interface to define option model contract
|
|
276
|
+
Properties:
|
|
277
|
+
| Name | Type | Description |
|
|
278
|
+
|-----------------------|----------------------------------------------------------------|----------------------------|
|
|
279
|
+
| value | `TValue` | Value of the option |
|
|
280
|
+
| label | `string` | Label of the option |
|
|
281
|
+
| disabled? | `boolean` | Whether the option is disabled |
|
|
282
|
+
| getLabel() optional | `(option: NgxVirtualSelectFieldOptionModel<TValue>) => string` | Function to get label of the option |
|
|
283
|
+
|
|
284
|
+
### NGX_VIRTUAL_SELECT_FIELD_CONFIG
|
|
285
|
+
|
|
286
|
+
Injection token to define global configuration for all instances of the component
|
|
287
|
+
Config see in NgxVirtualSelectFieldConfig interface
|
|
288
|
+
|
|
289
|
+
### NgxVirtualSelectFieldConfig
|
|
290
|
+
|
|
291
|
+
Interface to define global configuration contract
|
|
292
|
+
Properties:
|
|
293
|
+
| Name | Type | Description |
|
|
294
|
+
|-----------------------|--------------------------------------------|----------------------------|
|
|
295
|
+
| panelWidth | `string\|number` | Width for overlay panel |
|
|
296
|
+
| overlayPanelClass | `string \| string[]` | CSS class to be added to the panel element|
|
|
297
|
+
| optionHeight | `number` | Height for an option element |
|
|
298
|
+
| panelViewportPageSize | `number` | Amount of visible items in list |
|
|
299
|
+
|
|
300
|
+
### NgxVirtualSelectFieldChange
|
|
301
|
+
|
|
302
|
+
Class to define event for `selectionChange` output
|
|
303
|
+
Properties:
|
|
304
|
+
| Name | Type | Description |
|
|
305
|
+
|-----------------------|--------------------------------------------|----------------------------|
|
|
306
|
+
| source | `NgxVirtualSelectFieldComponent` | isntance of the selector component |
|
|
307
|
+
| value | `TValue` or `TValue[]` | new selection value|
|
|
308
|
+
|
|
309
|
+
|
|
310
|
+
### CSS variables
|
|
311
|
+
|
|
312
|
+
All styles are defined with css variables, so you can easily override them in your own styles.
|
|
313
|
+
CSS variables for main component:
|
|
314
|
+
```scss
|
|
315
|
+
:root {
|
|
316
|
+
--ngx-virtual-select-field-trigger-text-color: ...;
|
|
317
|
+
--ngx-virtual-select-field-trigger-text-color--disabled: ...;
|
|
318
|
+
--ngx-virtual-select-field-trigger-font-family: ...;
|
|
319
|
+
--ngx-virtual-select-field-trigger-line-height: ...;
|
|
320
|
+
--ngx-virtual-select-field-trigger-font-size: ...;
|
|
321
|
+
--ngx-virtual-select-field-trigger-font-weight: ...;
|
|
322
|
+
--ngx-virtual-select-field-trigger-letter-spacing: ...;
|
|
323
|
+
|
|
324
|
+
--ngx-virtual-select-field-placeholder-text-color: ...;
|
|
325
|
+
--ngx-virtual-select-field-placeholder-transition: ...;
|
|
326
|
+
|
|
327
|
+
--ngx-virtual-select-field-arrow-size: ...;
|
|
328
|
+
--ngx-virtual-select-field-arrow-color--enabled: ...;
|
|
329
|
+
--ngx-virtual-select-field-arrow-color--focused: ...;
|
|
330
|
+
--ngx-virtual-select-field-arrow-color--invalid: ...;
|
|
331
|
+
--ngx-virtual-select-field-arrow-color--disabled: ...;
|
|
332
|
+
|
|
333
|
+
--ngx-virtual-select-field-panel-background: ...;
|
|
334
|
+
--ngx-virtual-select-field-panel-box-shadow: ...;
|
|
335
|
+
--ngx-virtual-select-field-panel-list-wrapper-padding: ...;
|
|
336
|
+
|
|
337
|
+
--ngx-virtual-select-field-divider-color: ...;
|
|
338
|
+
--ngx-virtual-select-field-filter-input-border-color: ...;
|
|
339
|
+
--ngx-virtual-select-field-filter-input-border-color--focused: ...;
|
|
340
|
+
}
|
|
341
|
+
```
|
|
342
|
+
CSS variables for option component:
|
|
343
|
+
|
|
344
|
+
```scss
|
|
345
|
+
:root {
|
|
346
|
+
--ngx-virtual-select-field-option-color: ...;
|
|
347
|
+
--ngx-virtual-select-field-option-font-family: ...;
|
|
348
|
+
--ngx-virtual-select-field-option-line-height: ...;
|
|
349
|
+
--ngx-virtual-select-field-option-font-size: ...;
|
|
350
|
+
--ngx-virtual-select-field-option-letter-spacing: ...;
|
|
351
|
+
--ngx-virtual-select-field-option-font-weight: ...;
|
|
352
|
+
|
|
353
|
+
--ngx-virtual-select-field-option-selected-state-label-text-color: ...;
|
|
354
|
+
--ngx-virtual-select-field-option-background-color--active: ...;
|
|
355
|
+
--ngx-virtual-select-field-option-background-color--hover: ...;
|
|
356
|
+
--ngx-virtual-select-field-option-background-color--selected: ...;
|
|
357
|
+
|
|
358
|
+
--ngx-virtual-select-field-option-disabled-state-opacity: ...;
|
|
359
|
+
--ngx-virtual-select-field-option-gap: ...;
|
|
360
|
+
--ngx-virtual-select-field-option-padding: ...;
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
```
|