Skip to content

Commit 3771512

Browse files
feat(module:date-picker): add ElementRef type to nzSeparator (#7721)
add the possibility to assign an ElementRef to nzSeparator in nz-range-picker Co-authored-by: Daniel_Fornarini <44554840+Daniel-Fornarini@users.noreply.github.com>
1 parent 1820da5 commit 3771512

File tree

4 files changed

+22
-9
lines changed

4 files changed

+22
-9
lines changed

components/date-picker/date-picker.component.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -123,11 +123,13 @@ export type NzPlacement = 'bottomLeft' | 'bottomRight' | 'topLeft' | 'topRight';
123123
</div>
124124
<div #separatorElement class="{{ prefixCls }}-range-separator">
125125
<span class="{{ prefixCls }}-separator">
126-
<ng-container *ngIf="nzSeparator; else defaultSeparator">{{ nzSeparator }}</ng-container>
126+
<ng-container *nzStringTemplateOutlet="nzSeparator; let separator">
127+
<ng-container *ngIf="nzSeparator; else defaultSeparator">{{ nzSeparator }}</ng-container>
128+
<ng-template #defaultSeparator>
129+
<span nz-icon nzType="swap-right" nzTheme="outline"></span>
130+
</ng-template>
131+
</ng-container>
127132
</span>
128-
<ng-template #defaultSeparator>
129-
<span nz-icon nzType="swap-right" nzTheme="outline"></span>
130-
</ng-template>
131133
</div>
132134
<div class="{{ prefixCls }}-input">
133135
<ng-container *ngTemplateOutlet="tplRangeInput; context: { partType: 'right' }"></ng-container>
@@ -301,7 +303,7 @@ export class NzDatePickerComponent implements OnInit, OnChanges, OnDestroy, Afte
301303
@Input() @InputBoolean() nzShowNow: boolean = true;
302304
@Input() nzRanges?: PresetRanges;
303305
@Input() nzDefaultPickerValue: CompatibleDate | null = null;
304-
@Input() @WithConfig() nzSeparator?: string = undefined;
306+
@Input() @WithConfig() nzSeparator?: string | TemplateRef<NzSafeAny> = undefined;
305307
@Input() @WithConfig() nzSuffixIcon: string | TemplateRef<NzSafeAny> = 'calendar';
306308
@Input() @WithConfig() nzBackdrop = false;
307309
@Input() nzId: string | null = null;

components/date-picker/doc/index.en-US.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ The following APIs are shared by nz-date-picker, nz-range-picker.
8787
| -------- | ----------- | ---- | ------- |
8888
| `[(ngModel)]` | Date | `Date[]` | - |
8989
| `[nzRanges]` | preseted ranges for quick selection | `{ [ key: string ]: Date[] } \| { [ key: string ]: () => Date[] }` | - |
90-
| `[nzSeparator]` | separator | `string` | `'~'` |
90+
| `[nzSeparator]` | separator | `string \| TemplateRef` | `'~'` |
9191
| `(nzOnCalendarChange)` | The start time or the end time of the range change callback | `EventEmitter<Date[]>` | - |
9292

9393
### nz-range-picker[nzMode="date"]

components/date-picker/doc/index.zh-CN.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ registerLocaleData(zh);
8989
| --- | --- | --- | --- |
9090
| `[(ngModel)]` | 日期 | `Date[]` | - |
9191
| `[nzRanges]` | 预设时间范围快捷选择 | `{ [ key: string ]: Date[] } \| { [ key: string ]: () => Date[] }` | - |
92-
| `[nzSeparator]` | 分隔符 | `string` | `'~'` |
92+
| `[nzSeparator]` | 分隔符 | `string \| TemplateRef` | `'~'` |
9393
| `(nzOnCalendarChange)` | 待选日期发生变化的回调 | `EventEmitter<Date[]>` | - |
9494

9595
### nz-range-picker[nzMode="date"]

components/date-picker/range-picker.component.spec.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -312,14 +312,22 @@ describe('NzRangePickerComponent', () => {
312312
expect(queryFromRightPanel('.ant-picker-header-month-btn').textContent!.indexOf('2') > -1).toBeTruthy();
313313
}));
314314

315-
it('should support nzSeparator', fakeAsync(() => {
315+
it('should support string nzSeparator', fakeAsync(() => {
316316
fixtureInstance.nzSeparator = '→';
317317
fixture.detectChanges();
318318
expect(fixture.debugElement.query(By.css(`.ant-picker-range-separator`)).nativeElement.textContent.trim()).toBe(
319319
'→'
320320
);
321321
}));
322322

323+
it('should support ElementRef nzSeparator', fakeAsync(() => {
324+
fixtureInstance.useSuite = 6;
325+
fixture.detectChanges();
326+
expect(fixture.debugElement.query(By.css(`.ant-picker-range-separator`)).nativeElement.textContent.trim()).toBe(
327+
'TEST_SEPARATOR_REF'
328+
);
329+
}));
330+
323331
it('should support nzOnCalendarChange', fakeAsync(() => {
324332
const nzOnCalendarChange = spyOn(fixtureInstance, 'nzOnCalendarChange');
325333
fixture.detectChanges();
@@ -1216,11 +1224,14 @@ describe('NzRangePickerComponent', () => {
12161224
</ng-container>
12171225
12181226
<nz-range-picker *ngSwitchCase="5" nzOpen></nz-range-picker>
1227+
1228+
<nz-range-picker *ngSwitchCase="6" [nzSeparator]="separatorTemplate"></nz-range-picker>
1229+
<ng-template #separatorTemplate>TEST_SEPARATOR_REF</ng-template>
12191230
</ng-container>
12201231
`
12211232
})
12221233
class NzTestRangePickerComponent {
1223-
useSuite!: 1 | 2 | 3 | 4 | 5;
1234+
useSuite!: 1 | 2 | 3 | 4 | 5 | 6;
12241235
@ViewChild('tplDateRender', { static: true }) tplDateRender!: TemplateRef<Date>;
12251236
@ViewChild('tplExtraFooter', { static: true }) tplExtraFooter!: TemplateRef<void>;
12261237

0 commit comments

Comments
 (0)