Skip to content

Commit 3adc183

Browse files
authored
fix(combo): trim selected text #12782 (#12791)
1 parent 2477686 commit 3adc183

File tree

4 files changed

+58
-4
lines changed

4 files changed

+58
-4
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1300,7 +1300,7 @@ export abstract class IgxComboBaseDirective extends DisplayDensityBase implement
13001300
protected findMatch = (element: any): boolean => {
13011301
const value = this.displayKey ? element[this.displayKey] : element;
13021302
const searchValue = this.searchValue || this.comboInput?.value;
1303-
return value?.toString().toLowerCase() === searchValue.trim().toLowerCase();
1303+
return value?.toString().trim().toLowerCase() === searchValue.trim().toLowerCase();
13041304
};
13051305

13061306
protected manageRequiredAsterisk(): void {

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

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2101,6 +2101,38 @@ describe('igxCombo', () => {
21012101
expect(combo.selection).toEqual([]);
21022102
expect(combo.value).toBe('');
21032103
});
2104+
it('should select values that have spaces as prefixes/suffixes', fakeAsync(() => {
2105+
combo.displayKey = combo.valueKey = 'value';
2106+
combo.data = [
2107+
{ value: "Mississippi " }
2108+
];
2109+
const dropdown = combo.dropdown;
2110+
2111+
dropdown.toggle();
2112+
tick();
2113+
fixture.detectChanges();
2114+
const dropdownContent = fixture.debugElement.query(By.css(`.${CSS_CLASS_CONTENT}`));
2115+
2116+
UIInteractions.simulateTyping('Mississippi ', input);
2117+
// combo.searchValue = 'My New Custom Item';
2118+
// combo.handleInputChange();
2119+
fixture.detectChanges();
2120+
2121+
combo.handleKeyUp(UIInteractions.getKeyboardEvent('keyup', 'ArrowDown'));
2122+
fixture.detectChanges();
2123+
tick();
2124+
fixture.detectChanges();
2125+
UIInteractions.triggerEventHandlerKeyDown('Space', dropdownContent);
2126+
tick();
2127+
fixture.detectChanges();
2128+
combo.toggle();
2129+
tick();
2130+
fixture.detectChanges();
2131+
combo.onBlur();
2132+
tick();
2133+
fixture.detectChanges();
2134+
expect(combo.value).toBe('Mississippi ');
2135+
}));
21042136
it('should prevent selection when selectionChanging is cancelled', () => {
21052137
spyOn(combo.selectionChanging, 'emit').and.callFake((event: IComboSelectionChangingEventArgs) => event.cancel = true);
21062138
combo.toggle();

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

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1454,6 +1454,28 @@ describe('IgxSimpleCombo', () => {
14541454
fixture.detectChanges();
14551455
expect(combo.collapsed).toEqual(true);
14561456
}));
1457+
1458+
it('should select values that have spaces as prefixes/suffixes', fakeAsync(() => {
1459+
fixture.detectChanges();
1460+
1461+
dropdown.toggle();
1462+
fixture.detectChanges();
1463+
1464+
UIInteractions.simulateTyping('Ohio ', input);
1465+
fixture.detectChanges();
1466+
1467+
UIInteractions.triggerKeyDownEvtUponElem('Enter', input.nativeElement);
1468+
fixture.detectChanges();
1469+
1470+
combo.toggle();
1471+
tick();
1472+
fixture.detectChanges();
1473+
1474+
combo.onBlur();
1475+
tick();
1476+
fixture.detectChanges();
1477+
expect(combo.value).toBe('Ohio ');
1478+
}));
14571479
});
14581480

14591481
describe('Display density', () => {
@@ -2020,7 +2042,7 @@ class IgxSimpleComboSampleComponent {
20202042
'New England 01': ['Connecticut', 'Maine', 'Massachusetts'],
20212043
'New England 02': ['New Hampshire', 'Rhode Island', 'Vermont'],
20222044
'Mid-Atlantic': ['New Jersey', 'New York', 'Pennsylvania'],
2023-
'East North Central 02': ['Michigan', 'Ohio', 'Wisconsin'],
2045+
'East North Central 02': ['Michigan', 'Ohio ', 'Wisconsin'],
20242046
'East North Central 01': ['Illinois', 'Indiana'],
20252047
'West North Central 01': ['Missouri', 'Nebraska', 'North Dakota', 'South Dakota'],
20262048
'West North Central 02': ['Iowa', 'Kansas', 'Minnesota'],
@@ -2269,7 +2291,7 @@ export class IgxSimpleComboBindingDataAfterInitComponent implements AfterViewIni
22692291
@Component({
22702292
template: `
22712293
<div style="display: flex; flex-direction: column; height: 100%; justify-content: flex-end;">
2272-
<igx-simple-combo #combo [data]="items" [displayKey]="'field'" [valueKey]="'field'" [width]="'100%'"
2294+
<igx-simple-combo #combo [data]="items" [displayKey]="'field'" [valueKey]="'field'" [width]="'100%'"
22732295
style="margin-bottom: 60px;">
22742296
</igx-simple-combo>
22752297
</div>`

src/app/combo/combo.sample.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ export class ComboSampleComponent implements OnInit, AfterViewInit {
333333
if ('added' in evt) {
334334
this.hasSelection = !!evt?.newSelection.length;
335335
return;
336-
}
336+
}
337337

338338
if (!evt.newSelection) {
339339
this.simpleComboOpenOnClear.open();

0 commit comments

Comments
 (0)