Skip to content

Commit

Permalink
fix(module:time-picker): placeholder not update with i18n changes (#6069
Browse files Browse the repository at this point in the history
)

Co-authored-by: Sven Depickere <sven.depickere@sofico.be>
  • Loading branch information
Depickere Sven and Sven Depickere committed Dec 15, 2020
1 parent 8029ef4 commit f34840b
Show file tree
Hide file tree
Showing 22 changed files with 77 additions and 41 deletions.
2 changes: 1 addition & 1 deletion components/back-top/back-top.component.ts
Expand Up @@ -39,7 +39,7 @@ const NZ_CONFIG_MODULE_NAME: NzConfigKey = 'backTop';
exportAs: 'nzBackTop',
animations: [fadeMotion],
template: `
<div class="ant-back-top" [class.ant-back-top-rtl]="dir === 'rtl' " (click)="clickBackTop()" @fadeMotion *ngIf="visible">
<div class="ant-back-top" [class.ant-back-top-rtl]="dir === 'rtl'" (click)="clickBackTop()" @fadeMotion *ngIf="visible">
<ng-template #defaultContent>
<div class="ant-back-top-content">
<div class="ant-back-top-icon">
Expand Down
3 changes: 2 additions & 1 deletion components/card/card.component.ts
Expand Up @@ -105,7 +105,8 @@ export class NzCardComponent implements OnDestroy, OnInit {
public nzConfigService: NzConfigService,
private cdr: ChangeDetectorRef,
private elementRef: ElementRef,
@Optional() private directionality: Directionality) {
@Optional() private directionality: Directionality
) {
// TODO: move to host after View Engine deprecation
this.elementRef.nativeElement.classList.add('ant-card');

Expand Down
4 changes: 2 additions & 2 deletions components/checkbox/checkbox-group.component.ts
Expand Up @@ -50,8 +50,8 @@ export interface NzCheckBoxOptionInterface {
export class NzCheckboxGroupComponent implements ControlValueAccessor, OnInit, OnDestroy {
static ngAcceptInputType_nzDisabled: BooleanInput;

onChange: OnChangeType = () => { };
onTouched: OnTouchedType = () => { };
onChange: OnChangeType = () => {};
onTouched: OnTouchedType = () => {};
options: NzCheckBoxOptionInterface[] = [];
@Input() @InputBoolean() nzDisabled = false;

Expand Down
4 changes: 2 additions & 2 deletions components/checkbox/checkbox.component.ts
Expand Up @@ -78,8 +78,8 @@ export class NzCheckboxComponent implements OnInit, ControlValueAccessor, OnDest
dir: Direction = 'ltr';
private destroy$ = new Subject<void>();

onChange: OnChangeType = () => { };
onTouched: OnTouchedType = () => { };
onChange: OnChangeType = () => {};
onTouched: OnTouchedType = () => {};
@ViewChild('inputElement', { static: true }) private inputElement!: ElementRef;
@Output() readonly nzCheckedChange = new EventEmitter<boolean>();
@Input() nzValue: NzSafeAny | null = null;
Expand Down
3 changes: 2 additions & 1 deletion components/collapse/collapse.component.ts
Expand Up @@ -61,7 +61,8 @@ export class NzCollapseComponent implements OnDestroy, OnInit {
public nzConfigService: NzConfigService,
private cdr: ChangeDetectorRef,
private elementRef: ElementRef,
@Optional() private directionality: Directionality) {
@Optional() private directionality: Directionality
) {
// TODO: move to host after View Engine deprecation
this.elementRef.nativeElement.classList.add('ant-collapse');

Expand Down
4 changes: 2 additions & 2 deletions components/drawer/drawer.spec.ts
Expand Up @@ -694,7 +694,7 @@ class NzTestDrawerWithServiceComponent {
templateCloseSpy = jasmine.createSpy('template afterClose spy');
templateDrawerRef?: NzDrawerRef;

constructor(private drawerService: NzDrawerService) { }
constructor(private drawerService: NzDrawerService) {}

openTemplate(): void {
this.templateDrawerRef = this.drawerService.create({
Expand All @@ -718,7 +718,7 @@ class NzTestDrawerWithServiceComponent {
export class NzDrawerCustomComponent {
@Input() value: any; // tslint:disable-line:no-any

constructor(private drawerRef: NzDrawerRef) { }
constructor(private drawerRef: NzDrawerRef) {}

close(): void {
this.drawerRef.close(this.value);
Expand Down
4 changes: 2 additions & 2 deletions components/input-number/input-number.component.ts
Expand Up @@ -106,8 +106,8 @@ export class NzInputNumberComponent implements ControlValueAccessor, AfterViewIn
disabledUp = false;
disabledDown = false;
dir: Direction = 'ltr';
onChange: OnChangeType = () => { };
onTouched: OnTouchedType = () => { };
onChange: OnChangeType = () => {};
onTouched: OnTouchedType = () => {};
@Output() readonly nzBlur = new EventEmitter();
@Output() readonly nzFocus = new EventEmitter();
@ViewChild('inputElement', { static: true }) inputElement!: ElementRef<HTMLInputElement>;
Expand Down
12 changes: 11 additions & 1 deletion components/layout/layout.component.ts
Expand Up @@ -4,7 +4,17 @@
*/

import { Direction, Directionality } from '@angular/cdk/bidi';
import { ChangeDetectionStrategy, Component, ContentChildren, ElementRef, OnDestroy, OnInit, Optional, QueryList, ViewEncapsulation } from '@angular/core';
import {
ChangeDetectionStrategy,
Component,
ContentChildren,
ElementRef,
OnDestroy,
OnInit,
Optional,
QueryList,
ViewEncapsulation
} from '@angular/core';
import { Subject } from 'rxjs';
import { takeUntil } from 'rxjs/operators';
import { NzSiderComponent } from './sider.component';
Expand Down
2 changes: 1 addition & 1 deletion components/message/message-container.component.ts
Expand Up @@ -31,7 +31,7 @@ const NZ_MESSAGE_DEFAULT_CONFIG: Required<MessageConfig> = {
exportAs: 'nzMessageContainer',
preserveWhitespaces: false,
template: `
<div class="ant-message" [class.ant-message-rtl]=" dir === 'rtl' " [style.top]="top">
<div class="ant-message" [class.ant-message-rtl]="dir === 'rtl'" [style.top]="top">
<nz-message *ngFor="let instance of instances" [instance]="instance" (destroyed)="remove($event.id, $event.userAction)"></nz-message>
</div>
`
Expand Down
2 changes: 1 addition & 1 deletion components/page-header/page-header.component.ts
Expand Up @@ -43,7 +43,7 @@ const NZ_CONFIG_MODULE_NAME: NzConfigKey = 'pageHeader';
<div *ngIf="nzBackIcon !== null" (click)="onBack()" class="ant-page-header-back">
<div role="button" tabindex="0" class="ant-page-header-back-button">
<ng-container *nzStringTemplateOutlet="nzBackIcon; let backIcon">
<i nz-icon [nzType]="backIcon || getBackIcon()" nzTheme="outline"></i>
<i nz-icon [nzType]="backIcon || getBackIcon()" nzTheme="outline"></i>
</ng-container>
</div>
</div>
Expand Down
9 changes: 3 additions & 6 deletions components/result/result.component.ts
Expand Up @@ -97,10 +97,7 @@ export class NzResultComponent implements OnChanges, OnDestroy, OnInit {

private destroy$ = new Subject<void>();

constructor(
private elementRef: ElementRef,
private cdr: ChangeDetectorRef,
@Optional() private directionality: Directionality) {
constructor(private elementRef: ElementRef, private cdr: ChangeDetectorRef, @Optional() private directionality: Directionality) {
// TODO: move to host after View Engine deprecation
this.elementRef.nativeElement.classList.add('ant-result');
}
Expand Down Expand Up @@ -132,7 +129,7 @@ export class NzResultComponent implements OnChanges, OnDestroy, OnInit {
? IconMap[icon as NzResultIconType] || icon
: icon
: this.isException
? undefined
: IconMap[this.nzStatus as NzResultIconType];
? undefined
: IconMap[this.nzStatus as NzResultIconType];
}
}
4 changes: 1 addition & 3 deletions components/result/result.spec.ts
Expand Up @@ -17,9 +17,7 @@ import { NzResultModule } from './result.module';
<i nz-icon nz-result-icon nzType="up" nzTheme="outline"></i>
<div nz-result-title>Content Title</div>
<div nz-result-subtitle>Content SubTitle</div>
<div nz-result-content>
Content
</div>
<div nz-result-content>Content</div>
<div nz-result-extra>Content Extra</div>
</nz-result>
`
Expand Down
4 changes: 2 additions & 2 deletions components/select/select.component.ts
Expand Up @@ -234,8 +234,8 @@ export class NzSelectComponent implements ControlValueAccessor, OnInit, AfterVie
private value: NzSafeAny | NzSafeAny[];
private destroy$ = new Subject();
private _nzShowArrow: boolean | undefined;
onChange: OnChangeType = () => { };
onTouched: OnTouchedType = () => { };
onChange: OnChangeType = () => {};
onTouched: OnTouchedType = () => {};
dropDownPosition: 'top' | 'center' | 'bottom' = 'bottom';
triggerWidth: number | null = null;
listOfContainerItem: NzSelectItemInterface[] = [];
Expand Down
2 changes: 1 addition & 1 deletion components/time-picker/time-picker-panel.component.ts
Expand Up @@ -162,7 +162,7 @@ export class NzTimePickerPanelComponent implements ControlValueAccessor, OnInit,
@Input() nzAddOn?: TemplateRef<void>;
@Input() nzHideDisabledOptions = false;
@Input() nzClearText?: string;
@Input() nzPlaceHolder?: string;
@Input() nzPlaceHolder?: string | null;
@Input() @InputBoolean() nzUse12Hours = false;
@Input() nzDefaultOpenValue?: Date;

