Skip to content

Commit 28d334f

Browse files
Simple-combo: Opening the combo on input click - master (#12618)
* chore(simple-combo): Opening the combo when the user has clicked on the input * chore(changelog): Adding behavior changes of the simple-combo in changelog
1 parent 3b8ece3 commit 28d334f

File tree

4 files changed

+46
-3
lines changed

4 files changed

+46
-3
lines changed

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ All notable changes for each version of this project will be documented in this
1414
- `igxPivotGrid`
1515
- Adding `aggregatorName` for pivot value configuration as an alternative to setting `aggregator` function. If both are set `aggregatorName` takes precedent. If none are set an error is thrown.
1616
- `IgxSimpleCombo`
17-
- **Behavioral Change** - Keyboard navigation `ArrowUp` - when the combo is opened `ArrowUp` will close the dropdown if the search input is focused. If the active item is the first one in the list, the focus will be moved back to the search input while also selecting all of the text in the input. Otherwise `ArrowUp` will move to the previous list item.
17+
- **Behavioral Change**
18+
- When the user clicks on the combo's input, the dropdown opens up.
19+
- Keyboard navigation `ArrowUp` - when the combo is opened `ArrowUp` will close the dropdown if the search input is focused. If the active item is the first one in the list, the focus will be moved back to the search input while also selecting all of the text in the input. Otherwise `ArrowUp` will move to the previous list item.
1820

1921
## 15.0.0
2022

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
[attr.aria-expanded]="!this.dropdown.collapsed" [attr.aria-controls]="this.dropdown.listId"
1515
[attr.aria-labelledby]="this.ariaLabelledBy || this.label?.id || this.placeholder"
1616
[attr.placeholder]="placeholder" [disabled]="disabled" [igxTextSelection]="!composing"
17-
(focus)="onFocus()" (input)="handleInputChange($event)"
17+
(focus)="onFocus()" (input)="handleInputChange($event)" (click)="handleInputClick()"
1818
(keyup)="handleKeyUp($event)" (keydown)="handleKeyDown($event)" (blur)="onBlur()"/>
1919

2020
<ng-container ngProjectAs="igx-suffix">

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

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1139,6 +1139,37 @@ describe('IgxSimpleCombo', () => {
11391139
expect(combo.selection.length).toEqual(0);
11401140
});
11411141

1142+
it('should open the combo when input is focused', () => {
1143+
spyOn(combo, 'open').and.callThrough();
1144+
spyOn(combo, 'close').and.callThrough();
1145+
1146+
input.triggerEventHandler('focus', {});
1147+
fixture.detectChanges();
1148+
1149+
input.triggerEventHandler('click', UIInteractions.getMouseEvent('click'));
1150+
fixture.detectChanges();
1151+
1152+
expect(combo.open).toHaveBeenCalledTimes(1);
1153+
1154+
input.triggerEventHandler('click', UIInteractions.getMouseEvent('click'));
1155+
fixture.detectChanges();
1156+
1157+
expect(combo.open).toHaveBeenCalledTimes(1);
1158+
1159+
UIInteractions.triggerEventHandlerKeyDown('Tab', input);
1160+
fixture.detectChanges();
1161+
1162+
expect(combo.close).toHaveBeenCalledTimes(1);
1163+
1164+
input.triggerEventHandler('focus', {});
1165+
fixture.detectChanges();
1166+
1167+
input.triggerEventHandler('click', UIInteractions.getMouseEvent('click'));
1168+
fixture.detectChanges();
1169+
1170+
expect(combo.open).toHaveBeenCalledTimes(1);
1171+
});
1172+
11421173
it('should empty any invalid item values', () => {
11431174
combo.valueKey = 'key';
11441175
combo.displayKey = 'value';

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,14 @@ export class IgxSimpleComboComponent extends IgxComboBaseDirective implements Co
272272
this.composing = true;
273273
}
274274

275+
/** @hidden @internal */
276+
public handleInputClick(): void {
277+
if (this.collapsed) {
278+
this.open();
279+
this.comboInput.focus();
280+
}
281+
}
282+
275283
/** @hidden @internal */
276284
public handleKeyDown(event: KeyboardEvent): void {
277285
if (event.key === this.platformUtil.KEYMAP.ENTER) {
@@ -373,7 +381,9 @@ export class IgxSimpleComboComponent extends IgxComboBaseDirective implements Co
373381
/** @hidden @internal */
374382
public handleOpened(): void {
375383
this.triggerCheck();
376-
this.dropdownContainer.nativeElement.focus();
384+
if (!this.comboInput.focused) {
385+
this.dropdownContainer.nativeElement.focus();
386+
}
377387
this.opened.emit({ owner: this });
378388
}
379389

0 commit comments

Comments
 (0)