Skip to content

Commit 4715b6a

Browse files
skrustevmpavlinov
authored andcommitted
feat(IgxChip): Add new event when select animation is ended. Update the advanced filtering to use it instead. (#5822)
* feat(IgxChip): Add new event when select animation is ended. Update the advanced filtering to use it instead. * chore(*): Remove running specific test. * chore(*): Make private functions public and move test function to async function. * chore(*): Change onSelectionEnd to onSelectionDone. FIx tests. * fix(igxDrag): Fix onSelectionDone event triggered twice on IE and Edge. #5821
1 parent 3f7c777 commit 4715b6a

File tree

7 files changed

+119
-57
lines changed

7 files changed

+119
-57
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ For more information about the theming please read our [documentation](https://w
6464
- introduced a new `readonly` property that doesn't allow user interaction to change the state, but keeps the default active style. Intended for integration in complex controls that handle the interaction and control the checkbox instead through binding.
6565
- `IgxOverlay`
6666
- introduced a new `ContainerPositionStrategy`. The new strategy positions the element inside the containing outlet based on the directions passed in trough PositionSettings.
67+
- `IgxChip`
68+
- add `onSelectionDone` event that is triggered after all animations and transitions related to selection have ended.
6769

6870
### General
6971
- `IgxGrid`, `IgxTreeGrid`, `IgxHierarchicalGrid`

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
(enter)="onChipDragEnterHandler($event)"
1313
(dropped)="onChipDrop($event)">
1414

15-
<div [ngClass]="selectClass(selected)">
15+
<div [ngClass]="selectClass(selected)" (transitionend)="onSelectTransitionDone($event)">
1616
<ng-container *ngTemplateOutlet="selectIconTemplate"></ng-container>
1717
</div>
1818

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

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,12 +281,26 @@ export class IgxChipComponent extends DisplayDensityBase {
281281
* }
282282
* ```
283283
* ```html
284-
* <igx-chip #myChip [id]="'igx-chip-1'" [draggable]="true" (onSelection)="chipSelect($event)">
284+
* <igx-chip #myChip [id]="'igx-chip-1'" [selectable]="true" (onSelection)="chipSelect($event)">
285285
* ```
286286
*/
287287
@Output()
288288
public onSelection = new EventEmitter<IChipSelectEventArgs>();
289289

290+
/**
291+
* Emits event when the `IgxChipComponent` is selected/deselected and any related animations and transitions also end.
292+
* ```typescript
293+
* chipSelectEnd(event: IBaseChipEventArgs){
294+
* let selectedChip = event.owner;
295+
* }
296+
* ```
297+
* ```html
298+
* <igx-chip #myChip [id]="'igx-chip-1'" [selectable]="true" (onSelectionDone)="chipSelectEnd($event)">
299+
* ```
300+
*/
301+
@Output()
302+
public onSelectionDone = new EventEmitter<IBaseChipEventArgs>();
303+
290304
/**
291305
* Emits an event when the `IgxChipComponent` keyboard navigation is being used.
292306
* Returns the focused/selected `IgxChipComponent`, whether the event should be canceled,
@@ -435,6 +449,16 @@ export class IgxChipComponent extends DisplayDensityBase {
435449
}
436450
}
437451

452+
public onSelectTransitionDone(event) {
453+
if (event.propertyName === 'width' && !!event.target.tagName) {
454+
// Trigger onSelectionDone on when `width` property is changed and the target is valid element(not comment).
455+
this.onSelectionDone.emit({
456+
owner: this,
457+
originalEvent: event
458+
});
459+
}
460+
}
461+
438462
/**
439463
* @hidden
440464
*/

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

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { IgxPrefixDirective } from './../directives/prefix/prefix.directive';
1313
import { IgxLabelDirective } from './../directives/label/label.directive';
1414
import { IgxSuffixDirective } from './../directives/suffix/suffix.directive';
1515
import { DisplayDensity } from '../core/displayDensity';
16-
import { UIInteractions} from '../test-utils/ui-interactions.spec';
16+
import { UIInteractions, wait} from '../test-utils/ui-interactions.spec';
1717
import { configureTestSuite } from '../test-utils/configure-suite';
1818

1919
@Component({
@@ -398,13 +398,14 @@ describe('IgxChip', () => {
398398
});
399399
});
400400

401-
it('should fire onSelection event when selectable is true', () => {
401+
it('should fire onSelection event when selectable is true', (async() => {
402402
const fix = TestBed.createComponent(TestChipComponent);
403403
fix.detectChanges();
404404

405405
const secondChipComp = fix.componentInstance.chips.toArray()[1];
406406

407407
spyOn(secondChipComp.onSelection, 'emit');
408+
spyOn(secondChipComp.onSelectionDone, 'emit');
408409
secondChipComp.chipArea.nativeElement.focus();
409410

410411
const keyEvent = new KeyboardEvent('keydown', {
@@ -413,7 +414,11 @@ describe('IgxChip', () => {
413414
secondChipComp.chipArea.nativeElement.dispatchEvent(keyEvent);
414415
fix.detectChanges();
415416
expect(secondChipComp.onSelection.emit).toHaveBeenCalled();
416-
});
417+
expect(secondChipComp.onSelectionDone.emit).not.toHaveBeenCalled();
418+
419+
await wait(400);
420+
expect(secondChipComp.onSelectionDone.emit).toHaveBeenCalled();
421+
}));
417422

418423
it('should not fire onSelection event when selectable is false', () => {
419424
const fix = TestBed.createComponent(TestChipComponent);
@@ -422,6 +427,7 @@ describe('IgxChip', () => {
422427
const firstChipComp = fix.componentInstance.chips.toArray()[0];
423428

424429
spyOn(firstChipComp.onSelection, 'emit');
430+
spyOn(firstChipComp.onSelectionDone, 'emit');
425431
firstChipComp.elementRef.nativeElement.focus();
426432

427433
const keyEvent = new KeyboardEvent('keydown', {
@@ -430,6 +436,7 @@ describe('IgxChip', () => {
430436
firstChipComp.elementRef.nativeElement.dispatchEvent(keyEvent);
431437
fix.detectChanges();
432438
expect(firstChipComp.onSelection.emit).toHaveBeenCalledTimes(0);
439+
expect(firstChipComp.onSelectionDone.emit).toHaveBeenCalledTimes(0);
433440
});
434441

435442
it('should not fire onSelection event when the remove button is clicked', () => {
@@ -439,6 +446,7 @@ describe('IgxChip', () => {
439446
const secondChipComp = fix.componentInstance.chips.toArray()[1];
440447

441448
spyOn(secondChipComp.onSelection, 'emit');
449+
spyOn(secondChipComp.onSelectionDone, 'emit');
442450

443451
const chipRemoveButton = secondChipComp.elementRef.nativeElement.querySelectorAll('.' + CHIP_REMOVE_BUTTON)[0];
444452
const removeBtnTop = chipRemoveButton.getBoundingClientRect().top;
@@ -450,5 +458,6 @@ describe('IgxChip', () => {
450458
fix.detectChanges();
451459

452460
expect(secondChipComp.onSelection.emit).not.toHaveBeenCalled();
461+
expect(secondChipComp.onSelectionDone.emit).not.toHaveBeenCalled();
453462
});
454463
});

projects/igniteui-angular/src/lib/grids/filtering/advanced-filtering/advanced-filtering-dialog.component.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ <h6 class="igx-filter-empty__title">
9494
(click)="onChipClick(expressionItem)"
9595
(dblclick)="onChipDblClick(expressionItem)"
9696
(onRemove)="onChipRemove(expressionItem)"
97+
(onSelectionDone)="onChipSelectionEnd()"
9798
>
9899
<span igxPrefix class="igx-filter-tree__expression-column">{{ expressionItem.expression.fieldName }}</span>
99100
<igx-icon

projects/igniteui-angular/src/lib/grids/filtering/advanced-filtering/advanced-filtering-dialog.component.ts

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -538,15 +538,6 @@ export class IgxAdvancedFilteringDialogComponent implements AfterViewInit, OnDes
538538
}
539539
];
540540
}
541-
542-
setTimeout(() => {
543-
this.calculateContextMenuTarget();
544-
if (this.contextMenuToggle.collapsed) {
545-
this.contextMenuToggle.open(this._overlaySettings);
546-
} else {
547-
this.contextMenuToggle.reposition();
548-
}
549-
}, 200);
550541
} else {
551542
this.contextMenuToggle.close();
552543
}
@@ -832,4 +823,17 @@ export class IgxAdvancedFilteringDialogComponent implements AfterViewInit, OnDes
832823
this.applyChanges();
833824
this.closeDialog();
834825
}
826+
827+
public onChipSelectionEnd() {
828+
const contextualGroup = this.findSingleSelectedGroup();
829+
if (contextualGroup || this.selectedExpressions.length > 1) {
830+
this.contextualGroup = contextualGroup;
831+
this.calculateContextMenuTarget();
832+
if (this.contextMenuToggle.collapsed) {
833+
this.contextMenuToggle.open(this._overlaySettings);
834+
} else {
835+
this.contextMenuToggle.reposition();
836+
}
837+
}
838+
}
835839
}

0 commit comments

Comments
 (0)