Skip to content

Commit 1b167df

Browse files
MonikaKirkovadesig9stein
authored andcommitted
Add displayValue and change selection and value (#13207)
* feat(combo): add displayValue and change selection and value * chore(combo): add migrations and update CHANGELOG.md * chore(combo): add requested changes
1 parent 24affdb commit 1b167df

File tree

10 files changed

+373
-169
lines changed

10 files changed

+373
-169
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,12 @@ All notable changes for each version of this project will be documented in this
4646
- `IgxGrid`, `IgxTreeGrid`, `IgxHierarchicalGrid`
4747
- The `draggable` attribute is no longer required to be set on interactable elements, if a column header is templated and the Column Moving is enabled in order for handlers for any event to be triggered. Now `draggable='false'` can be used as an addition if the user shouldn't be able to drag a column by that element, but even if omitted `click` events for example will trigger now.
4848
- **Behavioral Change** When there are already grouped columns, the group drop area now shows after dragging of a column starts and not when only click actions are performed.
49+
- `IgxCombo`, `IgxSimpleCombo`:
50+
- **Breaking Change** The `selection` property returns an array of the selected items even when a value key is provided and the `value` property returns an array of value keys instead of display keys. Automatic migrations are available and will be applied on `ng update`.
51+
52+
### New Features
53+
- `IgxCombo`, `IgxSimpleCombo`
54+
- Added new property `displayValue` that returns array of display keys.
4955

5056
## 16.0.0
5157

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"$schema": "../../common/schema/members-changes.schema.json",
3+
"changes": [
4+
{
5+
"member": "value",
6+
"replaceWith": "displayValue",
7+
"definedIn": [
8+
"IgxComboComponent",
9+
"IgxSimpleComboComponent"
10+
]
11+
},
12+
{
13+
"member": "selection",
14+
"replaceWith": "value",
15+
"definedIn": [
16+
"IgxComboComponent",
17+
"IgxSimpleComboComponent"
18+
]
19+
}
20+
]
21+
}

