Skip to content

Commit b669065

Browse files
feat(IgxSimpleCombo): not open the drop-down on clear (#12790)
* feat(IgxSimpleCombo): not open the drop-down on clear * feat(IgxSimpleCombo): added demo samples for the old behavior * feat(IgxSimpleCombo): added breaking change feat to the changelog * feat(IgxSimpleCombo): added required changes * feat(IgxSimpleCombo): added overload for handleSelectionChanging * feat(IgxSimpleCombo): chenged handleSelectionChanging function logic * feat(IgxSimpleCombo): removed unused member
1 parent f2287ae commit b669065

File tree

5 files changed

+60
-17
lines changed

5 files changed

+60
-17
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ All notable changes for each version of this project will be documented in this
6666
- **Breaking Changes** - ` $label-floated-background` and `$label-floated-disabled-background` properties of `IgxInputGroupComponent` theme has been removed.
6767
- `IgxInputGroupComponent` The input group has been refactored so that the floating label for the input of `type="border"` does not require a background to match the surface background under the input field. Also, suffixes and prefixes are refactored to take the full height of the input which makes it easy to add background to them.
6868
- **Breaking Changes** - `$size` property of `scrollbar-theme` theme has been renamed to `$scrollbar-size`.
69+
- `IgxSimpleCombo`
70+
- The `IgxSimpleCombo` will not open its drop-down on clear.
6971

7072
## 15.0.1
7173

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

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1440,12 +1440,19 @@ describe('IgxSimpleCombo', () => {
14401440
tick();
14411441
fixture.detectChanges();
14421442
expect(combo.collapsed).toEqual(true);
1443+
}));
1444+
1445+
it('should not open when clearing the selection from the clear icon when the combo is collapsed', fakeAsync(() => {
1446+
fixture = TestBed.createComponent(IgxSimpleComboSampleComponent);
1447+
fixture.detectChanges();
1448+
combo = fixture.componentInstance.combo;
1449+
1450+
combo.select('Connecticut');
1451+
fixture.detectChanges();
14431452

14441453
combo.handleClear(new MouseEvent('click'));
14451454
fixture.detectChanges();
1446-
expect(combo.value).toEqual('');
1447-
expect(combo.collapsed).toEqual(false);
1448-
expect(combo.overlaySettings.positionStrategy.settings.verticalDirection).toBe(-1);
1455+
expect(combo.collapsed).toEqual(true);
14491456
}));
14501457
});
14511458

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

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -378,12 +378,7 @@ export class IgxSimpleComboComponent extends IgxComboBaseDirective implements Co
378378
return;
379379
}
380380
this.clearSelection(true);
381-
if (this.collapsed) {
382-
this.filterValue = '';
383-
this.cdr.detectChanges();
384-
this.open();
385-
this.dropdown.navigateFirst();
386-
} else {
381+
if(!this.collapsed){
387382
this.focusSearchInput(true);
388383
}
389384
event.stopPropagation();

src/app/combo/combo.sample.html

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,39 @@ <h1 class="combo-sample__title">Remote Binding</h1>
106106
</igx-simple-combo>
107107
</section>
108108

109+
<section class="combo-sample__section">
110+
<h1 class="combo-sample__title">Simple combo that opens on clear by handling its selectionChanging event</h1>
111+
<igx-simple-combo
112+
#simpleComboOpenOnClear
113+
[displayDensity]="'comfortable'"
114+
[(ngModel)]="singleValue"
115+
type="border"
116+
[data]="items"
117+
[displayKey]="valueKeyVar"
118+
[disabled]="isDisabled"
119+
[valueKey]="valueKeyVar"
120+
[groupKey]="valueKeyVar ? 'region' : ''"
121+
(selectionChanging)="handleSelectionChanging($event)">
122+
<label igxLabel>States</label>
123+
</igx-simple-combo>
124+
<h1 class="combo-sample__title">Simple combo that opens after its templated clear icon is clicked</h1>
125+
<igx-simple-combo
126+
#simpleComboOpenOnClearWithTemplate
127+
[displayDensity]="'comfortable'"
128+
[(ngModel)]="singleValue"
129+
type="border"
130+
[data]="items"
131+
[displayKey]="valueKeyVar"
132+
[disabled]="isDisabled"
133+
[valueKey]="valueKeyVar"
134+
[groupKey]="valueKeyVar ? 'region' : ''" >
135+
<label igxLabel>States</label>
136+
<ng-template igxComboClearIcon>
137+
<igx-icon (click)="simpleComboOpenOnClearWithTemplate.open()">cancel</igx-icon>
138+
</ng-template>
139+
</igx-simple-combo>
140+
</section>
141+
109142
<section class="combo-sample__section">
110143
<h1 class="combo-sample__title">Template items</h1>
111144

@@ -145,7 +178,7 @@ <h1 class="combo-sample__title">Template items</h1>
145178
<igx-combo #playgroundCombo [placeholder]="'Locations'"
146179
[showSearchCaseIcon]='true'
147180
(addition)="handleAddition($event)"
148-
(selectionChanging)="handleSelectionChange($event)"
181+
(selectionChanging)="handleSelectionChanging($event)"
149182
[data]="items"
150183
[allowCustomValues]="customValuesFlag"
151184
[autoFocusSearch]="autoFocusSearch"

src/app/combo/combo.sample.ts

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,10 @@ export class ComboSampleComponent implements OnInit, AfterViewInit {
5454
private customItemTemplate;
5555

5656
@ViewChild('simpleCombo', { read: IgxSimpleComboComponent, static: true })
57-
private simpleCombo;
57+
private simpleCombo: IgxSimpleComboComponent;
58+
59+
@ViewChild('simpleComboOpenOnClear')
60+
public simpleComboOpenOnClear: IgxSimpleComboComponent;
5861

5962
public alignment: ButtonGroupAlignment = ButtonGroupAlignment.vertical;
6063
public toggleItemState = false;
@@ -251,10 +254,6 @@ export class ComboSampleComponent implements OnInit, AfterViewInit {
251254
this.densityCombo.displayDensity = density;
252255
}
253256

254-
public handleSelectionChange(event: IComboSelectionChangingEventArgs) {
255-
console.log(event);
256-
}
257-
258257
public changeFiltering(e: IChangeSwitchEventArgs) {
259258
if (e.checked) {
260259
this.igxCombo.filterFunction = this.customFilterFunction;
@@ -330,8 +329,15 @@ export class ComboSampleComponent implements OnInit, AfterViewInit {
330329
this.searchText = '';
331330
}
332331

333-
public handleSelectionChanging(evt: IComboSelectionChangingEventArgs) {
334-
this.hasSelection = !!evt?.newSelection.length;
332+
public handleSelectionChanging(evt: IComboSelectionChangingEventArgs | ISimpleComboSelectionChangingEventArgs) {
333+
if ('added' in evt) {
334+
this.hasSelection = !!evt?.newSelection.length;
335+
return;
336+
}
337+
338+
if (!evt.newSelection) {
339+
this.simpleComboOpenOnClear.open();
340+
}
335341
}
336342

337343
public onSimpleComboDataLoading() {

0 commit comments

Comments
 (0)