Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(module:all): Add RTL support to all ng-zorro-antd #4703

Merged
merged 177 commits into from
Dec 15, 2020
Merged
Show file tree
Hide file tree
Changes from 175 commits
Commits
Show all changes
177 commits
Select commit Hold shift + click to select a range
2f00366
feat(module:nz-table): add rtl support
saeedrahimi Jan 20, 2020
4d786af
feat(module:table): add rtl tests and some rtl fixes
saeedrahimi Jan 20, 2020
a7b7494
feat(module:grid): add rtl support
saeedrahimi Jan 20, 2020
ce50527
feat(module:demo): add some rtl fixes to whole demo
saeedrahimi Jan 20, 2020
d80b199
fix(module:layout): fix rtl button issue
saeedrahimi Feb 1, 2020
61febb0
feat(module:cascader): added rtl support
saeedrahimi Feb 1, 2020
574ac4e
feat(module:carousel): added rtl direction
saeedrahimi Feb 1, 2020
c500040
feat(module:button): added rtl direction
saeedrahimi Feb 2, 2020
04bad6c
feat(module:layout): added rtl direction
saeedrahimi Feb 2, 2020
0e3f0e4
feat(module:descriptions): added rtl direction
saeedrahimi Feb 2, 2020
dc54bc8
feat(module:menu): added rtl direction
saeedrahimi Feb 2, 2020
8a7df5f
fix(module:cascader): fix arrow direction in RTL
saeedrahimi Mar 14, 2020
33bc8fb
feat(module:breadcrumb): add rtl direction
saeedrahimi Mar 14, 2020
2160ca9
feat(module:badge): add rtl direction
saeedrahimi Mar 14, 2020
da2da66
feat(module:comment): add rtl direction
saeedrahimi Mar 14, 2020
fcc7dd9
feat(module:drawer): add rtl direction
saeedrahimi Mar 14, 2020
2adf344
feat(module:steps): add rtl direction
saeedrahimi Mar 14, 2020
517dfed
feat(module:tag): add rtl direction
saeedrahimi Mar 14, 2020
d01d7a1
feat(module:treeselect): add rtl direction
saeedrahimi Mar 14, 2020
9544c60
feat(module:typography): add rtl direction
saeedrahimi Mar 14, 2020
6baeef3
feat(module:progress): add rtl direction
saeedrahimi Mar 14, 2020
36f4334
feat(module:rate): add rtl direction
saeedrahimi Mar 14, 2020
ffbcd1e
feat(module:result): add rtl direction
saeedrahimi Mar 14, 2020
aa9974a
feat(module:statistic): add rtl direction
saeedrahimi Mar 14, 2020
5cb6e57
feat(module:statistic): add rtl direction
saeedrahimi Mar 14, 2020
66d44c4
feat(module:tooltip): wip add rtl-direction
saeedrahimi Mar 14, 2020
92ae61e
feat(module:table): some rtl fixes after rebase
saeedrahimi Mar 24, 2020
caa02b8
feat(module:popover): some rtl fixes after rebase
saeedrahimi Mar 24, 2020
253b5f7
feat(module:tooltip): add rtl-direction
saeedrahimi Mar 25, 2020
bba6248
feat(module:affix): add rtl direction
saeedrahimi Mar 25, 2020
f42b8f5
feat(module:dropdown): add rtl direction
saeedrahimi Mar 25, 2020
e3154e3
feat(module:pagination): add rtl direction
saeedrahimi Mar 25, 2020
eb46c94
feat(module:select): add rtl direction
saeedrahimi Mar 25, 2020
c2f3fe3
fix(module:breadcrumb): float in rtl
saeedrahimi Mar 25, 2020
1b73d4f
feat(module:page-header): add rtl direction
saeedrahimi Mar 25, 2020
9d4e576
feat(module:autocomplete): add rtl direction
saeedrahimi Mar 25, 2020
e470c7a
feat(module:checkbox): add rtl direction
saeedrahimi Mar 25, 2020
92f798a
feat(module:radio): add rtl direction
saeedrahimi Mar 25, 2020
48cd7d6
feat(module:switch): add rtl direction
saeedrahimi Mar 25, 2020
9d65221
feat(module:popover): add rtl direction
saeedrahimi Mar 25, 2020
da47982
feat(module:datepicker): add rtl direction
saeedrahimi Apr 4, 2020
2e24bdd
fix(module:datepicker): fix issues after rebase
saeedrahimi May 30, 2020
2773d01
fix(module:carousel): resolve error
saeedrahimi Oct 3, 2020
e51eb56
fix(module:demo): resolve error
saeedrahimi Oct 3, 2020
ddeff3d
feat(module: tabs): add rtl support
hdm91 May 23, 2020
b00719a
feat(module: tree): add rtl support
hdm91 May 23, 2020
5511dff
feat(module: collapse): add rtl support
hdm91 May 23, 2020
8fd1179
feat(module: transfer): add rtl support
hdm91 May 23, 2020
031a2ad
feat(module: slider): add rtl support
hdm91 May 23, 2020
91f7bba
feat(module: alert): add rtl support
hdm91 May 23, 2020
c7f1426
feat(module:list): add rtl support
hdm91 May 23, 2020
1cbe088
feat(module: upload): add rtl support
hdm91 May 23, 2020
b067150
feat(module: spin): add rtl support
hdm91 May 23, 2020
13235a5
feat(module: modal): add rtl support to declarative modal
hdm91 May 23, 2020
b015445
feat(module: input-number): add rtl support
hdm91 May 21, 2020
d5c26ba
feat(module: input): add rtl support
hdm91 May 21, 2020
28f1364
feat(module: form): add rtl support
hdm91 May 21, 2020
6ea3b1b
fix(module:date-picker): fix rtl direction
hdm91 May 13, 2020
a823e35
fix(module:all): resolve CodeFactor issues
saeedrahimi Oct 3, 2020
d2ad6a4
fix(module:checkbox): order imports
saeedrahimi Oct 3, 2020
e88c5ab
fix(module:tree): order imports
saeedrahimi Oct 3, 2020
f9fcc7d
fix(module:upload): undo removed line after merge
saeedrahimi Oct 3, 2020
fdde82e
fix(module:cascader): rtl, remove inline style
saeedrahimi Oct 3, 2020
f5417ad
fix(module:menu): change optional directionality accessor
saeedrahimi Oct 3, 2020
1c7bee9
fix(module:steps): change optional directionality accessor
saeedrahimi Oct 3, 2020
eba84bd
fix(module:alert): change optional directionality accessor
saeedrahimi Oct 3, 2020
6cd7902
fix(module:tabs): change optional directionality accessor
saeedrahimi Oct 3, 2020
6e4c8a6
fix(module:checkbox): change optional directionality accessor
saeedrahimi Oct 3, 2020
b4f0dc4
fix(module:input): change optional directionality accessor
saeedrahimi Oct 3, 2020
31b1d57
fix(module:pagination): change optional directionality accessor
saeedrahimi Oct 3, 2020
cfe003e
fix(module:all): change optional directionality accessor
saeedrahimi Oct 3, 2020
edc64eb
fix(module:all): resolve test
saeedrahimi Oct 3, 2020
18ce9b6
fix(module:test): remove rtl
saeedrahimi Oct 3, 2020
44292c0
fix(module:datepicker): resolve test
saeedrahimi Oct 3, 2020
478725d
test(module:comment): add rtl tests
saeedrahimi Oct 4, 2020
50f4b44
test(module:alert): add rtl tests
saeedrahimi Oct 4, 2020
00e904b
test(module:comment): fix rtl tests
saeedrahimi Oct 4, 2020
2c3b26f
test(module:badge): add rtl tests
saeedrahimi Oct 4, 2020
7a9b6c7
test(module:breadcrumb): add rtl tests
saeedrahimi Oct 4, 2020
a2e393d
test(module:cascader): add rtl tests
saeedrahimi Oct 4, 2020
6300c14
test(module:tag): add rtl tests
saeedrahimi Oct 4, 2020
9a3fef6
test(module:radio): add rtl tests
saeedrahimi Oct 4, 2020
d0e620c
test(module:pageheader): add rtl tests
saeedrahimi Oct 4, 2020
e7633e8
test(module:timeline): add rtl tests
saeedrahimi Oct 4, 2020
fb41946
test(module:result): add rtl tests
saeedrahimi Oct 4, 2020
812c723
test(module:tag): update test
saeedrahimi Oct 4, 2020
b962a57
test(module:tag): update test
saeedrahimi Oct 4, 2020
d6326d3
test(module:tag): update test
saeedrahimi Oct 4, 2020
c93d853
test(module:tag): update test
saeedrahimi Oct 4, 2020
0ab310e
test(module:cascader): update test
saeedrahimi Oct 4, 2020
12cf700
test(module:cascader): update test
saeedrahimi Oct 6, 2020
4c89cf4
test(module:tag): update test
saeedrahimi Oct 6, 2020
443f0cb
test(module:radio): update test
saeedrahimi Oct 6, 2020
49a2051
test(module:result): update test
saeedrahimi Oct 6, 2020
ff3ad23
test(module:radio): update test
saeedrahimi Oct 6, 2020
077b1e9
test(module:result): update test
saeedrahimi Oct 6, 2020
8c53dd1
test(module:comment): update test
saeedrahimi Oct 6, 2020
01620d3
test(module:breadcrumb): update test
saeedrahimi Oct 6, 2020
498ea96
test(module:button): add test
saeedrahimi Oct 6, 2020
eca620c
test(module:spin): add test
saeedrahimi Oct 6, 2020
8c15489
test(module:button): update test
saeedrahimi Oct 7, 2020
a710c2f
test(module:checkbox): add test
saeedrahimi Oct 7, 2020
fa5868a
test(module:cascader): update test
saeedrahimi Oct 7, 2020
523f614
test(module:cascader): update test
saeedrahimi Oct 7, 2020
62b1bc1
test(module:checkbox): update test
saeedrahimi Oct 7, 2020
5c9d9ec
Merge branch 'master' of https://github.com/NG-ZORRO/ng-zorro-antd in…
saeedrahimi Oct 9, 2020
2f8d6b9
test(module:steps): add test
saeedrahimi Oct 9, 2020
7a09d40
test(module:alert): add test
saeedrahimi Oct 9, 2020
c76c452
test(module:collapse): add rtl tests
saeedrahimi Oct 9, 2020
fe8ca15
test(module:affix): add rtl tests
saeedrahimi Oct 9, 2020
1e5273e
test(module:statistic): add rtl tests
saeedrahimi Oct 9, 2020
4414a2d
test(module:timeline): update rtl tests
saeedrahimi Oct 9, 2020
26d6e55
test(module:switch): add rtl tests
saeedrahimi Oct 10, 2020
2a94b7d
test(module:drawer): add rtl tests
saeedrahimi Oct 10, 2020
99fb522
feat: rt for messages
HDaghash Oct 11, 2020
efc9275
test: message rtl
HDaghash Oct 12, 2020
aece250
fix: set direction
HDaghash Oct 12, 2020
9823398
feat: back to top rtl
HDaghash Oct 12, 2020
4fc846b
feat: card rtl skeleton
HDaghash Oct 12, 2020
6167ece
Merge branch 'master' of https://github.com/NG-ZORRO/ng-zorro-antd in…
saeedrahimi Oct 18, 2020
1383be3
fix(module:*): fix rtl direction error
Nov 10, 2020
cf341dd
Merge pull request #8 from hmdnikoo/filerplus-ng-zorro-antd-v10
saeedrahimi Nov 22, 2020
0b5ab79
fix(module:tabs): resolve rtl issue
saeedrahimi Dec 13, 2020
9af206b
fix(module:site): fix demo site rtl style
saeedrahimi Dec 13, 2020
40ceb47
fix(module:pagination): add rtl
saeedrahimi Dec 13, 2020
ba8e7e1
fix(module:input): fix rtl search button size
saeedrahimi Dec 13, 2020
d89ebb4
fix(module:dropdown): fix rtl menu icon
saeedrahimi Dec 13, 2020
ff35082
fix(module:menu): fix rtl sub-menu position
saeedrahimi Dec 13, 2020
1cbc166
fix(module:timepicker): add rtl
saeedrahimi Dec 13, 2020
9cd0aed
feat(module:slider): add rtl
saeedrahimi Dec 13, 2020
fab7e30
fix(module:input): fix input btn-icon size
saeedrahimi Dec 13, 2020
8509d67
fix(module:upload): fix rtl issue on ngOnInit
saeedrahimi Dec 13, 2020
bc7b8b7
fix(module:slider): change dir order in ngOnInit
saeedrahimi Dec 13, 2020
4fd320f
Merge branch 'v9-rtl' of https://github.com/HDaghash/ng-zorro-antd in…
saeedrahimi Dec 13, 2020
0c86b80
fix(module:back-top): fix demo divTarget rtl
saeedrahimi Dec 13, 2020
73a8930
Merge branch 'master' of https://github.com/saeedrahimi/ng-zorro-antd…
saeedrahimi Dec 13, 2020
af06c20
fix(module:*): fix cascader and upload tests
saeedrahimi Dec 13, 2020
4d5edf8
Merge branch 'master' of https://github.com/NG-ZORRO/ng-zorro-antd in…
saeedrahimi Dec 13, 2020
9898e18
fix(module:calendar): add rtl
saeedrahimi Dec 13, 2020
e70aff3
chore: package.json remove version
saeedrahimi Dec 13, 2020
2df2ccc
chore: fix some issues after merge
saeedrahimi Dec 13, 2020
270a8c6
test(module:card): add rtl test
saeedrahimi Dec 13, 2020
382337c
test(module:pagination): add rtl tests
saeedrahimi Dec 13, 2020
a26507b
test(module:affix): change coverage
saeedrahimi Dec 13, 2020
6386891
Update components/back-top/back-top.component.ts
saeedrahimi Dec 14, 2020
9aa40ba
Update components/tree-select/tree-select.component.ts
saeedrahimi Dec 14, 2020
7f350ad
Update components/grid/col.directive.ts
saeedrahimi Dec 14, 2020
c8c9d24
Update components/grid/row.directive.ts
saeedrahimi Dec 14, 2020
1e18f1c
Update scripts/site/_site/doc/app/app.component.html
saeedrahimi Dec 14, 2020
f134346
Update components/menu/menu-item.directive.ts
saeedrahimi Dec 14, 2020
a4926bc
Update components/message/message-container.component.ts
saeedrahimi Dec 14, 2020
ea726fb
Update components/page-header/page-header.component.ts
saeedrahimi Dec 14, 2020
34167bb
fix(module:card): move rtl styles to patch.less
saeedrahimi Dec 14, 2020
75e880b
fix(module:back-top): add destroy$
saeedrahimi Dec 14, 2020
1df3d2e
fix(module:input): fix input-group demo
saeedrahimi Dec 14, 2020
a087aa4
fix(module:affix): fix test error
saeedrahimi Dec 14, 2020
6b8c062
fix(module:core): remove fake document for test
saeedrahimi Dec 14, 2020
7bdf74c
fix(module:demo): change rtl styles
saeedrahimi Dec 14, 2020
c6f4788
fix(module:tabs): remove unused dir
saeedrahimi Dec 14, 2020
688c74e
fix(module:cascader): refactor cascader rtl
saeedrahimi Dec 14, 2020
d9f2a20
Merge branch 'v9-rtl' of https://github.com/saeedrahimi/ng-zorro-antd…
saeedrahimi Dec 14, 2020
69c773d
test(module:slider): add rtl tests
saeedrahimi Dec 14, 2020
ad95167
test(module:menu): add rtl test
saeedrahimi Dec 14, 2020
0a8661c
test(module:grid): add rtl tests
saeedrahimi Dec 14, 2020
9ed922f
test(module:descriptions): add rtl tests
saeedrahimi Dec 14, 2020
89841e9
test(module:button): add button-group test
saeedrahimi Dec 14, 2020
c1c5c11
test(module:calendar): add rtl tests
saeedrahimi Dec 14, 2020
5d0a567
test(module:carousel): add rtl tests
saeedrahimi Dec 14, 2020
06b7d3e
test(module:descriptions): fix descriptions
saeedrahimi Dec 14, 2020
b012ade
test(module:page-header): increase rtl test cover
saeedrahimi Dec 14, 2020
931bba1
test(module:rate): add rtl test
saeedrahimi Dec 14, 2020
5e8412c
test(module:layout): add rtl test
saeedrahimi Dec 14, 2020
4b94b45
test(module:list): add rtl test
saeedrahimi Dec 14, 2020
5e08cf0
test(module:progress): add rtl test
saeedrahimi Dec 14, 2020
9047622
test(module:transfer): add rtl test
saeedrahimi Dec 14, 2020
1c4d11e
Update components/menu/submenu-title.component.ts
saeedrahimi Dec 15, 2020
bfd485f
Update components/menu/menu-item.directive.ts
saeedrahimi Dec 15, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node-options=--max-old-space-size=14000
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤦‍♂️ No, it's for my local development

