Skip to content

Commit 8268cdd

Browse files
fix(IgxComboBase,IgxSimpleCombo): open the simple combo dropdown in the correct vertical direction #12648 (#12702)
1 parent ff2e89b commit 8268cdd

File tree

3 files changed

+103
-2
lines changed

3 files changed

+103
-2
lines changed

projects/igniteui-angular/src/lib/combo/combo.common.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1030,6 +1030,10 @@ export abstract class IgxComboBaseDirective extends DisplayDensityBase implement
10301030
* ```
10311031
*/
10321032
public toggle(): void {
1033+
if (this.collapsed && this._value.length !== 0) {
1034+
this.filterValue = '';
1035+
this.cdr.detectChanges();
1036+
}
10331037
const overlaySettings = Object.assign({}, this._overlaySettings, this.overlaySettings);
10341038
this.dropdown.toggle(overlaySettings);
10351039
if (!this.collapsed){
@@ -1046,6 +1050,10 @@ export abstract class IgxComboBaseDirective extends DisplayDensityBase implement
10461050
* ```
10471051
*/
10481052
public open(): void {
1053+
if (this.collapsed && this._value.length !== 0) {
1054+
this.filterValue = '';
1055+
this.cdr.detectChanges();
1056+
}
10491057
const overlaySettings = Object.assign({}, this._overlaySettings, this.overlaySettings);
10501058
this.dropdown.open(overlaySettings);
10511059
this.setActiveDescendant();

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

Lines changed: 93 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { IBaseCancelableBrowserEventArgs, PlatformUtil } from '../core/utils';
1313
import { IgxToggleModule } from '../directives/toggle/toggle.directive';
1414
import { IgxIconComponent, IgxIconModule, IgxIconService } from '../icon/public_api';
1515
import { IgxInputState } from '../input-group/public_api';
16-
import { AbsoluteScrollStrategy, ConnectedPositioningStrategy } from '../services/public_api';
16+
import { AbsoluteScrollStrategy, AutoPositionStrategy, ConnectedPositioningStrategy } from '../services/public_api';
1717
import { configureTestSuite } from '../test-utils/configure-suite';
1818
import { UIInteractions, wait } from '../test-utils/ui-interactions.spec';
1919
import { IgxSimpleComboComponent, IgxSimpleComboModule, ISimpleComboSelectionChangingEventArgs } from './public_api';
@@ -811,7 +811,8 @@ describe('IgxSimpleCombo', () => {
811811
declarations: [
812812
IgxSimpleComboSampleComponent,
813813
IgxComboInContainerTestComponent,
814-
IgxSimpleComboIconTemplatesComponent
814+
IgxSimpleComboIconTemplatesComponent,
815+
IgxBottomPositionSimpleComboComponent
815816
],
816817
imports: [
817818
IgxSimpleComboModule,
@@ -1387,6 +1388,52 @@ describe('IgxSimpleCombo', () => {
13871388
clearButton = fixture.debugElement.query(By.css(`.${CSS_CLASS_CLEARBUTTON}`));
13881389
expect(clearButton).toBeNull();
13891390
});
1391+
1392+
it('should open the combo to the top when there is no space to open to the bottom', fakeAsync(() => {
1393+
fixture = TestBed.createComponent(IgxBottomPositionSimpleComboComponent);
1394+
fixture.detectChanges();
1395+
combo = fixture.componentInstance.combo;
1396+
1397+
const newSettings = {
1398+
positionStrategy: new AutoPositionStrategy(),
1399+
scrollStrategy: new AbsoluteScrollStrategy()
1400+
};
1401+
combo.overlaySettings = newSettings;
1402+
fixture.detectChanges();
1403+
1404+
combo.open();
1405+
fixture.detectChanges();
1406+
expect(combo.collapsed).toEqual(false);
1407+
expect(combo.overlaySettings.positionStrategy.settings.verticalDirection).toBe(-1);
1408+
1409+
combo.select('Connecticut');
1410+
fixture.detectChanges();
1411+
1412+
expect(combo.selection.length).toBe(1);
1413+
expect(combo.selection[0]).toEqual('Connecticut');
1414+
fixture.detectChanges();
1415+
1416+
combo.dropdown.close();
1417+
tick();
1418+
fixture.detectChanges();
1419+
expect(combo.collapsed).toEqual(true);
1420+
1421+
combo.open();
1422+
fixture.detectChanges();
1423+
expect(combo.collapsed).toEqual(false);
1424+
expect(combo.overlaySettings.positionStrategy.settings.verticalDirection).toBe(-1);
1425+
1426+
combo.dropdown.close();
1427+
tick();
1428+
fixture.detectChanges();
1429+
expect(combo.collapsed).toEqual(true);
1430+
1431+
combo.handleClear(new MouseEvent('click'));
1432+
fixture.detectChanges();
1433+
expect(combo.value).toEqual('');
1434+
expect(combo.collapsed).toEqual(false);
1435+
expect(combo.overlaySettings.positionStrategy.settings.verticalDirection).toBe(-1);
1436+
}));
13901437
});
13911438

13921439
describe('Display density', () => {
@@ -2198,3 +2245,47 @@ export class IgxSimpleComboBindingDataAfterInitComponent implements AfterViewIni
21982245
});
21992246
}
22002247
}
2248+
2249+
@Component({
2250+
template: `
2251+
<div style="display: flex; flex-direction: column; height: 100%; justify-content: flex-end;">
2252+
<igx-simple-combo #combo [data]="items" [displayKey]="'field'" [valueKey]="'field'" [width]="'100%'"
2253+
style="margin-bottom: 60px;">
2254+
</igx-simple-combo>
2255+
</div>`
2256+
})
2257+
export class IgxBottomPositionSimpleComboComponent {
2258+
@ViewChild('combo', { read: IgxSimpleComboComponent, static: true })
2259+
public combo: IgxSimpleComboComponent;
2260+
public items: any[] = [];
2261+
2262+
constructor() {
2263+
const division = {
2264+
'New England 01': ['Connecticut', 'Maine', 'Massachusetts'],
2265+
'New England 02': ['New Hampshire', 'Rhode Island', 'Vermont'],
2266+
'Mid-Atlantic': ['New Jersey', 'New York', 'Pennsylvania'],
2267+
'East North Central 02': ['Michigan', 'Ohio', 'Wisconsin'],
2268+
'East North Central 01': ['Illinois', 'Indiana'],
2269+
'West North Central 01': ['Missouri', 'Nebraska', 'North Dakota', 'South Dakota'],
2270+
'West North Central 02': ['Iowa', 'Kansas', 'Minnesota'],
2271+
'South Atlantic 01': ['Delaware', 'Florida', 'Georgia', 'Maryland'],
2272+
'South Atlantic 02': ['North Carolina', 'South Carolina', 'Virginia'],
2273+
'South Atlantic 03': ['District of Columbia', 'West Virginia'],
2274+
'East South Central 01': ['Alabama', 'Kentucky'],
2275+
'East South Central 02': ['Mississippi', 'Tennessee'],
2276+
'West South Central': ['Arkansas', 'Louisiana', 'Oklahome', 'Texas'],
2277+
Mountain: ['Arizona', 'Colorado', 'Idaho', 'Montana', 'Nevada', 'New Mexico', 'Utah', 'Wyoming'],
2278+
'Pacific 01': ['Alaska', 'California'],
2279+
'Pacific 02': ['Hawaii', 'Oregon', 'Washington']
2280+
};
2281+
const keys = Object.keys(division);
2282+
for (const key of keys) {
2283+
division[key].map((e) => {
2284+
this.items.push({
2285+
field: e,
2286+
region: key.substring(0, key.length - 3)
2287+
});
2288+
});
2289+
}
2290+
}
2291+
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,8 @@ export class IgxSimpleComboComponent extends IgxComboBaseDirective implements Co
378378
}
379379
this.clearSelection(true);
380380
if (this.collapsed) {
381+
this.filterValue = '';
382+
this.cdr.detectChanges();
381383
this.open();
382384
this.dropdown.navigateFirst();
383385
} else {

0 commit comments

Comments
 (0)