Skip to content

Commit 13b1ed3

Browse files
authored
fix(suggest): add item selected output event
fix(suggest): add item selected output event
2 parents b620cf4 + 6067bc4 commit 13b1ed3

File tree

8 files changed

+50
-6
lines changed

8 files changed

+50
-6
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
# v14.8.0 (2023-05-29)
2+
* **suggest** changed in EventEmitter
3+
* **suggest** added item selected output
4+
* **deps** bump socket.io-parser from 4.2.1 to 4.2.3
5+
* **chore** workflow fixes publish to npmjs.org
6+
* **chore** use builtin GITHUB_TOKEN for gh publish
7+
* **deps** add workflow to publish package version
8+
19
# v14.7.14 (2023-05-23)
210
* **suggest** announce status of current item
311

package-lock.json

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

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "angular-components",
3-
"version": "14.7.14",
3+
"version": "14.8.0",
44
"author": {
55
"name": "UiPath Inc",
66
"url": "https://uipath.com"

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -621,6 +621,13 @@ export class UiSuggestComponent extends UiSuggestMatFormFieldDirective
621621
@Output()
622622
closed = new EventEmitter<void>();
623623

624+
/**
625+
* Emits when an item is selected.
626+
*
627+
*/
628+
@Output()
629+
itemSelected = new EventEmitter<ISuggestValue>();
630+
624631
/**
625632
* Emits when the overlay is displayed (dropdown open).
626633
*
@@ -1190,6 +1197,8 @@ export class UiSuggestComponent extends UiSuggestMatFormFieldDirective
11901197
let value = toSuggestValue(inputValue, this._isOnCustomValueIndex);
11911198
if (value.loading !== VirtualScrollItemStatus.loaded || value.disabled === true) { return; }
11921199

1200+
this.itemSelected.emit(value);
1201+
11931202
if (this.inDrillDownMode) {
11941203
value = {
11951204
...value,

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": "14.7.14",
3+
"version": "14.8.0",
44
"license": "MIT",
55
"author": {
66
"name": "UiPath Inc",

projects/playground/src/app/pages/suggest/suggest.module.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
} from '@angular/forms';
66
import { MatFormFieldModule } from '@angular/material/form-field';
77
import { UiSuggestModule } from '@uipath/angular/components/ui-suggest';
8+
import { MatRadioModule } from '@angular/material/radio';
89

910
import { SuggestPageComponent } from './suggest.page';
1011

@@ -18,6 +19,7 @@ import { SuggestPageComponent } from './suggest.page';
1819
MatFormFieldModule,
1920
FormsModule,
2021
ReactiveFormsModule,
22+
MatRadioModule,
2123
],
2224
})
2325
export class SuggestModule { }

projects/playground/src/app/pages/suggest/suggest.page.html

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,16 @@ <h3>With custom template</h3>
8686
</mat-form-field>
8787

8888

89+
<h1>Using custom template with field interaction output</h1>
90+
<mat-form-field>
91+
<ui-suggest [searchSourceFactory]="searchSourceFactory"
92+
(itemSelected)="itemClicked($event)">
93+
<ng-template let-item>
94+
<mat-radio-button [checked]="isItemAdded(item)">{{item.text}}</mat-radio-button>
95+
</ng-template>
96+
</ui-suggest>
97+
</mat-form-field>
98+
8999
<h1>Lazy Load</h1>
90100
<mat-form-field>
91101
<ui-suggest [searchSourceStrategy]="'lazy'"

projects/playground/src/app/pages/suggest/suggest.page.ts

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ import {
1313
ChangeDetectionStrategy,
1414
Component,
1515
} from '@angular/core';
16-
import { ISuggestValues } from '@uipath/angular/components/ui-suggest';
16+
import {
17+
ISuggestValue, ISuggestValues,
18+
} from '@uipath/angular/components/ui-suggest';
1719
import { FormControl } from '@angular/forms';
1820

1921
@Component({
@@ -23,10 +25,23 @@ import { FormControl } from '@angular/forms';
2325
changeDetection: ChangeDetectionStrategy.OnPush,
2426
})
2527
export class SuggestPageComponent {
26-
control = new FormControl();
28+
control = new FormControl<ISuggestValue[]>([]);
2729

2830
constructor() { }
2931

32+
itemClicked(item: ISuggestValue) {
33+
this.control.setValue([item]);
34+
}
35+
36+
isItemAdded(item: ISuggestValue) {
37+
const value = this.control.value;
38+
if (!value) {
39+
return false;
40+
}
41+
42+
return value.findIndex(itm => item.id === itm.id) !== -1;
43+
}
44+
3045
getResults(searchTerm: string): Observable<ISuggestValues<any>> {
3146
const options = range(0, 20).map(idx => ({
3247
id: idx,

0 commit comments

Comments
 (0)