38 changes: 35 additions & 3 deletions components/affix/affix.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { DOCUMENT } from '@angular/common';
import {
AfterViewInit,
ChangeDetectionStrategy,
ChangeDetectorRef,
Component,
ElementRef,
EventEmitter,
Expand All @@ -16,6 +17,8 @@ import {
NgZone,
OnChanges,
OnDestroy,
OnInit,
Optional,
Output,
Renderer2,
SimpleChanges,
Expand All @@ -30,6 +33,7 @@ import { getStyleAsText, InputNumber, shallowEqual } from 'ng-zorro-antd/core/ut
import { fromEvent, merge, ReplaySubject, Subject, Subscription } from 'rxjs';
import { auditTime, map, takeUntil } from 'rxjs/operators';

import { Direction, Directionality } from '@angular/cdk/bidi';
import { AffixRespondEvents } from './respond-events';
import { getTargetRect, SimpleRect } from './utils';

Expand All @@ -48,7 +52,7 @@ const NZ_AFFIX_DEFAULT_SCROLL_TIME = 20;
changeDetection: ChangeDetectionStrategy.OnPush,
encapsulation: ViewEncapsulation.None
})
export class NzAffixComponent implements AfterViewInit, OnChanges, OnDestroy {
export class NzAffixComponent implements AfterViewInit, OnChanges, OnDestroy, OnInit {
readonly _nzModuleName: NzConfigKey = NZ_CONFIG_MODULE_NAME;
static ngAcceptInputType_nzOffsetTop: NumberInput;
static ngAcceptInputType_nzOffsetBottom: NumberInput;
Expand All @@ -69,6 +73,8 @@ export class NzAffixComponent implements AfterViewInit, OnChanges, OnDestroy {

@Output() readonly nzChange = new EventEmitter<boolean>();

dir: Direction = 'ltr';

private readonly placeholderNode: HTMLElement;

private affixStyle?: NgStyleInterface;
Expand All @@ -91,13 +97,26 @@ export class NzAffixComponent implements AfterViewInit, OnChanges, OnDestroy {
private scrollSrv: NzScrollService,
private ngZone: NgZone,
private platform: Platform,
private renderer: Renderer2
private renderer: Renderer2,
private cdr: ChangeDetectorRef,
@Optional() private directionality: Directionality
) {
// The wrapper would stay at the original position as a placeholder.
this.placeholderNode = el.nativeElement;
this.document = doc;
}

ngOnInit(): void {
this.directionality.change?.pipe(takeUntil(this.destroy$)).subscribe((direction: Direction) => {
this.dir = direction;
this.registerListeners();
this.updatePosition({} as Event);
this.cdr.detectChanges();
});

this.dir = this.directionality.value;
}

ngOnChanges(changes: SimpleChanges): void {
const { nzOffsetBottom, nzOffsetTop, nzTarget } = changes;

Expand Down Expand Up @@ -182,7 +201,7 @@ export class NzAffixComponent implements AfterViewInit, OnChanges, OnDestroy {
} else {
wrapEl.classList.remove(NZ_AFFIX_CLS_PREFIX);
}

this.updateRtlClass();
if ((affixStyle && !originalAffixStyle) || (!affixStyle && originalAffixStyle)) {
this.nzChange.emit(fixed);
}
Expand Down Expand Up @@ -289,4 +308,17 @@ export class NzAffixComponent implements AfterViewInit, OnChanges, OnDestroy {
this.syncPlaceholderStyle(e);
}
}

private updateRtlClass(): void {
const wrapEl = this.fixedEl.nativeElement;
if (this.dir === 'rtl') {
if (wrapEl.classList.contains(NZ_AFFIX_CLS_PREFIX)) {
wrapEl.classList.add(`${NZ_AFFIX_CLS_PREFIX}-rtl`);
} else {
wrapEl.classList.remove(`${NZ_AFFIX_CLS_PREFIX}-rtl`);
}
} else {
wrapEl.classList.remove(`${NZ_AFFIX_CLS_PREFIX}-rtl`);
}
}
}
102 changes: 81 additions & 21 deletions components/affix/affix.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { BidiModule, Dir } from '@angular/cdk/bidi';
import { Component, DebugElement, ViewChild } from '@angular/core';
import { ComponentFixture, discardPeriodicTasks, fakeAsync, TestBed, tick } from '@angular/core/testing';
import { ComponentFixture, discardPeriodicTasks, fakeAsync, TestBed, tick, waitForAsync } from '@angular/core/testing';
import { By } from '@angular/platform-browser';
import { NzScrollService } from 'ng-zorro-antd/core/services';

Expand Down Expand Up @@ -40,26 +41,28 @@ describe('affix', () => {
const height = 100;
const width = 100;

beforeEach(fakeAsync(() => {
TestBed.configureTestingModule({
imports: [NzAffixModule],
declarations: [TestAffixComponent],
providers: [
{
provide: NzScrollService,
useClass: NzScrollService
}
]
}).compileComponents();

fixture = TestBed.createComponent(TestAffixComponent);
context = fixture.componentInstance;
component = context.nzAffixComponent;
scrollService = TestBed.inject(NzScrollService);
componentObject = new NzAffixPageObject();
debugElement = fixture.debugElement;
componentObject.wrap().id = 'wrap';
}));
beforeEach(
waitForAsync(() => {
TestBed.configureTestingModule({
imports: [NzAffixModule],
declarations: [TestAffixComponent],
providers: [
{
provide: NzScrollService,
useClass: NzScrollService
}
]
}).compileComponents();

fixture = TestBed.createComponent(TestAffixComponent);
context = fixture.componentInstance;
component = context.nzAffixComponent;
scrollService = TestBed.inject(NzScrollService);
componentObject = new NzAffixPageObject();
debugElement = fixture.debugElement;
componentObject.wrap().id = 'wrap';
})
);
afterEach(fakeAsync(() => {
setupInitialState();
}));
Expand Down Expand Up @@ -493,6 +496,43 @@ describe('affix-extra', () => {
}));
});

describe('affix RTL', () => {
let fixture: ComponentFixture<TestAffixRtlComponent>;
let context: TestAffixRtlComponent;
let dl: DebugElement;

beforeEach(
waitForAsync(() => {
TestBed.configureTestingModule({
imports: [BidiModule, NzAffixModule],
declarations: [TestAffixRtlComponent]
}).compileComponents();
fixture = TestBed.createComponent(TestAffixRtlComponent);
context = fixture.componentInstance;
dl = fixture.debugElement;
})
);
it('should className correct on dir change', fakeAsync(() => {
const value = 10;
context.newOffsetBottom = value;
context.fakeTarget = window;
fixture.detectChanges();
const el = dl.query(By.css('nz-affix')).nativeElement as HTMLElement;
spyOn(el, 'getBoundingClientRect').and.returnValue({
top: 1000,
left: 5,
width: 200,
height: 20
} as DOMRect);
window.dispatchEvent(new Event('scroll'));
tick(30);
fixture.detectChanges();
window.dispatchEvent(new Event('scroll'));
tick(30);
fixture.detectChanges();
expect(el.querySelector('.ant-affix')?.classList).toContain('ant-affix-rtl');
}));
});
@Component({
template: `
<nz-affix id="affix" [nzTarget]="fakeTarget" [nzOffsetTop]="newOffset" [nzOffsetBottom]="newOffsetBottom">
Expand All @@ -507,3 +547,23 @@ class TestAffixComponent {
newOffset!: number;
newOffsetBottom!: number;
}

@Component({
template: `
<div [dir]="direction">
<nz-affix id="affix" [nzTarget]="fakeTarget" [nzOffsetTop]="newOffset" [nzOffsetBottom]="newOffsetBottom">
<button id="content">Affix Button</button>
</nz-affix>
<div id="target"></div>
</div>
`
})
export class TestAffixRtlComponent {
@ViewChild(Dir) dir!: Dir;
direction = 'rtl';

@ViewChild(NzAffixComponent, { static: true }) nzAffixComponent!: NzAffixComponent;
fakeTarget: string | Element | Window | null = null;
newOffset!: number;
newOffsetBottom!: number;
}
18 changes: 16 additions & 2 deletions components/alert/alert.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* found in the LICENSE file at https://github.com/NG-ZORRO/ng-zorro-antd/blob/master/LICENSE
*/

import { Direction, Directionality } from '@angular/cdk/bidi';
import {
ChangeDetectionStrategy,
ChangeDetectorRef,
Expand All @@ -11,6 +12,8 @@ import {
Input,
OnChanges,
OnDestroy,
OnInit,
Optional,
Output,
SimpleChanges,
TemplateRef,
Expand All @@ -33,6 +36,7 @@ const NZ_CONFIG_MODULE_NAME: NzConfigKey = 'alert';
<div
*ngIf="!closed"
class="ant-alert"
[class.ant-alert-rtl]="dir === 'rtl'"
[class.ant-alert-success]="nzType === 'success'"
[class.ant-alert-info]="nzType === 'info'"
[class.ant-alert-warning]="nzType === 'warning'"
Expand Down Expand Up @@ -72,7 +76,7 @@ const NZ_CONFIG_MODULE_NAME: NzConfigKey = 'alert';
encapsulation: ViewEncapsulation.None,
preserveWhitespaces: false
})
export class NzAlertComponent implements OnChanges, OnDestroy {
export class NzAlertComponent implements OnChanges, OnDestroy, OnInit {
readonly _nzModuleName: NzConfigKey = NZ_CONFIG_MODULE_NAME;
static ngAcceptInputType_nzCloseable: BooleanInput;
static ngAcceptInputType_nzShowIcon: BooleanInput;
Expand All @@ -92,11 +96,12 @@ export class NzAlertComponent implements OnChanges, OnDestroy {
closed = false;
iconTheme: 'outline' | 'fill' = 'fill';
inferredIconType: string = 'info-circle';
dir: Direction = 'ltr';
private isTypeSet = false;
private isShowIconSet = false;
private destroy$ = new Subject();

constructor(public nzConfigService: NzConfigService, private cdr: ChangeDetectorRef) {
constructor(public nzConfigService: NzConfigService, private cdr: ChangeDetectorRef, @Optional() private directionality: Directionality) {
this.nzConfigService
.getConfigChangeEventForComponent(NZ_CONFIG_MODULE_NAME)
.pipe(takeUntil(this.destroy$))
Expand All @@ -105,6 +110,15 @@ export class NzAlertComponent implements OnChanges, OnDestroy {
});
}

ngOnInit(): void {
this.directionality.change?.pipe(takeUntil(this.destroy$)).subscribe((direction: Direction) => {
this.dir = direction;
this.cdr.detectChanges();
});

this.dir = this.directionality.value;
}

closeAlert(): void {
this.closed = true;
}
Expand Down
53 changes: 42 additions & 11 deletions components/alert/alert.spec.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
import { BidiModule, Dir } from '@angular/cdk/bidi';
import { Component, DebugElement, TemplateRef, ViewChild } from '@angular/core';
import { ComponentFixture, fakeAsync, TestBed, tick } from '@angular/core/testing';
import { ComponentFixture, fakeAsync, TestBed, tick, waitForAsync } from '@angular/core/testing';
import { By } from '@angular/platform-browser';
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
import { NzIconTestModule } from 'ng-zorro-antd/icon/testing';
import { NzAlertComponent } from './alert.component';
import { NzAlertModule } from './alert.module';

describe('alert', () => {
beforeEach(fakeAsync(() => {
TestBed.configureTestingModule({
imports: [NzAlertModule, NoopAnimationsModule, NzIconTestModule],
declarations: [NzDemoTestBasicComponent, NzDemoTestBannerComponent]
});
TestBed.compileComponents();
}));
beforeEach(
waitForAsync(() => {
TestBed.configureTestingModule({
imports: [BidiModule, NzAlertModule, NoopAnimationsModule, NzIconTestModule],
declarations: [NzDemoTestBasicComponent, NzDemoTestBannerComponent, NzTestAlertRtlComponent]
});
TestBed.compileComponents();
})
);

describe('basic alert', () => {
let fixture: ComponentFixture<NzDemoTestBasicComponent>;
let testComponent: NzDemoTestBasicComponent;
Expand Down Expand Up @@ -115,9 +119,23 @@ describe('alert', () => {
expect(alert.nativeElement.querySelector('.ant-alert-icon')).toBeDefined();
});
});
describe('RTL', () => {
it('should className correct on dir change', () => {
const fixture = TestBed.createComponent(NzTestAlertRtlComponent);
const alert = fixture.debugElement.query(By.directive(NzAlertComponent));
fixture.detectChanges();
expect(alert.nativeElement.firstElementChild!.classList).toContain('ant-alert-rtl');

fixture.componentInstance.direction = 'ltr';
fixture.detectChanges();
expect(alert.nativeElement.firstElementChild!.classList).not.toContain('ant-alert-rtl');
});
});
});

@Component({
// tslint:disable-next-line:no-selector
selector: 'nz-test-basic-alert',
hsuanxyz marked this conversation as resolved.
Show resolved Hide resolved
template: `
<ng-template #template>template</ng-template>
<nz-alert
Expand All @@ -130,8 +148,7 @@ describe('alert', () => {
[nzIconType]="iconType"
[nzType]="type"
(nzOnClose)="onClose($event)"
>
</nz-alert>
></nz-alert>
`
})
export class NzDemoTestBasicComponent {
Expand All @@ -148,6 +165,20 @@ export class NzDemoTestBasicComponent {
}

@Component({
template: ` <nz-alert nzBanner> </nz-alert> `
template: `
<nz-alert nzBanner></nz-alert>
`
})
export class NzDemoTestBannerComponent {}

@Component({
template: `
<div [dir]="direction">
<nz-test-basic-alert></nz-test-basic-alert>
</div>
`
})
export class NzTestAlertRtlComponent {
@ViewChild(Dir) dir!: Dir;
direction = 'rtl';
}
Loading