Skip to content

Commit 778f524

Browse files
authored
Merge branch '18.0.x' into bpachilova/comboIdChangeInTemplate-fix-14305-18.0.x
2 parents 0394ade + ddbabc8 commit 778f524

3 files changed

Lines changed: 165 additions & 3 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@ All notable changes for each version of this project will be documented in this
7676
### General
7777
- `IgxGrid`, `IgxTreeGrid`, `IgxHierarchicalGrid`
7878
- The `contextMenu` event now fires when the end-user clicks to the right of the right-most cell in the grid in case the grid's columns don't span its full width. For this reason the event argument of the event is now of type `IGridContextMenuEventArgs` which contains the row object as well as the cell one. The latter will be `null` if the event didn't originate from a cell. **This is not a breaking change** as the new type extends the old.
79+
- `IgxSimpleCombo`
80+
- **Behavioral Change** The `selectionChanging` event will now trigger when typing the first character in the input if there is a previously selected value in the `IgxSimpleCombo`.
7981

8082
## 17.1.0
8183
### New Features

‎projects/igniteui-angular/src/lib/simple-combo/simple-combo.component.spec.ts‎

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1558,6 +1558,136 @@ describe('IgxSimpleCombo', () => {
15581558

15591559
expect(spy).toHaveBeenCalledTimes(1);
15601560
}));
1561+
1562+
it('should emit selectionChanging event when input value changes', () => {
1563+
spyOn(combo.selectionChanging, 'emit').and.callThrough();
1564+
fixture.detectChanges();
1565+
1566+
combo.select('Connecticut');
1567+
fixture.detectChanges();
1568+
1569+
expect(combo.selectionChanging.emit).toHaveBeenCalledTimes(1);
1570+
expect(combo.selectionChanging.emit).toHaveBeenCalledWith({
1571+
newValue: "Connecticut",
1572+
oldValue: undefined,
1573+
newSelection: {
1574+
field: "Connecticut",
1575+
region: "New England"
1576+
},
1577+
oldSelection: undefined,
1578+
displayText: 'Connecticut',
1579+
owner: combo,
1580+
cancel: false
1581+
});
1582+
1583+
combo.handleInputChange('z');
1584+
fixture.detectChanges();
1585+
1586+
expect(combo.selectionChanging.emit).toHaveBeenCalledTimes(2);
1587+
expect(combo.selectionChanging.emit).toHaveBeenCalledWith({
1588+
oldValue: "Connecticut",
1589+
newValue: undefined,
1590+
oldSelection: {
1591+
field: "Connecticut",
1592+
region: "New England"
1593+
},
1594+
newSelection: undefined,
1595+
owner: combo,
1596+
displayText: "z",
1597+
cancel: false
1598+
});
1599+
});
1600+
1601+
it('should not change selection when selectionChanging event is canceled', () => {
1602+
spyOn(combo.selectionChanging, 'emit').and.callThrough();
1603+
1604+
fixture.detectChanges();
1605+
1606+
combo.select('Connecticut');
1607+
fixture.detectChanges();
1608+
1609+
expect(combo.selection).toEqual({
1610+
field: 'Connecticut',
1611+
region: 'New England'
1612+
});
1613+
1614+
const cancelEventSpy = spyOn(combo.selectionChanging, 'emit').and.callFake((args: ISimpleComboSelectionChangingEventArgs) => {
1615+
args.cancel = true;
1616+
});
1617+
1618+
combo.handleInputChange('z');
1619+
fixture.detectChanges();
1620+
1621+
expect(cancelEventSpy).toHaveBeenCalled();
1622+
expect(combo.selection).toEqual({
1623+
field: 'Connecticut',
1624+
region: 'New England'
1625+
});
1626+
1627+
combo.handleInputChange(' ');
1628+
fixture.detectChanges();
1629+
1630+
expect(cancelEventSpy).toHaveBeenCalled();
1631+
expect(combo.selection).toEqual({
1632+
field: 'Connecticut',
1633+
region: 'New England'
1634+
});
1635+
});
1636+
1637+
1638+
it('should preserved the input value of the combo when selectionChanging event is canceled', () => {
1639+
spyOn(combo.selectionChanging, 'emit').and.callThrough();
1640+
fixture.detectChanges();
1641+
1642+
const comboInput = fixture.debugElement.query(By.css(`.igx-input-group__input`));
1643+
fixture.detectChanges();
1644+
1645+
combo.select('Connecticut');
1646+
fixture.detectChanges();
1647+
1648+
expect(combo.selection).toEqual({
1649+
field: 'Connecticut',
1650+
region: 'New England'
1651+
});
1652+
1653+
const cancelEventSpy = spyOn(combo.selectionChanging, 'emit').and.callFake((args: ISimpleComboSelectionChangingEventArgs) => {
1654+
args.cancel = true;
1655+
});
1656+
1657+
const clearButton = fixture.debugElement.query(By.css(`.${CSS_CLASS_CLEARBUTTON}`));
1658+
clearButton.triggerEventHandler('click', UIInteractions.getMouseEvent('click'));
1659+
fixture.detectChanges();
1660+
1661+
expect(cancelEventSpy).toHaveBeenCalled();
1662+
expect(combo.selection).toEqual({
1663+
field: 'Connecticut',
1664+
region: 'New England'
1665+
});
1666+
1667+
expect(comboInput.nativeElement.value).toEqual('Connecticut');
1668+
1669+
combo.handleInputChange('z');
1670+
fixture.detectChanges();
1671+
1672+
expect(cancelEventSpy).toHaveBeenCalled();
1673+
expect(combo.selection).toEqual({
1674+
field: 'Connecticut',
1675+
region: 'New England'
1676+
});
1677+
1678+
expect(comboInput.nativeElement.value).toEqual('Connecticut');
1679+
1680+
combo.handleInputChange(' ');
1681+
fixture.detectChanges();
1682+
1683+
expect(cancelEventSpy).toHaveBeenCalled();
1684+
expect(combo.selection).toEqual({
1685+
field: 'Connecticut',
1686+
region: 'New England'
1687+
});
1688+
1689+
expect(comboInput.nativeElement.value).toEqual('Connecticut');
1690+
});
15611691
});
15621692

