Skip to content

Commit

Permalink
fix: avoid ngTemplateOutletContext to modify object reference
Browse files Browse the repository at this point in the history
  • Loading branch information
fengtianze committed Jan 8, 2021
1 parent 476b435 commit 55f28f8
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
9 changes: 2 additions & 7 deletions src/select/base-select.ts
Original file line number Diff line number Diff line change
Expand Up @@ -403,14 +403,9 @@ export abstract class BaseSelect<T>
if (this.focusedOption) {
this.focusedOption.blur();
}

this.focusedOption = focusedOption;
// TODO: 避免 aui-option 中的 labelContext 的引用被修改,为什么?
// http://jira.alauda.cn/browse/AIT-4714
if (focusedOption?.labelContext) {
this.focusedOption.labelContext = {
...(focusedOption.labelContext as Record<string, unknown>),
};
}

if (this.focusedOption) {
this.focusedOption.focus();
this.scrollToOption(this.focusedOption);
Expand Down
5 changes: 4 additions & 1 deletion src/select/select.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,10 @@ export class SelectComponent
option
? {
label: option.label || coerceString(trackFn(option.value)),
labelContext: option.labelContext,
// In ng 11, ngTemplateOutletContext will modify the object reference.
labelContext: {
...(option.labelContext as Record<string, unknown>),
},
}
: { label: coerceString(trackFn(value)) },
),
Expand Down

0 comments on commit 55f28f8

Please sign in to comment.