Skip to content

Commit

Permalink
perf(module:select): ability to pass nzKey to nz-option (#8033)
Browse files Browse the repository at this point in the history
When object is used as key for select option re-rendering occurs, to solve this added new 'key' param | 'nzKey' Input
  • Loading branch information
oleksandr-codefresh committed Sep 12, 2023
1 parent 7f7c155 commit e94da4e
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 5 deletions.
3 changes: 2 additions & 1 deletion components/select/doc/index.en-US.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ import { NzSelectModule } from 'ng-zorro-antd/select';
| `[nzTokenSeparators]` | Separator used to tokenize on tag/multiple mode | `string[]` | `[]` |
| `[nzLoading]` | indicate loading state | `boolean` | false |
| `[nzMaxTagCount]` | Max tag count to show| `number` | - |
| `[nzOptions]` | use nzOptions or `nz-option` to pass options to the select | `Array<{ label: string \| number \| TemplateRef<any>; value: any; disabled?: boolean; hide?: boolean; groupLabel?: string \| TemplateRef<any>;}>` | - |
| `[nzOptions]` | use nzOptions or `nz-option` to pass options to the select | `Array<{ label: string \| number \| TemplateRef<any>; value: any; key?: string \| number; disabled?: boolean; hide?: boolean; groupLabel?: string \| TemplateRef<any>;}>` | - |
| `[nzMaxTagPlaceholder]` | Placeholder for not showing tags | `TemplateRef<{ $implicit: any[] }>` | - |
| `[nzOptionHeightPx]` | Each option height inside the dropdown | `number` | `32` |
| `[nzOptionOverflowSize]` | Max option size inside the dropdown, overflow when exceed the size | `number` | `8` |
Expand All @@ -78,6 +78,7 @@ import { NzSelectModule } from 'ng-zorro-antd/select';
| `[nzDisabled]` | Disable this option | `boolean` | `false` |
| `[nzLabel]` | The text show in nz-select and dropdown menu | `string \| number` | - |
| `[nzValue]` | The value passed to ngModel of nz-select | `any ` | - |
| `[nzKey]` | Should be passed when typeof nzValue - Object. Key will be used for performance optimizations | `string \| number ` | - |
| `[nzHide]` | Whether hide the option in the option list | `boolean` | `false` |
| `[nzCustomContent]` | Whether custom nz-option content in drodown menu, the ng-content in nz-option will replace nzLabel when it was set to true | `boolean` | `false` |

Expand Down
3 changes: 2 additions & 1 deletion components/select/doc/index.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ import { NzSelectModule } from 'ng-zorro-antd/select';
| `[nzLoading]` | 加载中状态 | `boolean` | `false` |
| `[nzMaxTagCount]` | 最多显示多少个 tag | `number` | - |
| `[nzMaxTagPlaceholder]` | 隐藏 tag 时显示的内容 | `TemplateRef<{ $implicit: any[] }>` | - |
| `[nzOptions]` | option 列表,可以取代 nz-option,用法参见例子 | `Array<{ label: string \| number \| TemplateRef<any>; value: any; disabled?: boolean; hide?: boolean; groupLabel?: string \| TemplateRef<any>;}>` | - |
| `[nzOptions]` | option 列表,可以取代 nz-option,用法参见例子 | `Array<{ label: string \| number \| TemplateRef<any>; value: any; key?: string \| number; disabled?: boolean; hide?: boolean; groupLabel?: string \| TemplateRef<any>;}>` | - |
| `[nzOptionHeightPx]` | 下拉菜单中每个 Option 的高度 | `number` | `32` |
| `[nzOptionOverflowSize]` | 下拉菜单中最多展示的 Option 个数,超出部分滚动 | `number` | `8` |
| `[nzSelectOnTab]` | 允许使用 TAB 键选择项目 | `boolean` | `false` |
Expand All @@ -79,6 +79,7 @@ import { NzSelectModule } from 'ng-zorro-antd/select';
| `[nzDisabled]` | 是否禁用 | `boolean` | `false` |
| `[nzLabel]` | 选中该 nz-option 后,nz-select 中显示的文字 | `string \| number` | - |
| `[nzValue]` | nz-select 中 ngModel 的值 | `any` | - |
| `[nzKey]` | nz-select 中 ngModel 的值 | `string \| number` | - |
| `[nzHide]` | 是否在选项列表中隐藏该选项 | `boolean` | `false` |
| `[nzCustomContent]` | 是否自定义在下拉菜单中的 Template 内容,当为 true 时,nz-option 包裹的内容将直接渲染在下拉菜单中 | `boolean` | `false` |

Expand Down
1 change: 1 addition & 0 deletions components/select/option.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export class NzOptionComponent implements OnChanges, OnInit {
@ViewChild(TemplateRef, { static: true }) template!: TemplateRef<NzSafeAny>;
@Input() nzLabel: string | number | null = null;
@Input() nzValue: NzSafeAny | null = null;
@Input() nzKey?: string | number;
@Input() @InputBoolean() nzDisabled = false;
@Input() @InputBoolean() nzHide = false;
@Input() @InputBoolean() nzCustomContent = false;
Expand Down
6 changes: 3 additions & 3 deletions components/select/select.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -630,7 +630,7 @@ export class NzSelectComponent implements ControlValueAccessor, OnInit, AfterCon
nzCustomContent: item.label instanceof TemplateRef,
groupLabel: item.groupLabel || null,
type: 'item',
key: item.value
key: item.key === undefined ? item.value : item.key
};
});
this.listOfTemplateItem$.next(listOfTransformedItem);
Expand Down Expand Up @@ -757,7 +757,7 @@ export class NzSelectComponent implements ControlValueAccessor, OnInit, AfterCon
)
.subscribe(() => {
const listOfOptionInterface = this.listOfNzOptionComponent.toArray().map(item => {
const { template, nzLabel, nzValue, nzDisabled, nzHide, nzCustomContent, groupLabel } = item;
const { template, nzLabel, nzValue, nzKey, nzDisabled, nzHide, nzCustomContent, groupLabel } = item;
return {
template,
nzLabel,
Expand All @@ -767,7 +767,7 @@ export class NzSelectComponent implements ControlValueAccessor, OnInit, AfterCon
nzCustomContent,
groupLabel,
type: 'item',
key: nzValue
key: nzKey === undefined ? nzValue : nzKey
};
});
this.listOfTemplateItem$.next(listOfOptionInterface);
Expand Down
1 change: 1 addition & 0 deletions components/select/select.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export interface NzSelectOptionInterface {
disabled?: boolean;
hide?: boolean;
groupLabel?: string | number | TemplateRef<NzSafeAny> | null;
key?: string | number;
}

export type NzSelectTopControlItemType = Partial<NzSelectItemInterface> & {
Expand Down

0 comments on commit e94da4e

Please sign in to comment.