Skip to content

Commit

Permalink
feat(legi-shared): add labelType as an option to prevent translate fo…
Browse files Browse the repository at this point in the history
…r new values

(cherry picked from commit 86cbab8)
(cherry picked from commit fa4852c)
  • Loading branch information
srikanth authored and WilliamChelman committed Dec 27, 2024
1 parent 1e34623 commit f87f959
Showing 1 changed file with 7 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ export class AutocompleteSingleComponent<T> extends ControlComponent<T> implemen
canBeDiscarded = false;
@Input()
hint?: string;
@Input()
labelHandling: 'translate' | 'raw' = 'translate';
@Output()
optionSelection: EventEmitter<string | undefined> = new EventEmitter();

Expand Down Expand Up @@ -171,9 +173,11 @@ export class AutocompleteSingleComponent<T> extends ControlComponent<T> implemen
*/
displayFn: (value?: T) => Nil<string> = value => {
if (value == null) return undefined;
const allOptions = [...this.storedValueOptions, ...this.options];
const option = allOptions.find(o => o.value === value);
if (option) return this.i18n.translate(option.label, undefined, this.lang);
if (this.labelHandling === 'translate') {
const allOptions = [...this.storedValueOptions, ...this.options];
const option = allOptions.find(o => o.value === value);
if (option) return this.i18n.translate(option.label, undefined, this.lang);
}
// eslint-disable-next-line @typescript-eslint/no-floating-promises
this.storeValueOption(value);
return value as unknown as string;
Expand Down

0 comments on commit f87f959

Please sign in to comment.