Expand Down
23 changes: 22 additions & 1 deletion components/time-picker/time-picker.component.spec.ts
Expand Up @@ -6,7 +6,7 @@ import { By } from '@angular/platform-browser';
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
import { dispatchMouseEvent } from 'ng-zorro-antd/core/testing';
import { getPickerInput } from 'ng-zorro-antd/date-picker/testing/util';
import { NzI18nModule } from '../i18n/nz-i18n.module';
import { en_GB, NzI18nModule, NzI18nService } from '../i18n';
import { NzTimePickerComponent } from './time-picker.component';
import { NzTimePickerModule } from './time-picker.module';

Expand Down Expand Up @@ -151,6 +151,27 @@ describe('time-picker', () => {
fixture.detectChanges();
expect(fixture.debugElement.query(By.css(`.anticon-calendar`))).toBeDefined();
}));
describe('setup I18n service', () => {
let srv: NzI18nService;

beforeEach(inject([NzI18nService], (s: NzI18nService) => {
srv = s;
}));

it('should detect the language changes', fakeAsync(() => {
let placeHolderValue: string | undefined;
placeHolderValue = timeElement.nativeElement.querySelector('input').placeholder;

expect(placeHolderValue).toBe('请选择时间');

srv.setLocale(en_GB);
tick(400);
fixture.detectChanges();

placeHolderValue = timeElement.nativeElement.querySelector('input').placeholder;
expect(placeHolderValue).toBe('Select time');
}));
});
});

