ng-select2-component 17.0.0 → 17.1.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/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Changelog of ng-select2
2
2
 
3
+ ## V17.1.0 (2024-12-26)
4
+
5
+ - Add attribute `multipleDrag`: drag'n drop list of items in selection
6
+
3
7
  ## V17.0.0 (2024-12-23)
4
8
 
5
9
  ### Changes
package/README.md CHANGED
@@ -25,21 +25,21 @@ npm i ng-select2-component --save
25
25
 
26
26
  | Version  | For **Angular** | Notes |
27
27
  | --------- | --------------- | ----------------- |
28
- | `7.3.1` | 7, 8 and 9 | View Engine |
29
- | `8.1.0` | 10, 11 and 12 | View Engine |
30
- | `9.0.0` | 13 | Ivy |
31
- | `10.0.0` | 14 | Ivy |
32
- | `11.1.0` | 15 | Ivy |
33
- | `12.1.0` | 16 | Ivy |
34
- | `13.0.12` | 16.1 | Ivy |
35
- | `14.0.1` | 17 | Ivy |
36
- | `15.3.0` | 18 | Ivy |
28
+ | `17.1.0` | 19 and more | Ivy / Stand-alone |
37
29
  | `16.0.0` | 19 | Ivy / Module |
38
- | `17.0.0` | 19 and more | Ivy / Stand-alone |
30
+ | `15.4.0` | 18 | Ivy |
31
+ | `14.0.1` | 17 | Ivy |
32
+ | `13.0.12` | 16.1 | Ivy |
33
+ | `12.1.0` | 16 | Ivy |
34
+ | `11.1.0` | 15 | Ivy |
35
+ | `10.0.0` | 14 | Ivy |
36
+ | `9.0.0` | 13 | Ivy |
37
+ | `8.1.0` | 10, 11 and 12 | View Engine |
38
+ | `7.3.1` | 7, 8 and 9 | View Engine |
39
39
 
40
40
  ## Demo
41
41
 
