Skip to content

Commit

Permalink
fix(module:datepicker): ng0956 recreation entire collection (#8658)
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicoss54 committed Jul 31, 2024
1 parent 548ad48 commit 70a0817
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 22 deletions.
2 changes: 1 addition & 1 deletion components/date-picker/lib/abstract-panel-header.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
</button>

<div class="{{ prefixCls }}-view">
@for(selector of selectors; track selector) {
@for (selector of selectors; track trackBySelector(selector)) {
<button
class="{{ selector.className }}"
role="button"
Expand Down
25 changes: 19 additions & 6 deletions components/date-picker/lib/abstract-panel-header.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,16 @@
* found in the LICENSE file at https://github.com/NG-ZORRO/ng-zorro-antd/blob/master/LICENSE
*/

import { Directive, EventEmitter, Input, OnChanges, OnInit, Output, SimpleChanges, booleanAttribute } from '@angular/core';
import {
booleanAttribute,
Directive,
EventEmitter,
Input,
OnChanges,
OnInit,
Output,
SimpleChanges
} from '@angular/core';

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

@Input() value!: CandyDate;
@Input() locale!: NzCalendarI18nInterface;
@Input({ transform: booleanAttribute }) showSuperPreBtn: boolean = true;
@Input({ transform: booleanAttribute }) showSuperNextBtn: boolean = true;
@Input({ transform: booleanAttribute }) showPreBtn: boolean = true;
@Input({ transform: booleanAttribute }) showNextBtn: boolean = true;
@Input({transform: booleanAttribute}) showSuperPreBtn: boolean = true;
@Input({transform: booleanAttribute}) showSuperNextBtn: boolean = true;
@Input({transform: booleanAttribute}) showPreBtn: boolean = true;
@Input({transform: booleanAttribute}) showNextBtn: boolean = true;

@Output() readonly panelModeChange = new EventEmitter<NzDateMode>();
@Output() readonly valueChange = new EventEmitter<CandyDate>();
Expand Down Expand Up @@ -91,4 +100,8 @@ export abstract class AbstractPanelHeader implements OnInit, OnChanges {
this.render();
}
}
}

trackBySelector(selector: PanelSelector): string {
return `${selector.title}-${selector.label}`;
}
}
30 changes: 15 additions & 15 deletions components/date-picker/lib/abstract-table.html
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
<table class="ant-picker-content" cellspacing="0" role="grid">
@if(headRow && headRow.length > 0) {
@if (headRow && headRow.length > 0) {
<thead>
<tr role="row">
@if(showWeek) {
@if (showWeek) {
<th role="columnheader"></th>
}
@for(cell of headRow; track cell) {
<th role="columnheader" title="{{ cell.title }}"> {{ cell.content }} </th>
@for (cell of headRow; track $index) {
<th role="columnheader" title="{{ cell.title }}"> {{ cell.content }}</th>
}
</tr>
</thead>
}

<tbody>
@for(row of bodyRows; track row.trackByIndex) {
@for (row of bodyRows; track row.trackByIndex) {
<tr [ngClass]="row.classMap!" role="row">
@if(row.weekNum) {
<td role="gridcell" class="{{ prefixCls }}-cell-week"> {{ row.weekNum }} </td>
@if (row.weekNum) {
<td role="gridcell" class="{{ prefixCls }}-cell-week"> {{ row.weekNum }}</td>
}
@for(cell of row.dateCells; track cell.trackByIndex) {
@for (cell of row.dateCells; track cell.trackByIndex) {
<td
title="{{ cell.title }}"
role="gridcell"
Expand All @@ -27,12 +27,12 @@
(mouseenter)="cell.onMouseEnter()"
>
@switch (prefixCls) {
@case('ant-picker') {
@if(cell.isTemplateRef) {
@case ('ant-picker') {
@if (cell.isTemplateRef) {
<ng-container *ngTemplateOutlet="$any(cell.cellRender); context: { $implicit: cell.value }" />
}@else if(cell.isNonEmptyString) {
} @else if (cell.isNonEmptyString) {
<span [innerHTML]="cell.cellRender"></span>
}@else {
} @else {
<div
class="{{ prefixCls }}-cell-inner"
[attr.aria-selected]="cell.isSelected"
Expand All @@ -42,14 +42,14 @@
</div>
}
}
@case('ant-picker-calendar') {
@case ('ant-picker-calendar') {
<div
class="{{ prefixCls }}-date ant-picker-cell-inner"
[class.ant-picker-calendar-date-today]="cell.isToday"
>
@if(cell.fullCellRender) {
@if (cell.fullCellRender) {
<ng-container *ngTemplateOutlet="$any(cell.fullCellRender); context: { $implicit: cell.value }" />
}@else() {
} @else {
<div class="{{ prefixCls }}-date-value">{{ cell.content }}</div>
<div class="{{ prefixCls }}-date-content">
<ng-container *ngTemplateOutlet="$any(cell.cellRender); context: { $implicit: cell.value }">
Expand Down

0 comments on commit 70a0817

Please sign in to comment.