15631693
describe('Display density', () => {

‎projects/igniteui-angular/src/lib/simple-combo/simple-combo.component.ts‎

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,19 @@ export class IgxSimpleComboComponent extends IgxComboBaseDirective implements Co
292292
this.filterValue = '';
293293
}
294294
if (super.selection.length) {
295-
this.selectionService.clear(this.id);
295+
const args: ISimpleComboSelectionChangingEventArgs = {
296+
newValue: undefined,
297+
oldValue: this.selectedItem,
298+
newSelection: undefined,
299+
oldSelection: this.selection,
300+
displayText: typeof event === 'string' ? event : event?.target?.value,
301+
owner: this,
302+
cancel: false
303+
};
304+
this.selectionChanging.emit(args);
305+
if (!args.cancel) {
306+
this.selectionService.select_items(this.id, [], true);
307+
}
296308
}
297309
// when filtering the focused item should be the first item or the currently selected item
298310
if (!this.dropdown.focusedItem || this.dropdown.focusedItem.id !== this.dropdown.items[0].id) {
@@ -388,13 +400,19 @@ export class IgxSimpleComboComponent extends IgxComboBaseDirective implements Co
388400
if (this.disabled) {
389401
return;
390402
}
403+
404+
const oldSelection = this.selection;
391405
this.clearSelection(true);
406+
392407
if(!this.collapsed){
393408
this.focusSearchInput(true);
394409
}
395410
event.stopPropagation();
396411

397-
this.comboInput.value = this.filterValue = this.searchValue = '';
412+
if (this.selection !== oldSelection) {
413+
this.comboInput.value = this.filterValue = this.searchValue = '';
414+
}
415+
398416
this.dropdown.focusedItem = null;
399417
this.composing = false;
400418
this.comboInput.focus();
@@ -486,6 +504,15 @@ export class IgxSimpleComboComponent extends IgxComboBaseDirective implements Co
486504
this._updateInput = true;
487505
} else if (this.isRemote) {
488506
this.registerRemoteEntries(newValueAsArray, false);
507+
} else {
508+
args.displayText = this.createDisplayText(oldItems, []);
509+
510+
const oldSelectionArray = args.oldSelection ? [args.oldSelection] : [];
511+
this.comboInput.value = this._displayValue = this.searchValue = this.createDisplayText(oldSelectionArray, []);
512+
513+
if (this.isRemote) {
514+
this.registerRemoteEntries(newValueAsArray, false);
515+
}
489516
}
490517
}
491518

@@ -558,7 +585,10 @@ export class IgxSimpleComboComponent extends IgxComboBaseDirective implements Co
558585

559586
private clear(): void {
560587
this.clearSelection(true);
561-
this.comboInput.value = this._displayValue = this.searchValue = '';
588+
const oldSelection = this.selection;
589+
if (this.selection !== oldSelection) {
590+
this.comboInput.value = this._displayValue = this.searchValue = '';
591+
}
562592
}
563593

564594
private isValid(value: any): boolean {

0 commit comments

Comments
 (0)