42
- [See a demo](https://harvest-dev.github.io/ng-select2/dist/ng-select2/browser).
42
+ [See a demo and code generator](https://harvest-dev.github.io/ng-select2/dist/ng-select2/browser).
43
43
 
44
44
  ## Features
45
45
 
@@ -57,6 +57,7 @@ npm i ng-select2-component --save
57
57
  - material style
58
58
  - form binding
59
59
  - templating
60
+ - etc.
60
61
 
61
62
  ## Usage
62
63
 
@@ -82,58 +83,52 @@ class MyComponent {}
82
83
 
83
84
  ### properties and events of the component
84
85
 
85
- | name | type | status | default | description | required |
86
- | ------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------ | -------- | -------------------- | ----------------------------------------------------------------------------------------------------------------------- | ------------------------------------ |
87
- | `data` | [`Select2Data`](#select2-data-structure) | required | | the data of the select2 | |
88
- | `value` | [`Select2Value`](#select2-data-structure) | | | initial value | |
89
- | `minCharForSearch` | `number` | | `0` | start the search when the number of characters is reached (`0` = unlimited) | |
90
- | `minCountForSearch` | `number` | | `6` | hide search box if `options.length < minCountForSearch` | |
91
- | `displaySearchStatus` | `'default'`<br>`'hidden'`<br>`'always'` | | `'default'` | display the search box (`default` : is based on `minCountForSearch`) | |
92
- | `placeholder` | `string` | | | the placeholder string if nothing selected | |
93
- | `noResultMessage` | `string` | | | the message string if no results when using the search field | |
94
- | `customSearchEnabled` | `boolean` | | `false` | will trigger `search` event, and disable inside filter | |
95
- | `multiple` | `boolean` | | `false` | select multiple options | |
96
- | `resettable` | `boolean` | | `false` | add a button to reset value | not `multiple` |
97
- | `resetSelectedValue` | `any` | | `undefined` | selected option when × is clicked | not `multiple` and with `resettable` |
98
- | `autoCreate` | `boolean` | | `false` | gives the possibility to add elements not present in the list. | |
99
- | `limitSelection` | `number` | | `0` | to limit multiple selection (`0` = unlimited) | |
100
- | `hideSelectedItems` | `boolean` | | `false` | remove selected values | with `multiple` |
101
- | `resultMaxHeight` | `string` | | `'200px'` | change the height size of results | |
102
- | `maxResults` | `number` | | `0` | maximum results limit (`0` = unlimited) | |
103
- | `maxResultsMessage` | `string` | | `'Too much result…'` | message when maximum result | |
104
- | `grid` | `number` or `string` | | | option by line in grid layout (empty or `0` = no grid layout)<br>`number`: item by line<br>`string`: minimal item width | |
105
- | `listPosition` | `'below'`<br>`'above'`<br>`'auto'` ¹ | | `'below'` | the position for the dropdown list | ¹ `'auto'`: only with `overlay` |
106
- | `infiniteScroll` | `boolean` | | `false` | active infiniteScroll on dropdown list | with `ngx-infinite-scroll` |
107
- | `infiniteScrollDistance` | `number` | | `1.5` | infiniteScroll distance | with `ngx-infinite-scroll` |
108
- | `infiniteScrollThrottle` | `number` | | `150` | infiniteScroll throttle | |
109
- | `overlay` | `boolean` | | `false` | active an overlay mode for dropdown list (with angular cdk). (See [Overlay](#overlay)) | |
110
- | `styleMode` | `'default'`<br>`'material'`<br>`'noStyle'`<br>`'borderless'` | | `'default'` | change style for material style or remove border and background color | |
111
- | `templates` | `TemplateRef`<br>`{option?: TemplateRef, group?: TemplateRef}`<br>etc.<br>(see ”possible object” in [Templating](#templating)) | | | use templates for formatting content (see [Templating](#templating)) | |
112
- | `templateSelection` | `TemplateRef` | | | use templates for formatting content (see [Templating](#templating)) | |
113
- | `noLabelTemplate` | `boolean` | | `false` | do not use the template in the selection, stay in text mode | |
114
- | `selectionOverride` | `string` or function ([`Select2SelectionOverride`](#select2-data-structure)) | | | Replace selection by a text<br>`string`: `%size%` = total selected options<br>`function`: juste show the string | |
115
- | `selectionNoWrap` | `boolean` | | `false` | Force selection on one line | |
116
- | `showSelectAll` | `boolean` | | `false` | Add an option to select all options | with `multiple` |
117
- | `selectAllText` | `string` | | `'Select all'` | Text when all options as not selected | with `multiple` |
118
- | `removeAllText` | `string` | | `'Remove all'` | Text when all options as selected | with `multiple` |
119
- | `editPattern` | `(str: string) => string` | | | use it for change the pattern of the filter search | |
120
- | `ngModel`<br>`id`<br>`required`<br>`disabled`<br>`readonly`<br>`tabIndex` | | | | just like a `select` control | |
121
- | `(update)` | `(event: `[`Select2UpdateEvent`](#select2-data-structure)`) => void` | event | | triggered when user select an option | |
122
- | `(open)` | `(event: Select2) => void` | event | | triggered when user open the options | |
123
- | `(close)` | `(event: Select2) => void` | event | | triggered when user close the options | |
124
- | `(focus)` | `(event: Select2) => void` | event | | triggered when user enters the component | |
125
- | `(blur)` | `(event: Select2) => void` | event | | triggered when user leaves the component | |
126
- | `(search)` | `(event: `[`Select2SearchEvent`](#select2-data-structure)`) => void` | event | | triggered when search text changed | with `customSearchEnabled` |
127
- | `(scroll)` | `(event: `[`Select2ScrollEvent`](#select2-data-structure)`) => void` | event | | triggered when infiniteScroll is on `up` or `down` position | with `ngx-infinite-scroll` |
128
- | `(removeOption)` | `(event: `[`Select2RemoveEvent`](#select2-data-structure)`) => void` | event | | triggered when an option is removed from the list of selected options options list | with `multiple` |
129
- | `(autoCreateItem)` | `(event: `[`Select2AutoCreateEvent`](#select2-data-structure)`) => void` | event | | triggered when a new item has been added | with `autoCreate` |
130
-
131
- @Input() selectionOverride: Select2SelectionOverride;
132
-
133
- /** force selection on one line */
134
- @HostBinding('class.select2-selection-nowrap')
135
- @Input({ transform: booleanAttribute })
136
- selectionNoWrap = false;
86
+ | name | type | default | description | required |
87
+ | ------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------- | -------------------- | ----------------------------------------------------------------------------------------------------------------------- | ------------------------------- |
88
+ | `data` (required) | [`Select2Data`](#select2-data-structure) | | the data of the select2 | |
89
+ | `value` | [`Select2Value`](#select2-data-structure) | | initial value | |
90
+ | `minCharForSearch` | `number` | `0` | start the search when the number of characters is reached (`0` = unlimited) | |
91
+ | `minCountForSearch` | `number` | `6` | hide search box if `options.length < minCountForSearch` | |
92
+ | `displaySearchStatus` | `'default'`<br>`'hidden'`<br>`'always'` | `'default'` | display the search box (`default` : is based on `minCountForSearch`) | |
93
+ | `placeholder` | `string` | | the placeholder string if nothing selected | |
94
+ | `noResultMessage` | `string` | | the message string if no results when using the search field | |
95
+ | `customSearchEnabled` | `boolean` | `false` | will trigger `search` event, and disable inside filter | |
96
+ | `multiple` | `boolean` | `false` | select multiple options | |
97
+ | `multipleDrag` | `boolean` | `false` | drag'n drop list of items in selection | with `multiple` |
98
+ | `resettable` | `boolean` | `false` | add a button to reset value | |
99
+ | `resetSelectedValue` | `any` | `undefined` | selected option when × is clicked | |
100
+ | `autoCreate` | `boolean` | `false` | gives the possibility to add elements not present in the list. | |
101
+ | `limitSelection` | `number` | `0` | to limit multiple selection (`0` = unlimited) | |
102
+ | `hideSelectedItems` | `boolean` | `false` | remove selected values | with `multiple` |
103
+ | `resultMaxHeight` | `string` | `'200px'` | change the height size of results | |
104
+ | `maxResults` | `number` | `0` | maximum results limit (`0` = unlimited) | |
105
+ | `maxResultsMessage` | `string` | `'Too much result…'` | message when maximum result | |
106
+ | `grid` | `number` or `string` | | option by line in grid layout (empty or `0` = no grid layout)<br>`number`: item by line<br>`string`: minimal item width | |
107
+ | `listPosition` | `'below'`<br>`'above'`<br>`'auto'` ¹ | `'below'` | the position for the dropdown list | ¹ `'auto'`: only with `overlay` |
108
+ | `infiniteScroll` | `boolean` | `false` | active infiniteScroll on dropdown list | with `ngx-infinite-scroll` |
109
+ | `infiniteScrollDistance` | `number` | `1.5` | infiniteScroll distance | with `ngx-infinite-scroll` |
110
+ | `infiniteScrollThrottle` | `number` | `150` | infiniteScroll throttle | |
111
+ | `overlay` | `boolean` | `false` | active an overlay mode for dropdown list (with angular cdk). (See [Overlay](#overlay)) | |
112
+ | `styleMode` | `'default'`<br>`'material'`<br>`'noStyle'`<br>`'borderless'` | `'default'` | change style for material style or remove border and background color | |
113
+ | `templates` | [`Select2Template`](#select2-data-structure)<br>(see ”possible object” in [Templating](#templating)) | | use templates for formatting content (see [Templating](#templating)) | |
114
+ | `templateSelection` | `TemplateRef` | | use templates for formatting content (see [Templating](#templating)) | |
115
+ | `noLabelTemplate` | `boolean` | `false` | do not use the template in the selection, stay in text mode | |
116
+ | `selectionOverride` | [`Select2SelectionOverride`](#select2-data-structure) | | Replace selection by a text<br>`string`: `%size%` = total selected options<br>`function`: juste show the string | |
117
+ | `selectionNoWrap` | `boolean` | `false` | Force selection on one line | |
118
+ | `showSelectAll` | `boolean` | `false` | Add an option to select all options | with `multiple` |
119
+ | `selectAllText` | `string` | `'Select all'` | Text when all options as not selected | with `multiple` |
120
+ | `removeAllText` | `string` | `'Remove all'` | Text when all options as selected | with `multiple` |
121
+ | `editPattern` | `(str: string) => string` | | use it for change the pattern of the filter search | |
122
+ | `ngModel`<br>`id`<br>`required`<br>`disabled`<br>`readonly`<br>`tabIndex` | | | just like a `select` control | |
123
+ | `(update)` | `(event: `[`Select2UpdateEvent`](#select2-data-structure)`) => void` | | triggered when user select an option | |
124
+ | `(open)` | `(event: Select2) => void` | | triggered when user open the options | |
125
+ | `(close)` | `(event: Select2) => void` | | triggered when user close the options | |
126
+ | `(focus)` | `(event: Select2) => void` | | triggered when user enters the component | |
127
+ | `(blur)` | `(event: Select2) => void` | | triggered when user leaves the component | |
128
+ | `(search)` | `(event: `[`Select2SearchEvent`](#select2-data-structure)`) => void` | | triggered when search text changed | with `customSearchEnabled` |
129
+ | `(scroll)` | `(event: `[`Select2ScrollEvent`](#select2-data-structure)`) => void` | | triggered when infiniteScroll is on `up` or `down` position | with `ngx-infinite-scroll` |
130
+ | `(removeOption)` | `(event: `[`Select2RemoveEvent`](#select2-data-structure)`) => void` | | triggered when an option is removed from the list of selected options options list | with `multiple` |
131
+ | `(autoCreateItem)` | `(event: `[`Select2AutoCreateEvent`](#select2-data-structure)`) => void` | | triggered when a new item has been added | with `autoCreate` |
137
132
 
138
133
  ### select2 data structure
139
134
 
@@ -145,7 +140,7 @@ export interface Select2Group {
145
140
  options: Select2Option[];
146
141
  /** add classes */
147
142
  classes?: string;
148
- /** template id */
143
+ /** template id dropdown & selection if no templateSelectionId */
149
144
  templateId?: string;
150
145
  /** template data */
151
146
  data?: any;
@@ -162,17 +157,19 @@ export interface Select2Option {
162
157
  id?: string;
163
158
  /** add classes */
164
159
  classes?: string;
165
- /** template id */
160
+ /** template id dropdown & selection if no templateSelectionId */
166
161
  templateId?: string;
162
+ /** template id for selection */
163
+ templateSelectionId?: string;
167
164
  /** template data */
168
165
  data?: any;
169
166
  /** hide this option */
170
167
  hide?: boolean;
171
168
  }
172
169
 
173
- export type Select2Value = string | number | boolean | object;
170
+ export type Select2Value = string | number | boolean | object | null | undefined;
174
171
 
175
- export type Select2UpdateValue = Select2Value | Select2Value[];
172
+ export type Select2UpdateValue = Select2Value | Select2Value[] | undefined | null;
176
173
 
177
174
  export type Select2Data = (Select2Group | Select2Option)[];
178
175
 
@@ -180,9 +177,9 @@ export interface Select2UpdateEvent<U extends Select2UpdateValue = Select2Value>
180
177
  /** component */
181
178
  readonly component: Select2;
182
179
  /** current selected value */
183
- readonly value: U;
180
+ readonly value: U | null;
184
181
  /** selected option */
185
- readonly options: Select2Option[];
182
+ readonly options: Select2Option[] | null;
186
183
  }
187
184
 
188
185
  export interface Select2AutoCreateEvent<U extends Select2UpdateValue = Select2Value> {
@@ -191,14 +188,14 @@ export interface Select2AutoCreateEvent<U extends Select2UpdateValue = Select2Va
191
188
  /** current selected value */
192
189
  readonly value: U;
193
190
  /** selected option */
194
- readonly options: Select2Option[];
191
+ readonly options: Select2Option[] | null;
195
192
  }
196
193
 
197
194
  export interface Select2SearchEvent<U extends Select2UpdateValue = Select2Value> {
198
195
  /** component */
199
196
  readonly component: Select2;
200
197
  /** current selected value */
201
- readonly value: U;
198
+ readonly value: U | null;
202
199
  /** search text */
203
200
  readonly search: string;
204
201
  /** current data source */
@@ -228,6 +225,8 @@ export interface Select2ScrollEvent {
228
225
  }
229
226
 
230
227
  export type Select2SelectionOverride = string | ((params: { size: number; options: Select2Option[] | null }) => string);
228
+
229
+ export type Select2Template = TemplateRef<any> | { [key: string]: TemplateRef<any> } | undefined;
231
230
  ```
232
231
 
233
232
  ### Templating
@@ -293,6 +292,14 @@ const data: Select2Data = [
293
292
  ];
294
293
  ```
295
294
 
295
+ #### Template for change the selection
296
+
297
+ ```html
298
+ <select2 [data]="data" [templateSelection]="templateSelection">
299
+ <ng-template #templateSelection let-data="data"><strong>{{ data?.color }}</strong> ({{ data?.name }})</ng-template>
300
+ </select2>
301
+ ```
302
+
296
303
  #### Possible object
297
304
 
298
305
  - `TemplateRef`