Skip to content

Commit 4143473

Browse files
yuhengzhouzYuhengZhou
andauthored
feat(module:resizable): add direction parameter in NzResizeEvent (#7987)
Co-authored-by: YuhengZhou <YuhengZhou@thoughtworks.com>
1 parent e240264 commit 4143473

File tree

5 files changed

+24
-8
lines changed

5 files changed

+24
-8
lines changed

components/resizable/demo/basic.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Component } from '@angular/core';
22

3-
import { NzResizeEvent } from 'ng-zorro-antd/resizable';
3+
import { NzResizeDirection, NzResizeEvent } from 'ng-zorro-antd/resizable';
44

55
@Component({
66
selector: 'nz-demo-resizable-basic',
@@ -42,12 +42,14 @@ export class NzDemoResizableBasicComponent {
4242
height = 200;
4343
id = -1;
4444
disabled = false;
45+
resizeDirection: NzResizeDirection | null = null;
4546

46-
onResize({ width, height }: NzResizeEvent): void {
47+
onResize({ width, height, direction }: NzResizeEvent): void {
4748
cancelAnimationFrame(this.id);
4849
this.id = requestAnimationFrame(() => {
4950
this.width = width!;
5051
this.height = height!;
52+
this.resizeDirection = direction!;
5153
});
5254
}
5355
}

components/resizable/doc/index.en-US.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ interface NzResizeEvent {
4646
width?: number;
4747
height?: number;
4848
col?: number;
49-
mouseEvent?: MouseEvent
49+
direction?: NzResizeDirection;
50+
mouseEvent?: MouseEvent;
5051
}
5152
```
5253

components/resizable/doc/index.zh-CN.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ interface NzResizeEvent {
4545
width?: number;
4646
height?: number;
4747
col?: number;
48-
mouseEvent?: MouseEvent
48+
direction?: NzResizeDirection;
49+
mouseEvent?: MouseEvent;
4950
}
5051
```
5152

components/resizable/resizable.directive.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,14 @@ import { ensureInBounds, InputBoolean } from 'ng-zorro-antd/core/util';
2424

2525
import { getEventWithPoint } from './resizable-utils';
2626
import { NzResizableService } from './resizable.service';
27-
import { NzResizeHandleMouseDownEvent } from './resize-handle.component';
27+
import { NzResizeDirection, NzResizeHandleMouseDownEvent } from './resize-handle.component';
2828

2929
export interface NzResizeEvent {
3030
width?: number;
3131
height?: number;
3232
col?: number;
3333
mouseEvent?: MouseEvent | TouchEvent;
34+
direction?: NzResizeDirection;
3435
}
3536

3637
@Directive({
@@ -87,7 +88,7 @@ export class NzResizableDirective implements AfterViewInit, OnDestroy {
8788
this.currentHandleEvent = event;
8889
this.setCursor();
8990
if (this.nzResizeStart.observers.length) {
90-
this.ngZone.run(() => this.nzResizeStart.emit({ mouseEvent: event.mouseEvent }));
91+
this.ngZone.run(() => this.nzResizeStart.emit({ mouseEvent: event.mouseEvent, direction: event.direction }));
9192
}
9293
this.elRect = this.el.getBoundingClientRect();
9394
});
@@ -250,7 +251,8 @@ export class NzResizableDirective implements AfterViewInit, OnDestroy {
250251
this.ngZone.run(() => {
251252
this.nzResize.emit({
252253
...size,
253-
mouseEvent: event
254+
mouseEvent: event,
255+
direction: this.currentHandleEvent!.direction
254256
});
255257
});
256258
}
@@ -275,7 +277,8 @@ export class NzResizableDirective implements AfterViewInit, OnDestroy {
275277
this.ngZone.run(() => {
276278
this.nzResizeEnd.emit({
277279
...size,
278-
mouseEvent: event
280+
mouseEvent: event,
281+
direction: this.currentHandleEvent!.direction
279282
});
280283
});
281284
}

components/resizable/resizable.spec.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ describe('resizable', () => {
159159
fixture.detectChanges();
160160
expect(testComponent.height).toBeLessThanOrEqual(200);
161161
expect(testComponent.height).toBeGreaterThanOrEqual(100);
162+
expect(testComponent.resizeDirection).toEqual('top');
162163
}));
163164

164165
/**
@@ -184,6 +185,7 @@ describe('resizable', () => {
184185
fixture.detectChanges();
185186
expect(testComponent.height).toBeLessThanOrEqual(200);
186187
expect(testComponent.height).toBeGreaterThanOrEqual(100);
188+
expect(testComponent.resizeDirection).toEqual('top');
187189
}));
188190

189191
/**
@@ -209,6 +211,7 @@ describe('resizable', () => {
209211
fixture.detectChanges();
210212
expect(testComponent.height).toBeLessThanOrEqual(200);
211213
expect(testComponent.height).toBeGreaterThanOrEqual(100);
214+
expect(testComponent.resizeDirection).toEqual('bottom');
212215
}));
213216

214217
/**
@@ -234,6 +237,7 @@ describe('resizable', () => {
234237
fixture.detectChanges();
235238
expect(testComponent.width).toBeLessThanOrEqual(400);
236239
expect(testComponent.width).toBeGreaterThanOrEqual(300);
240+
expect(testComponent.resizeDirection).toEqual('left');
237241
}));
238242

239243
/**
@@ -259,6 +263,7 @@ describe('resizable', () => {
259263
fixture.detectChanges();
260264
expect(testComponent.width).toBeLessThanOrEqual(400);
261265
expect(testComponent.width).toBeGreaterThanOrEqual(300);
266+
expect(testComponent.resizeDirection).toEqual('right');
262267
}));
263268

264269
/**
@@ -286,6 +291,7 @@ describe('resizable', () => {
286291
expect(testComponent.width).toBeGreaterThanOrEqual(300);
287292
expect(testComponent.height).toBeLessThanOrEqual(210);
288293
expect(testComponent.height).toBeGreaterThanOrEqual(100);
294+
expect(testComponent.resizeDirection).toEqual('topRight');
289295
}));
290296

291297
/**
@@ -313,6 +319,7 @@ describe('resizable', () => {
313319
expect(testComponent.width).toBeGreaterThanOrEqual(300);
314320
expect(testComponent.height).toBeLessThanOrEqual(200);
315321
expect(testComponent.height).toBeGreaterThanOrEqual(100);
322+
expect(testComponent.resizeDirection).toEqual('topLeft');
316323
}));
317324

318325
/**
@@ -340,6 +347,7 @@ describe('resizable', () => {
340347
expect(testComponent.width).toBeGreaterThanOrEqual(300);
341348
expect(testComponent.height).toBeLessThanOrEqual(190);
342349
expect(testComponent.height).toBeGreaterThanOrEqual(100);
350+
expect(testComponent.resizeDirection).toEqual('bottomRight');
343351
}));
344352

345353
/**
@@ -367,6 +375,7 @@ describe('resizable', () => {
367375
expect(testComponent.width).toBeGreaterThanOrEqual(300);
368376
expect(testComponent.height).toBeLessThanOrEqual(200);
369377
expect(testComponent.height).toBeGreaterThanOrEqual(100);
378+
expect(testComponent.resizeDirection).toEqual('bottomLeft');
370379
}));
371380
});
372381

0 commit comments

Comments
 (0)