Skip to content

Commit 991200d

Browse files
committed
fix(suggest): persist drilldown selected value
1 parent e6dd24d commit 991200d

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

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

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ import {
7878
} from './utils';
7979

8080
export const DEFAULT_SUGGEST_DEBOUNCE_TIME = 300;
81+
export const DEFAULT_SUGGEST_DRILLDOWN_CHARACTER = ':';
8182

8283
/**
8384
* A form compatible `dropdown` packing `lazy-loading` and `virtual-scroll`.
@@ -111,7 +112,7 @@ export class UiSuggestComponent extends UiSuggestMatFormFieldDirective
111112
AfterViewInit {
112113

113114
get inDrillDownMode() {
114-
return !!this.drillDown && this.inputControl.value.includes(':');
115+
return !!this.drillDown && this.inputControl.value.includes(this.drillDownCharacter);
115116
}
116117

117118
/**
@@ -151,6 +152,12 @@ export class UiSuggestComponent extends UiSuggestMatFormFieldDirective
151152
this._drillDown = !!value;
152153
}
153154

155+
/**
156+
* Divider character for drilldown logic
157+
*/
158+
@Input()
159+
drillDownCharacter = DEFAULT_SUGGEST_DRILLDOWN_CHARACTER;
160+
154161
/**
155162
* Configure if the component is `readonly`.
156163
*
@@ -929,9 +936,18 @@ export class UiSuggestComponent extends UiSuggestMatFormFieldDirective
929936
* @param [closeAfterSelect=true] If the dropdown should close after the value is selected.
930937
* @param [refocus=true] If the search input should regain focus after selection.
931938
*/
939+
// eslint-disable-next-line complexity
932940
updateValue(inputValue: ISuggestValue | string, closeAfterSelect = true, refocus = true) {
933-
const value = toSuggestValue(inputValue, this._isOnCustomValueIndex);
941+
let value = toSuggestValue(inputValue, this._isOnCustomValueIndex);
934942
if (value.loading !== VirtualScrollItemStatus.loaded) { return; }
943+
944+
if (this.inDrillDownMode) {
945+
value = {
946+
...value,
947+
text: `${this.inputControl.value}${value.text}`,
948+
};
949+
}
950+
935951
const isExpandable = this.searchable && this.drillDown && !!value.expandable;
936952

937953
if (isExpandable) {

0 commit comments

Comments
 (0)