Skip to content

Commit 1283a13

Browse files
authored
Merge branch 'master' into ddavidkov/treegrid
2 parents 8c29cbc + e8bbf4f commit 1283a13

File tree

4 files changed

+48
-11
lines changed

4 files changed

+48
-11
lines changed

projects/igniteui-angular/src/lib/chips/README.md

+6-6
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ The chips can be focused using the `Tab` key or by clicking on them. Chips can b
178178
| `onMoveEnd` | `IBaseChipEventArgs` | Fired when the chip moving(dragging) ends. |
179179
| `onRemove ` | `IBaseChipEventArgs` | Fired when the chip remove button is clicked. |
180180
| `onClick ` | `IChipClickEventArgs` | Fired when the chip is clicked instead of dragged. |
181-
| `onSelection` | `IChipSelectEventArgs` | Fired when the chip is being selected. |
181+
| `onSelection` | `IChipSelectEventArgs` | Fired when the chip is being selected/deselected. |
182182
| `onKeyDown ` | `IChipKeyDownEventArgs` | Fired when the chip keyboard navigation is being used. |
183183
| `onDragEnter ` | `IChipEnterDragAreaEventArgs` | Fired when another chip has entered the current chip area. |
184184

@@ -188,15 +188,15 @@ The chips can be focused using the `Tab` key or by clicking on them. Chips can b
188188
| Name | Type | Description |
189189
|:----------|:-------------:|:------|
190190
| `width` | `number` | Sets the width of the chips area. |
191-
| `height ` | `number` | Sets the height of the chip area. |
191+
| `height ` | `number` | Sets the height of the chips area. |
192192

193193
### Outputs
194194
| Name | Argument Type | Description |
195195
|:--:|:---|:---|
196-
| `onReorder ` | `IChipsAreaReorderEventArgs` | Fired when the chip moving(dragging) starts. |
197-
| `onSelection ` | `IChipsAreaSelectEventArgs` | Fired when the chip moving(dragging) ends. |
198-
| `onMoveStart ` | `IBaseChipsAreaEventArgs` | Fired when the chip remove button is clicked. |
199-
| `onMoveEnd ` | `IBaseChipsAreaEventArgs` | Fired when the chip is clicked instead of dragged. |
196+
| `onReorder ` | `IChipsAreaReorderEventArgs` | Fired when the chips order should be changed(from dragging). Requires custom logic for actual reorder. |
197+
| `onSelection ` | `IChipsAreaSelectEventArgs` | Fired for all initially selected chips and when chip is being selected/deselected. |
198+
| `onMoveStart ` | `IBaseChipsAreaEventArgs` | Fired when any chip moving(dragging) starts. |
199+
| `onMoveEnd ` | `IBaseChipsAreaEventArgs` | Fired when any chip moving(dragging) ends. |
200200

201201
### Properties
202202
| Name | Return Type | Description |

projects/igniteui-angular/src/lib/chips/chip.component.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ export class IgxChipComponent implements AfterViewInit {
241241
public onClick = new EventEmitter<IChipClickEventArgs>();
242242

243243
/**
244-
* Emits event when the `IgxChipComponent` is selected.
244+
* Emits event when the `IgxChipComponent` is selected/deselected.
245245
* Returns the selected chip reference, whether the event should be canceled, what is the next selection state and
246246
* when the event is triggered by interaction `originalEvent` is provided, otherwise `originalEvent` is `null`.
247247
* ```typescript

projects/igniteui-angular/src/lib/chips/chips-area.component.ts

+23-4
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
IterableDiffers,
1010
Output,
1111
QueryList,
12-
DoCheck
12+
DoCheck,
13+
AfterViewInit
1314
} from '@angular/core';
1415
import {
1516
IgxChipComponent,
@@ -40,7 +41,7 @@ export interface IChipsAreaSelectEventArgs extends IBaseChipsAreaEventArgs {
4041
selector: 'igx-chips-area',
4142
templateUrl: 'chips-area.component.html',
4243
})
43-
export class IgxChipsAreaComponent implements DoCheck {
44+
export class IgxChipsAreaComponent implements DoCheck, AfterViewInit {
4445

4546
/**
4647
* @hidden
@@ -69,7 +70,7 @@ export class IgxChipsAreaComponent implements DoCheck {
6970
public height: number;
7071

7172
/**
72-
* Emits an event when `IgxChipComponent`s in the `IgxChipsAreaComponent` are reordered.
73+
* Emits an event when `IgxChipComponent`s in the `IgxChipsAreaComponent` should be reordered.
7374
* Returns an array of `IgxChipComponent`s.
7475
* ```html
7576
* <igx-chips-area #chipsArea [width]="'300'" [height]="'10'" (onReorder)="changedOrder($event)"></igx-chips-area>
@@ -84,7 +85,8 @@ export class IgxChipsAreaComponent implements DoCheck {
8485
public onReorder = new EventEmitter<IChipsAreaReorderEventArgs>();
8586

8687
/**
87-
* Emits an event when an `IgxChipComponent` in the `IgxChipsAreaComponent` is selected.
88+
* Emits an event when an `IgxChipComponent` in the `IgxChipsAreaComponent` is selected/deselected.
89+
* Fired after the chips area is initialized if there are initially selected chips as well.
8890
* Returns an array of selected `IgxChipComponent`s and the `IgxChipAreaComponent`.
8991
* ```html
9092
* <igx-chips-area #chipsArea [width]="'300'" [height]="'10'" (onSelection)="selection($event)"></igx-chips-area>
@@ -145,6 +147,23 @@ export class IgxChipsAreaComponent implements DoCheck {
145147
this._differ = this._iterableDiffers.find([]).create(null);
146148
}
147149

150+
/**
151+
* @hidden
152+
*/
153+
public ngAfterViewInit() {
154+
// If we have initially selected chips through their inputs, we need to get them, because we cannot listen to their events yet.
155+
if (this.chipsList.length) {
156+
this.selectedChips = this.chipsList.filter((item: IgxChipComponent) => item.selected);
157+
if (this.selectedChips.length) {
158+
this.onSelection.emit({
159+
originalEvent: null,
160+
newSelection: this.selectedChips,
161+
owner: this
162+
});
163+
}
164+
}
165+
}
166+
148167
/**
149168
* @hidden
150169
*/

projects/igniteui-angular/src/lib/chips/chips-area.spec.ts

+18
Original file line numberDiff line numberDiff line change
@@ -832,4 +832,22 @@ describe('IgxChipsArea', () => {
832832
expect(chipComponents.length).toEqual(3);
833833
});
834834
});
835+
836+
it('should emit onSelection for the chipArea event when there are initially selected chips through their inputs', () => {
837+
const fix = TestBed.createComponent(TestChipSelectComponent);
838+
839+
const chipAreaComp = fix.componentInstance.chipsArea;
840+
spyOn(chipAreaComp.onSelection, 'emit');
841+
842+
fix.detectChanges();
843+
844+
const secondChipComp = fix.componentInstance.chips.toArray();
845+
846+
expect(chipAreaComp['selectedChips']).toEqual([secondChipComp[0], secondChipComp[1]]);
847+
expect(chipAreaComp.onSelection.emit).toHaveBeenCalledWith({
848+
originalEvent: null,
849+
owner: chipAreaComp,
850+
newSelection: [secondChipComp[0], secondChipComp[1]]
851+
});
852+
});
835853
});

0 commit comments

Comments
 (0)