Skip to content

Commit 70a0817

Browse files
authored
fix(module:datepicker): ng0956 recreation entire collection (#8658)
1 parent 548ad48 commit 70a0817

File tree

3 files changed

+35
-22
lines changed

3 files changed

+35
-22
lines changed

components/date-picker/lib/abstract-panel-header.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
</button>
2424

2525
<div class="{{ prefixCls }}-view">
26-
@for(selector of selectors; track selector) {
26+
@for (selector of selectors; track trackBySelector(selector)) {
2727
<button
2828
class="{{ selector.className }}"
2929
role="button"

components/date-picker/lib/abstract-panel-header.ts

+19-6
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,16 @@
33
* found in the LICENSE file at https://github.com/NG-ZORRO/ng-zorro-antd/blob/master/LICENSE
44
*/
55

6-
import { Directive, EventEmitter, Input, OnChanges, OnInit, Output, SimpleChanges, booleanAttribute } from '@angular/core';
6+
import {
7+
booleanAttribute,
8+
Directive,
9+
EventEmitter,
10+
Input,
11+
OnChanges,
12+
OnInit,
13+
Output,
14+
SimpleChanges
15+
} from '@angular/core';
716

817
import { CandyDate } from 'ng-zorro-antd/core/time';
918
import { NzCalendarI18nInterface } from 'ng-zorro-antd/i18n';
@@ -19,10 +28,10 @@ export abstract class AbstractPanelHeader implements OnInit, OnChanges {
1928

2029
@Input() value!: CandyDate;
2130
@Input() locale!: NzCalendarI18nInterface;
22-
@Input({ transform: booleanAttribute }) showSuperPreBtn: boolean = true;
23-
@Input({ transform: booleanAttribute }) showSuperNextBtn: boolean = true;
24-
@Input({ transform: booleanAttribute }) showPreBtn: boolean = true;
25-
@Input({ transform: booleanAttribute }) showNextBtn: boolean = true;
31+
@Input({transform: booleanAttribute}) showSuperPreBtn: boolean = true;
32+
@Input({transform: booleanAttribute}) showSuperNextBtn: boolean = true;
33+
@Input({transform: booleanAttribute}) showPreBtn: boolean = true;
34+
@Input({transform: booleanAttribute}) showNextBtn: boolean = true;
2635

2736
@Output() readonly panelModeChange = new EventEmitter<NzDateMode>();
2837
@Output() readonly valueChange = new EventEmitter<CandyDate>();
@@ -91,4 +100,8 @@ export abstract class AbstractPanelHeader implements OnInit, OnChanges {
91100
this.render();
92101
}
93102
}
94-
}
103+
104+
trackBySelector(selector: PanelSelector): string {
105+
return `${selector.title}-${selector.label}`;
106+
}
107+
}

components/date-picker/lib/abstract-table.html

+15-15
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
11
<table class="ant-picker-content" cellspacing="0" role="grid">
2-
@if(headRow && headRow.length > 0) {
2+
@if (headRow && headRow.length > 0) {
33
<thead>
44
<tr role="row">
5-
@if(showWeek) {
5+
@if (showWeek) {
66
<th role="columnheader"></th>
77
}
8-
@for(cell of headRow; track cell) {
9-
<th role="columnheader" title="{{ cell.title }}"> {{ cell.content }} </th>
8+
@for (cell of headRow; track $index) {
9+
<th role="columnheader" title="{{ cell.title }}"> {{ cell.content }}</th>
1010
}
1111
</tr>
1212
</thead>
1313
}
1414

1515
<tbody>
16-
@for(row of bodyRows; track row.trackByIndex) {
16+
@for (row of bodyRows; track row.trackByIndex) {
1717
<tr [ngClass]="row.classMap!" role="row">
18-
@if(row.weekNum) {
19-
<td role="gridcell" class="{{ prefixCls }}-cell-week"> {{ row.weekNum }} </td>
18+
@if (row.weekNum) {
19+
<td role="gridcell" class="{{ prefixCls }}-cell-week"> {{ row.weekNum }}</td>
2020
}
21-
@for(cell of row.dateCells; track cell.trackByIndex) {
21+
@for (cell of row.dateCells; track cell.trackByIndex) {
2222
<td
2323
title="{{ cell.title }}"
2424
role="gridcell"
@@ -27,12 +27,12 @@
2727
(mouseenter)="cell.onMouseEnter()"
2828
>
2929
@switch (prefixCls) {
30-
@case('ant-picker') {
31-
@if(cell.isTemplateRef) {
30+
@case ('ant-picker') {
31+
@if (cell.isTemplateRef) {
3232
<ng-container *ngTemplateOutlet="$any(cell.cellRender); context: { $implicit: cell.value }" />
33-
}@else if(cell.isNonEmptyString) {
33+
} @else if (cell.isNonEmptyString) {
3434
<span [innerHTML]="cell.cellRender"></span>
35-
}@else {
35+
} @else {
3636
<div
3737
class="{{ prefixCls }}-cell-inner"
3838
[attr.aria-selected]="cell.isSelected"
@@ -42,14 +42,14 @@
4242
</div>
4343
}
4444
}
45-
@case('ant-picker-calendar') {
45+
@case ('ant-picker-calendar') {
4646
<div
4747
class="{{ prefixCls }}-date ant-picker-cell-inner"
4848
[class.ant-picker-calendar-date-today]="cell.isToday"
4949
>
50-
@if(cell.fullCellRender) {
50+
@if (cell.fullCellRender) {
5151
<ng-container *ngTemplateOutlet="$any(cell.fullCellRender); context: { $implicit: cell.value }" />
52-
}@else() {
52+
} @else {
5353
<div class="{{ prefixCls }}-date-value">{{ cell.content }}</div>
5454
<div class="{{ prefixCls }}-date-content">
5555
<ng-container *ngTemplateOutlet="$any(cell.cellRender); context: { $implicit: cell.value }">

0 commit comments

Comments
 (0)