Skip to content

Commit 9e59b13

Browse files
authored
Merge pull request #216 from UiPath/fix/suggest_issues
fix: suggest issues
2 parents c4d2a1b + 510a7bb commit 9e59b13

File tree

6 files changed

+99
-28
lines changed

6 files changed

+99
-28
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
# v13.2.1 (2022-03-04)
2+
* **chore** karma bump
3+
* **suggest** add tests
4+
* **suggest** refocus post item selection
5+
* **suggest** on multiple always clear input
6+
* **suggest** push custom item only on single select
7+
18
# v13.2.0 (2022-02-23)
29
* **suggest** add input for removable chips
310

package-lock.json

Lines changed: 30 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "angular-components",
3-
"version": "13.2.0",
3+
"version": "13.2.1",
44
"author": {
55
"name": "UiPath Inc",
66
"url": "https://uipath.com"
@@ -140,7 +140,7 @@
140140
"jasmine-expect": "^4.0.3",
141141
"jasmine-spec-reporter": "~5.0.0",
142142
"json": "^9.0.6",
143-
"karma": "~6.3.2",
143+
"karma": "^6.3.17",
144144
"karma-chrome-launcher": "~3.1.0",
145145
"karma-coverage-istanbul-reporter": "~3.0.2",
146146
"karma-jasmine": "~3.3.0",

projects/angular/components/ui-suggest/src/ui-suggest.component.spec.ts

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1088,6 +1088,16 @@ const sharedSpecifications = (
10881088
});
10891089

10901090
describe('With custom', () => {
1091+
function addByClickCustomValue(str: string) {
1092+
searchFor(str, fixture);
1093+
fixture.detectChanges();
1094+
tick(5000);
1095+
1096+
fixture.debugElement.query(By.css('.custom-item')).nativeElement
1097+
.dispatchEvent(EventGenerator.click);
1098+
fixture.detectChanges();
1099+
}
1100+
10911101
function addCustomValue(str: string) {
10921102
searchFor(str, fixture);
10931103
fixture.detectChanges();
@@ -1158,6 +1168,35 @@ const sharedSpecifications = (
11581168
expect(`${chips}`).toEqual(`A,B,C`);
11591169
}));
11601170

1171+
it('should preserve input focus on click custom value', fakeAsync(() => {
1172+
const input = fixture.debugElement.query(By.css('.mat-chip-list input'));
1173+
addByClickCustomValue('A');
1174+
tick(1000);
1175+
expect(document.activeElement).toBe(input.nativeElement);
1176+
}));
1177+
1178+
it('should NOT add custom value on close if input is populated', fakeAsync(() => {
1179+
searchFor('test', fixture);
1180+
fixture.detectChanges();
1181+
tick(5000);
1182+
expect(uiSuggest.inputControl.value).toEqual('test');
1183+
1184+
uiSuggest.close();
1185+
fixture.detectChanges();
1186+
tick(1000);
1187+
1188+
expect(uiSuggest.value).toEqual([]);
1189+
}));
1190+
1191+
it('should clear input after selection', fakeAsync(() => {
1192+
addCustomValue('A');
1193+
tick(1000);
1194+
1195+
const input: HTMLInputElement = fixture.debugElement.query(By.css('input'))!.nativeElement;
1196+
expect(uiSuggest.inputControl.value).toEqual('');
1197+
expect(input.value).toEqual('');
1198+
}));
1199+
11611200
});
11621201

11631202
describe('generic', () => {

projects/angular/components/ui-suggest/src/ui-suggest.component.ts

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ import {
7979

8080
export const DEFAULT_SUGGEST_DEBOUNCE_TIME = 300;
8181
export const DEFAULT_SUGGEST_DRILLDOWN_CHARACTER = ':';
82+
export const MAT_CHIP_INPUT_SELECTOR = '.mat-chip-list input';
8283

8384
/**
8485
* A form compatible `dropdown` packing `lazy-loading` and `virtual-scroll`.
@@ -827,10 +828,12 @@ export class UiSuggestComponent extends UiSuggestMatFormFieldDirective
827828
close(refocus = true) {
828829
if (this.alwaysExpanded || !this.isOpen) { return; }
829830

830-
if (this._isOnCustomValueIndex && !this.loading$.value) {
831-
if (!this.multiple) {
832-
this._clearSelection();
833-
}
831+
if (
832+
this._isOnCustomValueIndex &&
833+
!this.loading$.value &&
834+
!this.multiple
835+
) {
836+
this._clearSelection();
834837
this._pushEntry(toSuggestValue(this.inputControl.value.trim(), true));
835838
}
836839

@@ -968,20 +971,20 @@ export class UiSuggestComponent extends UiSuggestMatFormFieldDirective
968971
if (!isItemSelected && value) {
969972
if (!this.multiple) {
970973
this._clearSelection();
974+
this._pushEntry(value);
971975
} else {
972-
if (value.isCustom) {
973-
this.inputControl.setValue('');
974-
}
976+
this.inputControl.setValue('');
977+
this._pushEntry(value);
978+
this._focusChipInput();
975979
}
976-
this._pushEntry(value);
977980
}
978981

979-
if (
980-
this.multiple &&
982+
const alreadySelectedNormalValue = this.multiple &&
981983
isItemSelected &&
982984
!!value &&
983-
!value.isCustom
984-
) {
985+
!value.isCustom;
986+
987+
if (alreadySelectedNormalValue) {
985988
this._removeEntry(value);
986989
}
987990

@@ -1279,4 +1282,9 @@ export class UiSuggestComponent extends UiSuggestMatFormFieldDirective
12791282
private _gotoBottomAsync(element: HTMLElement) {
12801283
setTimeout(() => element.scrollTop = element.scrollHeight - element.clientHeight, 0);
12811284
}
1285+
1286+
private _focusChipInput() {
1287+
// direct focus needed as chip component doesn't expose a focus to input mechanism
1288+
document.querySelector<HTMLInputElement>(MAT_CHIP_INPUT_SELECTOR)?.focus();
1289+
}
12821290
}

projects/angular/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@uipath/angular",
3-
"version": "13.2.0",
3+
"version": "13.2.1",
44
"license": "MIT",
55
"author": {
66
"name": "UiPath Inc",

0 commit comments

Comments
 (0)