Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add displayValue and change selection and value #13207

Merged
merged 10 commits into from
Jul 25, 2023
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ All notable changes for each version of this project will be documented in this
- `IgxGrid`, `IgxTreeGrid`, `IgxHierarchicalGrid`
- 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.
- **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.
- `IgxCombo`, `IgxSimpleCombo`:
- **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`.

### New Features
- `IgxCombo`, `IgxSimpleCombo`
- Added new property `displayValue` that returns array of display keys.

## 16.0.0

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"$schema": "../../common/schema/members-changes.schema.json",
"changes": [
{
"member": "value",
"replaceWith": "displayValue",
"definedIn": [
"IgxComboComponent",
"IgxSimpleComboComponent"
]
},
{
"member": "selection",
"replaceWith": "value",
"definedIn": [
"IgxComboComponent",
"IgxSimpleComboComponent"
]
}
]
}
44 changes: 44 additions & 0 deletions projects/igniteui-angular/migrations/update-16_1_0/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,48 @@ describe(`Update to ${version}`, () => {
</igx-stepper>`);

});

it('Should properly rename value property to displayValue and selection to value', async () => {
pending('set up tests for migrations through lang service');
appTree.create('/testSrc/appPrefix/component/test.component.ts',
`
import { IgxComboComponent } from 'igniteui-angular';
export class MyClass {
@ViewChild(IgxComboComponent, { read: IgxComboComponent })
public combo: IgxComboComponent;
@ViewChild(IgxSimpleComboComponent, { read: IgxSimpleComboComponent })
public simpleCombo: IgxSimpleComboComponent;
public ngAfterViewInit() {
const comboDisplayValue = combo.value;
const comboSelectionValue = combo.selection;
const simpleComboDisplayValue = simpleCombo.value;
const simpleComboSelectionValue = simpleCombo.selection;
}
}
`);

const tree = await schematicRunner
.runSchematicAsync(migrationName, {}, appTree)
.toPromise();

expect(
tree.readContent('/testSrc/appPrefix/component/test.component.ts')
).toEqual(
`
import { IgxComboComponent } from 'igniteui-angular';
export class MyClass {
@ViewChild(IgxComboComponent, { read: IgxComboComponent })
public combo: IgxComboComponent;
@ViewChild(IgxSimpleComboComponent, { read: IgxSimpleComboComponent })
public simpleCombo: IgxSimpleComboComponent;
public ngAfterViewInit() {
const comboDisplayValue = combo.displayValue;
const comboSelectionValue = combo.value;
const simpleComboDisplayValue = simpleCombo.displayValue;
const simpleComboSelectionValue = simpleCombo.value;
}
}
`
);
});
});
27 changes: 20 additions & 7 deletions projects/igniteui-angular/src/lib/combo/combo.common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -812,17 +812,29 @@ export abstract class IgxComboBaseDirective extends DisplayDensityBase implement
}

/**
* The text displayed in the combo input
* The value of the selected item in the combo
*
* ```typescript
* // get
* let comboValue = this.combo.value;
* ```
*/
public get value(): string {
public get value(): any[] {
return this._value;
}

/**
* The text displayed in the combo input
*
* ```typescript
* // get
* let comboDisplayValue = this.combo.displayValue;
* ```
*/
public get displayValue(): string[] {
return this._displayValue ? this._displayValue.split(', ') : [];
}

/**
* Defines the current state of the virtualized data. It contains `startIndex` and `chunkSize`
*
Expand Down Expand Up @@ -923,7 +935,8 @@ export abstract class IgxComboBaseDirective extends DisplayDensityBase implement
this._filteringOptions = value;
}
protected _data = [];
protected _value = '';
protected _value = [];
protected _displayValue = '';
protected _groupKey = '';
protected _searchValue = '';
protected _filteredData = [];
Expand Down Expand Up @@ -1024,7 +1037,7 @@ export abstract class IgxComboBaseDirective extends DisplayDensityBase implement
* ```
*/
public toggle(): void {
if (this.collapsed && this._value.length !== 0) {
if (this.collapsed && this._displayValue.length !== 0) {
this.filterValue = '';
this.cdr.detectChanges();
}
Expand All @@ -1044,7 +1057,7 @@ export abstract class IgxComboBaseDirective extends DisplayDensityBase implement
* ```
*/
public open(): void {
if (this.collapsed && this._value.length !== 0) {
if (this.collapsed && this._displayValue.length !== 0) {
this.filterValue = '';
this.cdr.detectChanges();
}
Expand Down Expand Up @@ -1082,7 +1095,7 @@ export abstract class IgxComboBaseDirective extends DisplayDensityBase implement
*/
public get selection() {
const items = Array.from(this.selectionService.get(this.id));
return items;
return this.convertKeysToItems(items);
}

/**
Expand Down Expand Up @@ -1280,7 +1293,7 @@ export abstract class IgxComboBaseDirective extends DisplayDensityBase implement

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

Expand Down
4 changes: 2 additions & 2 deletions projects/igniteui-angular/src/lib/combo/combo.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<ng-container ngProjectAs="igx-hint, [igxHint]">
<ng-content select="igx-hint, [igxHint]"></ng-content>
</ng-container>
<input igxInput #comboInput name="comboInput" type="text" [value]="value" readonly
<input igxInput #comboInput name="comboInput" type="text" [value]="displayValue.join(', ')" readonly
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For future reference - we might want to expose a way for the users to define a custom separator for the values in the combo.

[attr.placeholder]="placeholder" [disabled]="disabled"
role="combobox" aria-haspopup="listbox"
[attr.aria-expanded]="!this.dropdown.collapsed" [attr.aria-controls]="this.dropdown.listId"
Expand All @@ -17,7 +17,7 @@
<ng-container ngProjectAs="igx-suffix">
<ng-content select="igx-suffix"></ng-content>
</ng-container>
<igx-suffix *ngIf="value.length" aria-label="Clear Selection" class="igx-combo__clear-button"
<igx-suffix *ngIf="displayValue.length" aria-label="Clear Selection" class="igx-combo__clear-button"
(click)="handleClearItems($event)">
<ng-container *ngIf="clearIconTemplate">
<ng-container *ngTemplateOutlet="clearIconTemplate"></ng-container>
Expand Down
Loading