Skip to content

Commit df813f1

Browse files
authored
Merge branch 'master' into mkirova/fix-6701-master
2 parents bbec2a2 + e0e2290 commit df813f1

File tree

7 files changed

+60
-5
lines changed

7 files changed

+60
-5
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ All notable changes for each version of this project will be documented in this
1414
```typescript
1515
public pinningConfiguration: IPinningConfig = { columns: ColumnPinningPosition.End };
1616
```
17+
- `IgxCombo`:
18+
- Added `autoFocusSearch` input that allows to manipulate the combo's opening behavior. When the property is `true` (by default), the combo's search input is focused on open. When set to `false`, the focus goes to the combo items container, which can be used to prevent the software keyboard from activating on mobile devices when opening the combo.
1719

1820
### RTL Support
1921
- `igxSlider` have full right-to-left (RTL) support.
@@ -2487,4 +2489,3 @@ export class IgxCustomFilteringOperand extends IgxFilteringOperand {
24872489
- `IgxDraggableDirective` moved inside `../directives/dragdrop/` folder
24882490
- `IgxRippleDirective` moved inside `../directives/ripple/` folder
24892491
- Folder `"./navigation/nav-service"` renamed to `"./navigation/nav.service"`
2490-

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,7 @@ Setting `[displayDensity]` affects the control's items' and inputs' css properti
314314
| `type` | Combo style. - "line", "box", "border", "search" | string |
315315
| `valid` | gets if control is valid, when used in a form | boolean |
316316
| `overlaySettings` | gets/sets the custom overlay settings that control how the drop-down list displays | OverlaySettings |
317+
| `autoFocusSearch` | controls whether the search input should be focused when the combo is opened | boolean |
317318

318319
### Getters
319320
| Name | Description | Type |

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

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,24 @@ describe('igxCombo', () => {
149149
expect(combo.dropdown.toggle).toHaveBeenCalledTimes(1);
150150
expect(combo.collapsed).toBe(false);
151151
});
152+
it(`should not focus search input when property autoFocusSearch=false`, () => {
153+
combo = new IgxComboComponent({ nativeElement: null }, mockCdr, mockSelection as any, mockComboService, null, mockInjector);
154+
const dropdownContainer = { nativeElement: { focus: () => {}}};
155+
combo['dropdownContainer'] = dropdownContainer;
156+
spyOn(combo, 'focusSearchInput');
157+
158+
combo.autoFocusSearch = false;
159+
combo.handleOpened();
160+
expect(combo.focusSearchInput).toHaveBeenCalledTimes(0);
161+
162+
combo.autoFocusSearch = true;
163+
combo.handleOpened();
164+
expect(combo.focusSearchInput).toHaveBeenCalledTimes(1);
165+
166+
combo.autoFocusSearch = false;
167+
combo.handleOpened();
168+
expect(combo.focusSearchInput).toHaveBeenCalledTimes(1);
169+
});
152170
it('should call dropdown toggle with correct overlaySettings', () => {
153171
combo = new IgxComboComponent({ nativeElement: null }, mockCdr, mockSelection as any, mockComboService, null, mockInjector);
154172
const dropdown = jasmine.createSpyObj('IgxComboDropDownComponent', ['toggle']);
@@ -788,6 +806,19 @@ describe('igxCombo', () => {
788806
fixture.detectChanges();
789807
expect(combo.searchInput).toBeFalsy();
790808
});
809+
it('should focus search input', fakeAsync(() => {
810+
combo.toggle();
811+
tick();
812+
fixture.detectChanges();
813+
expect(document.activeElement).toEqual(combo.searchInput.nativeElement);
814+
}));
815+
it('should not focus search input, when autoFocusSearch=false', fakeAsync(() => {
816+
combo.autoFocusSearch = false;
817+
combo.toggle();
818+
tick();
819+
fixture.detectChanges();
820+
expect(document.activeElement).not.toEqual(combo.searchInput.nativeElement);
821+
}));
791822
it('should properly initialize templates', () => {
792823
expect(combo).toBeDefined();
793824
expect(combo.footerTemplate).toBeDefined();
@@ -983,7 +1014,7 @@ describe('igxCombo', () => {
9831014

9841015
productIndex = 485;
9851016
combo.virtualScrollContainer.scrollTo(productIndex);
986-
await wait();
1017+
await wait(30);
9871018
fixture.detectChanges();
9881019
verifyComboData();
9891020
expect(combo.virtualizationState.startIndex + combo.virtualizationState.chunkSize - 1)

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

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -813,6 +813,14 @@ export class IgxComboComponent extends DisplayDensityBase implements IgxComboBas
813813
@Input()
814814
public type = 'box';
815815

816+
/**
817+
* An @Input property that controls whether the combo's search box
818+
* should be focused after the `onOpened` event is called
819+
* When `false`, the combo's list item container will be focused instead
820+
*/
821+
@Input()
822+
public autoFocusSearch = true;
823+
816824
/**
817825
* Gets if control is valid, when used in a form
818826
*
@@ -1480,7 +1488,15 @@ export class IgxComboComponent extends DisplayDensityBase implements IgxComboBas
14801488
*/
14811489
public handleOpened() {
14821490
this.triggerCheck();
1483-
this.focusSearchInput(true);
1491+
1492+
// Disabling focus of the search input should happen only when drop down opens.
1493+
// During keyboard navigation input should receive focus, even the autoFocusSearch is disabled.
1494+
// That is why in such cases focusing of the dropdownContainer happens outside focusSearchInput method.
1495+
if (this.autoFocusSearch) {
1496+
this.focusSearchInput(true);
1497+
} else {
1498+
this.dropdownContainer.nativeElement.focus();
1499+
}
14841500
this.onOpened.emit();
14851501
}
14861502

projects/igniteui-angular/src/lib/directives/for-of/for_of.directive.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1185,15 +1185,18 @@ export class IgxForOfDirective<T> implements OnInit, OnChanges, DoCheck, OnDestr
11851185
this.scrollComponent.size = totalWidth;
11861186
if (totalWidth <= parseInt(this.igxForContainerSize, 10)) {
11871187
this.scrollPosition = 0;
1188+
// Need to reset the scrollAmount value here, because horizontalScrollBar is hidden, therefore
1189+
// onScroll event handler for VirtualHelperBaseDirective will not be called
1190+
this.scrollComponent.scrollAmount = 0;
11881191
}
11891192
}
11901193
if (this.igxForScrollOrientation === 'vertical') {
11911194
this.scrollComponent.nativeElement.style.height = parseInt(this.igxForContainerSize, 10) + 'px';
11921195
this.scrollComponent.size = this._calcHeight();
11931196
if ( this.scrollComponent.size <= parseInt(this.igxForContainerSize, 10)) {
11941197
this.scrollPosition = 0;
1195-
// Need to reset the scrollAmount value here, because
1196-
// Firefox will not fire the scrollComponent scroll event handler
1198+
// Need to reset the scrollAmount value here, because verticalScrollBar is hidden, therefore
1199+
// onScroll event handler for VirtualHelperBaseDirective will not be called
11971200
this.scrollComponent.scrollAmount = 0;
11981201
}
11991202
}

src/app/combo/combo.sample.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
[data]="items"
2323
[allowCustomValues]="customValuesFlag"
2424
[displayDensity]="'comfortable'"
25+
[autoFocusSearch]="autoFocusSearch"
2526
[filterable]="filterableFlag" [displayKey]="valueKeyVar" [valueKey]="valueKeyVar"
2627
[groupKey]="valueKeyVar ? 'region' : ''" [width]="'100%'">
2728
<ng-template *ngIf="currentDataType !== 'primitive'" #itemTemplate let-display let-key="valueKey">
@@ -101,6 +102,7 @@ <h4>Display Density</h4>
101102
<h4>Search Input</h4>
102103
<igx-switch [(ngModel)]="filterableFlag">Filterable</igx-switch><br/>
103104
<igx-switch [(ngModel)]="customValuesFlag">Custom Values</igx-switch>
105+
<igx-switch [(ngModel)]="autoFocusSearch">Automatic Search Focus</igx-switch>
104106
</div>
105107
<div>
106108
<h4>Overlay Settings</h4>

src/app/combo/combo.sample.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ export class ComboSampleComponent implements OnInit, AfterViewInit {
4343
private initData: any[] = [];
4444
public filterableFlag = true;
4545
public customValuesFlag = true;
46+
public autoFocusSearch = true;
4647
public items: any[] = [];
4748
public values1: Array<any>;
4849
public values2: Array<any>;

0 commit comments

Comments
 (0)