function queryFromOverlay(selector: string): HTMLElement {
Expand Down
14 changes: 9 additions & 5 deletions components/time-picker/time-picker.component.ts
Expand Up @@ -33,9 +33,9 @@ import { NzConfigKey, NzConfigService, WithConfig } from 'ng-zorro-antd/core/con
import { warn } from 'ng-zorro-antd/core/logger';
import { BooleanInput, NzSafeAny } from 'ng-zorro-antd/core/types';
import { InputBoolean, isNil } from 'ng-zorro-antd/core/util';
import { DateHelperService } from 'ng-zorro-antd/i18n';
import { Subject } from 'rxjs';
import { takeUntil } from 'rxjs/operators';
import { DateHelperService, NzI18nInterface, NzI18nService } from 'ng-zorro-antd/i18n';
import { Observable, of, Subject } from 'rxjs';
import { map, takeUntil } from 'rxjs/operators';

const NZ_CONFIG_MODULE_NAME: NzConfigKey = 'timePicker';

Expand All @@ -50,7 +50,7 @@ const NZ_CONFIG_MODULE_NAME: NzConfigKey = 'timePicker';
#inputElement
type="text"
[size]="inputSize"
[placeholder]="nzPlaceHolder || ('TimePicker.placeholder' | nzI18n)"
[placeholder]="nzPlaceHolder || (i18nPlaceHolder$ | async)"
[(ngModel)]="inputValue"
[disabled]="nzDisabled"
(focus)="onFocus(true)"
Expand Down Expand Up @@ -92,7 +92,7 @@ const NZ_CONFIG_MODULE_NAME: NzConfigKey = 'timePicker';
[nzDisabledHours]="nzDisabledHours"
[nzDisabledMinutes]="nzDisabledMinutes"
[nzDisabledSeconds]="nzDisabledSeconds"
[nzPlaceHolder]="nzPlaceHolder || ('TimePicker.placeholder' | nzI18n)"
[nzPlaceHolder]="nzPlaceHolder || (i18nPlaceHolder$ | async)"
[nzHideDisabledOptions]="nzHideDisabledOptions"
[nzUse12Hours]="nzUse12Hours"
[nzDefaultOpenValue]="nzDefaultOpenValue"
Expand Down Expand Up @@ -138,6 +138,7 @@ export class NzTimePickerComponent implements ControlValueAccessor, OnInit, Afte
preValue: Date | null = null;
origin!: CdkOverlayOrigin;
inputSize?: number;
i18nPlaceHolder$: Observable<string | undefined> = of(undefined);
overlayPositions: ConnectionPositionPair[] = [
{
originX: 'start',
Expand Down Expand Up @@ -278,6 +279,7 @@ export class NzTimePickerComponent implements ControlValueAccessor, OnInit, Afte

constructor(
public nzConfigService: NzConfigService,
protected i18n: NzI18nService,
private element: ElementRef,
private renderer: Renderer2,
private cdr: ChangeDetectorRef,
Expand All @@ -294,6 +296,8 @@ export class NzTimePickerComponent implements ControlValueAccessor, OnInit, Afte
this.inputSize = Math.max(8, this.nzFormat.length) + 2;
this.origin = new CdkOverlayOrigin(this.element);

this.i18nPlaceHolder$ = this.i18n.localeChange.pipe(map((nzLocale: NzI18nInterface) => nzLocale.TimePicker.placeholder));

this.dir = this.directionality.value;
this.directionality.change?.pipe(takeUntil(this.destroy$)).subscribe((direction: Direction) => {
this.dir = direction;
Expand Down
4 changes: 2 additions & 2 deletions components/tooltip/base.ts
Expand Up @@ -118,7 +118,7 @@ export abstract class NzTooltipBaseDirective implements OnChanges, OnDestroy, Af
protected resolver: ComponentFactoryResolver,
protected renderer: Renderer2,
protected noAnimation?: NzNoAnimationDirective
) { }
) {}

ngOnChanges(changes: SimpleChanges): void {
const { specificTrigger } = changes;
Expand Down Expand Up @@ -365,7 +365,7 @@ export abstract class NzTooltipBaseComponent implements OnDestroy, OnInit {
public cdr: ChangeDetectorRef,
@Optional() private directionality: Directionality,
public noAnimation?: NzNoAnimationDirective
) { }
) {}
ngOnInit(): void {
this.directionality.change?.pipe(takeUntil(this.destroy$)).subscribe((direction: Direction) => {
this.dir = direction;
Expand Down
7 changes: 5 additions & 2 deletions components/tooltip/demo/template.ts
Expand Up @@ -4,7 +4,10 @@ import { Component } from '@angular/core';
selector: 'nz-demo-tooltip-template',
template: `
<a nz-tooltip [nzTooltipTitle]="titleTemplate">This Tooltip has an Icon</a>
<ng-template #titleTemplate> <i nz-icon nzType="file"></i> <span>Tooltip With Icon</span> </ng-template>
<ng-template #titleTemplate>
<i nz-icon nzType="file"></i>
<span>Tooltip With Icon</span>
</ng-template>
`,
styles: [
`
Expand All @@ -15,4 +18,4 @@ import { Component } from '@angular/core';
`
]
})
export class NzDemoTooltipTemplateComponent { }
export class NzDemoTooltipTemplateComponent {}
3 changes: 2 additions & 1 deletion components/transfer/transfer.component.ts
Expand Up @@ -253,7 +253,8 @@ export class NzTransferComponent implements OnInit, OnChanges, OnDestroy {
private cdr: ChangeDetectorRef,
private i18n: NzI18nService,
private elementRef: ElementRef,
@Optional() private directionality: Directionality) {
@Optional() private directionality: Directionality
) {
// TODO: move to host after View Engine deprecation
this.elementRef.nativeElement.classList.add('ant-transfer');
}
Expand Down
4 changes: 2 additions & 2 deletions components/tree-select/tree-select.component.ts
Expand Up @@ -299,8 +299,8 @@ export class NzTreeSelectComponent extends NzTreeBase implements ControlValueAcc

private destroy$ = new Subject<void>();

onChange: OnChangeType = _value => { };
onTouched: OnTouchedType = () => { };
onChange: OnChangeType = _value => {};
onTouched: OnTouchedType = () => {};

get placeHolderDisplay(): string {
return this.inputValue || this.isComposing || this.selectedNodes.length ? 'none' : 'block';
Expand Down
2 changes: 1 addition & 1 deletion components/upload/upload-list.component.ts
Expand Up @@ -157,7 +157,7 @@ export class NzUploadListComponent implements OnChanges {

try {
ctx!.drawImage(img, offsetX, offsetY, drawWidth, drawHeight);
} catch { }
} catch {}
const dataURL = canvas.toDataURL();
this.doc.body.removeChild(canvas);

Expand Down
2 changes: 1 addition & 1 deletion components/upload/upload.component.ts
Expand Up @@ -172,7 +172,7 @@ export class NzUploadComponent implements OnInit, OnChanges, OnDestroy {

// #endregion

constructor(private cdr: ChangeDetectorRef, private i18n: NzI18nService, @Optional() private directionality: Directionality) { }
constructor(private cdr: ChangeDetectorRef, private i18n: NzI18nService, @Optional() private directionality: Directionality) {}

// #region upload

Expand Down

0 comments on commit f34840b

Please sign in to comment.