projects/igniteui-angular/migrations/update-16_1_0/index.spec.ts

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,4 +88,48 @@ describe(`Update to ${version}`, () => {
8888
</igx-stepper>`);
8989

9090
});
91+
92+
it('Should properly rename value property to displayValue and selection to value', async () => {
93+
pending('set up tests for migrations through lang service');
94+
appTree.create('/testSrc/appPrefix/component/test.component.ts',
95+
`
96+
import { IgxComboComponent } from 'igniteui-angular';
97+
export class MyClass {
98+
@ViewChild(IgxComboComponent, { read: IgxComboComponent })
99+
public combo: IgxComboComponent;
100+
@ViewChild(IgxSimpleComboComponent, { read: IgxSimpleComboComponent })
101+
public simpleCombo: IgxSimpleComboComponent;
102+
public ngAfterViewInit() {
103+
const comboDisplayValue = combo.value;
104+
const comboSelectionValue = combo.selection;
105+
const simpleComboDisplayValue = simpleCombo.value;
106+
const simpleComboSelectionValue = simpleCombo.selection;
107+
}
108+
}
109+
`);
110+
111+
const tree = await schematicRunner
112+
.runSchematicAsync(migrationName, {}, appTree)
113+
.toPromise();
114+
115+
expect(
116+
tree.readContent('/testSrc/appPrefix/component/test.component.ts')
117+
).toEqual(
118+
`
119+
import { IgxComboComponent } from 'igniteui-angular';
120+
export class MyClass {
121+
@ViewChild(IgxComboComponent, { read: IgxComboComponent })
122+
public combo: IgxComboComponent;
123+
@ViewChild(IgxSimpleComboComponent, { read: IgxSimpleComboComponent })
124+
public simpleCombo: IgxSimpleComboComponent;
125+
public ngAfterViewInit() {
126+
const comboDisplayValue = combo.displayValue;
127+
const comboSelectionValue = combo.value;
128+
const simpleComboDisplayValue = simpleCombo.displayValue;
129+
const simpleComboSelectionValue = simpleCombo.value;
130+
}
131+
}
132+
`
133+
);
134+
});
91135
});

projects/igniteui-angular/src/lib/combo/combo.common.ts

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -812,17 +812,29 @@ export abstract class IgxComboBaseDirective extends DisplayDensityBase implement
812812
}
813813

814814
/**
815-
* The text displayed in the combo input
815+
* The value of the selected item in the combo
816816
*
817817
* ```typescript
818818
* // get
819819
* let comboValue = this.combo.value;
820820
* ```
821821
*/
822-
public get value(): string {
822+
public get value(): any[] {
823823
return this._value;
824824
}
825825

826+
/**
827+
* The text displayed in the combo input
828+
*
829+
* ```typescript
830+
* // get
831+
* let comboDisplayValue = this.combo.displayValue;
832+
* ```
833+
*/
834+
public get displayValue(): string[] {
835+
return this._displayValue ? this._displayValue.split(', ') : [];
836+
}
837+
826838
/**
827839
* Defines the current state of the virtualized data. It contains `startIndex` and `chunkSize`
828840
*
@@ -923,7 +935,8 @@ export abstract class IgxComboBaseDirective extends DisplayDensityBase implement
923935
this._filteringOptions = value;
924936
}
925937
protected _data = [];
926-
protected _value = '';
938+
protected _value = [];
939+
protected _displayValue = '';
927940
protected _groupKey = '';
928941
protected _searchValue = '';
929942
protected _filteredData = [];
@@ -1024,7 +1037,7 @@ export abstract class IgxComboBaseDirective extends DisplayDensityBase implement
10241037
* ```
10251038
*/
10261039
public toggle(): void {
1027-
if (this.collapsed && this._value.length !== 0) {
1040+
if (this.collapsed && this._displayValue.length !== 0) {
10281041
this.filterValue = '';
10291042
this.cdr.detectChanges();
10301043
}
@@ -1044,7 +1057,7 @@ export abstract class IgxComboBaseDirective extends DisplayDensityBase implement
10441057
* ```
10451058
*/
10461059
public open(): void {
1047-
if (this.collapsed && this._value.length !== 0) {
1060+
if (this.collapsed && this._displayValue.length !== 0) {
10481061
this.filterValue = '';
10491062
this.cdr.detectChanges();
10501063
}
@@ -1082,7 +1095,7 @@ export abstract class IgxComboBaseDirective extends DisplayDensityBase implement
10821095
*/
10831096
public get selection() {
10841097
const items = Array.from(this.selectionService.get(this.id));
1085-
return items;
1098+
return this.convertKeysToItems(items);
10861099
}
10871100

10881101
/**
@@ -1280,7 +1293,7 @@ export abstract class IgxComboBaseDirective extends DisplayDensityBase implement
12801293

12811294
/** if there is a valueKey - map the keys to data items, else - just return the keys */
12821295
protected convertKeysToItems(keys: any[]) {
1283-
if (this.comboAPI.valueKey === null) {
1296+
if (this.valueKey === null || this.valueKey === undefined) {
12841297
return keys;
12851298
}
12861299

projects/igniteui-angular/src/lib/combo/combo.component.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<ng-container ngProjectAs="igx-hint, [igxHint]">
99
<ng-content select="igx-hint, [igxHint]"></ng-content>
1010
</ng-container>
11-
<input igxInput #comboInput name="comboInput" type="text" [value]="value" readonly
11+
<input igxInput #comboInput name="comboInput" type="text" [value]="displayValue.join(', ')" readonly
1212
[attr.placeholder]="placeholder" [disabled]="disabled"
1313
role="combobox" aria-haspopup="listbox"
1414
[attr.aria-expanded]="!this.dropdown.collapsed" [attr.aria-controls]="this.dropdown.listId"
@@ -17,7 +17,7 @@
1717
<ng-container ngProjectAs="igx-suffix">
1818
<ng-content select="igx-suffix"></ng-content>
1919
</ng-container>
20-
<igx-suffix *ngIf="value.length" aria-label="Clear Selection" class="igx-combo__clear-button"
20+
<igx-suffix *ngIf="displayValue.length" aria-label="Clear Selection" class="igx-combo__clear-button"
2121
(click)="handleClearItems($event)">
2222
<ng-container *ngIf="clearIconTemplate">
2323
<ng-container *ngTemplateOutlet="clearIconTemplate"></ng-container>

0 commit comments

Comments
 (0)