Skip to content

Commit 04e214c

Browse files
feat(simple-combo): allow values to be selected on tab press - master (#14708)
1 parent a256c0f commit 04e214c

File tree

3 files changed

+62
-12
lines changed

3 files changed

+62
-12
lines changed

CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ All notable changes for each version of this project will be documented in this
44

55
## 18.2.0
66
### New Features
7+
- `IgxSimpleCombo`
8+
- Introduced ability for Simple Combo to automatically select and retain valid input on "Tab" press enhancing user experience by streamlining data entry and reducing the need for manual selection improving form navigation.
9+
710
#### Scrollbar: New CSS variables
811

912
We have introduced new CSS variables to allow for more customizable scrollbars. This enhancement utilizes the available WebKit pseudo-selectors such as `::-webkit-scrollbar-track`. However, please note that these pseudo-selectors are prefixed with `-webkit-` and are only supported in WebKit-based browsers (e.g., Chrome, Safari).

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

+44-10
Original file line numberDiff line numberDiff line change
@@ -1425,20 +1425,54 @@ describe('IgxSimpleCombo', () => {
14251425
expect(combo.close).toHaveBeenCalledTimes(1);
14261426
});
14271427

1428-
it('should clear the input on blur with a partial match', () => {
1429-
spyOn(combo as any, 'clearSelection').and.callThrough();
1428+
it('should select first match item on tab key pressed', () => {
1429+
input.triggerEventHandler('focus', {});
1430+
fixture.detectChanges();
1431+
1432+
const toggleButton = fixture.debugElement.query(By.css('.' + CSS_CLASS_TOGGLEBUTTON));
1433+
toggleButton.triggerEventHandler('click', UIInteractions.getMouseEvent('click'));
1434+
fixture.detectChanges();
1435+
1436+
UIInteractions.simulateTyping('connecticut', input);
1437+
fixture.detectChanges();
1438+
1439+
UIInteractions.triggerEventHandlerKeyDown('Tab', input);
1440+
fixture.detectChanges();
1441+
1442+
expect(combo.displayValue).toEqual('Connecticut');
1443+
expect(combo.comboInput.value).toEqual('Connecticut');
1444+
});
1445+
1446+
it('should not select any item if input does not match data on tab key pressed', () => {
1447+
input.triggerEventHandler('focus', {});
1448+
fixture.detectChanges();
1449+
1450+
const toggleButton = fixture.debugElement.query(By.css('.' + CSS_CLASS_TOGGLEBUTTON));
1451+
toggleButton.triggerEventHandler('click', UIInteractions.getMouseEvent('click'));
1452+
fixture.detectChanges();
1453+
1454+
UIInteractions.simulateTyping('nonexistent', input);
1455+
fixture.detectChanges();
1456+
1457+
UIInteractions.triggerEventHandlerKeyDown('Tab', input);
1458+
fixture.detectChanges();
1459+
1460+
expect(combo.displayValue).toEqual('');
1461+
expect(combo.comboInput.value).toEqual('');
1462+
});
1463+
1464+
it('should not clear the input on blur with a partial match but it should select the match item', () => {
14301465
spyOn(combo.dropdown.closing, 'emit').and.callThrough();
14311466

14321467
input.triggerEventHandler('focus', {});
14331468
fixture.detectChanges();
1434-
UIInteractions.simulateTyping('new', input);
1469+
UIInteractions.simulateTyping('mic', input);
14351470

14361471
UIInteractions.triggerEventHandlerKeyDown('Tab', input);
14371472
fixture.detectChanges();
14381473

1439-
expect((combo as any).clearSelection).toHaveBeenCalledOnceWith(true);
1474+
expect(combo.displayValue).toEqual('Michigan');
14401475
expect(combo.dropdown.closing.emit).toHaveBeenCalledTimes(1);
1441-
expect(combo.displayValue).toEqual('');
14421476
});
14431477

14441478
it('should not clear the selection and input on blur with a match', () => {
@@ -1465,7 +1499,7 @@ describe('IgxSimpleCombo', () => {
14651499
expect(combo.selection).toBeDefined()
14661500
});
14671501

1468-
it('should clear input on blur when dropdown is collapsed with no match', () => {
1502+
it('should not clear input on blur when dropdown is collapsed with match', () => {
14691503
input.triggerEventHandler('focus', {});
14701504
fixture.detectChanges();
14711505

@@ -1478,8 +1512,8 @@ describe('IgxSimpleCombo', () => {
14781512
UIInteractions.triggerEventHandlerKeyDown('Tab', input);
14791513
fixture.detectChanges();
14801514

1481-
expect(combo.displayValue).toEqual('');
1482-
expect(combo.selection).not.toBeDefined()
1515+
expect(combo.displayValue).toEqual('New Jersey');
1516+
expect(combo.selection).toBeDefined()
14831517
});
14841518

14851519
it('should open the combo when input is focused', () => {
@@ -2765,7 +2799,7 @@ describe('IgxSimpleCombo', () => {
27652799
const selectedItem = combo.data[combo.data.length - 1];
27662800
expect(combo.displayValue).toEqual(`${selectedItem[combo.displayKey]}`);
27672801
}));
2768-
it('should clear input on blur when bound to remote data and no item is selected', () => {
2802+
it('should not clear input on blur when bound to remote data and item is selected', () => {
27692803
input.triggerEventHandler('focus', {});
27702804
fixture.detectChanges();
27712805

@@ -2775,7 +2809,7 @@ describe('IgxSimpleCombo', () => {
27752809
UIInteractions.triggerEventHandlerKeyDown('Tab', input);
27762810
fixture.detectChanges();
27772811

2778-
expect(combo.comboInput.value).toEqual('');
2812+
expect(combo.comboInput.value).toEqual('Product 0');
27792813
});
27802814

27812815
it('should display correct value after the value has been changed from the form and then by the user', fakeAsync(() => {

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

+15-2
Original file line numberDiff line numberDiff line change
@@ -361,8 +361,21 @@ export class IgxSimpleComboComponent extends IgxComboBaseDirective implements Co
361361
this.clearSelection(true);
362362
}
363363
if (!this.collapsed && event.key === this.platformUtil.KEYMAP.TAB) {
364-
this.clearOnBlur();
365-
this.close();
364+
const filtered = this.filteredData.find(this.findAllMatches);
365+
if (filtered === null || filtered === undefined) {
366+
this.clearOnBlur();
367+
this.close();
368+
return;
369+
}
370+
const focusedItem = this.dropdown.focusedItem;
371+
if (focusedItem && !focusedItem.isHeader) {
372+
this.select(focusedItem.itemID);
373+
this.close();
374+
this.textSelection.trigger();
375+
} else {
376+
this.clearOnBlur();
377+
this.close();
378+
}
366379
}
367380
this.composing = false;
368381
super.handleKeyDown(event);

0 commit comments

Comments
 (0)