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:resizable): add nzDisabled property #5475

Merged
merged 2 commits into from
Jul 9, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
2 changes: 2 additions & 0 deletions components/resizable/demo/basic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { NzResizeEvent } from 'ng-zorro-antd/resizable';
[nzMinWidth]="80"
[nzMaxHeight]="200"
[nzMinHeight]="80"
[nzDisabled]="disabled"
[style.height.px]="height"
[style.width.px]="width"
(nzResize)="onResize($event)"
Expand Down Expand Up @@ -39,6 +40,7 @@ export class NzDemoResizableBasicComponent {
width = 400;
height = 200;
id = -1;
disabled = false;

onResize({ width, height }: NzResizeEvent): void {
cancelAnimationFrame(this.id);
Expand Down
1 change: 1 addition & 0 deletions components/resizable/doc/index.en-US.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ interface NzResizeEvent {
| [nzMinColumn] | Minimum Column | `number` | - |
| [nzLockAspectRatio] | Lock the aspect ratio based on the initial size | `boolean` | `false` |
| [nzPreview] | Enable preview when resizing | `boolean` | `false` |
| [nzDisabled] | Disable resize | `boolean` | `false` |
| (nzResize) | Calls when Resizing | `EventEmitter<NzResizeEvent>` | - |
| (nzResizeStart) | Calls when resize start | `EventEmitter<NzResizeEvent>` | - |
| (nzResizeEnd) | Calls when resize end | `EventEmitter<NzResizeEvent>` | - |
Expand Down
1 change: 1 addition & 0 deletions components/resizable/doc/index.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ interface NzResizeEvent {
| [nzMinColumn] | 栅格最小列数 | `number` | - |
| [nzLockAspectRatio] | 锁定宽高比 | `boolean` | `false` |
| [nzPreview] | 开启预览 | `boolean` | `false` |
| [nzDisabled] | 禁用 | `boolean` | `false` |
| (nzResize) | 调整尺寸时的事件 | `EventEmitter<NzResizeEvent>` | - |
| (nzResizeStart) | 开始调整尺寸时的事件 | `EventEmitter<NzResizeEvent>` | - |
| (nzResizeEnd) | 结束调整尺寸时的事件 | `EventEmitter<NzResizeEvent>` | - |
Expand Down
5 changes: 5 additions & 0 deletions components/resizable/resizable.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export interface NzResizeEvent {
host: {
'[class.nz-resizable]': 'true',
'[class.nz-resizable-resizing]': 'resizing',
'[class.nz-resizable-disabled]': 'nzDisabled',
'(mouseenter)': 'onMouseenter()',
'(mouseleave)': 'onMouseleave()'
}
Expand All @@ -47,6 +48,7 @@ export class NzResizableDirective implements AfterViewInit, OnDestroy {
@Input() nzMinColumn: number = -1;
@Input() @InputBoolean() nzLockAspectRatio: boolean = false;
@Input() @InputBoolean() nzPreview: boolean = false;
@Input() @InputBoolean() nzDisabled: boolean = false;
@Output() readonly nzResize = new EventEmitter<NzResizeEvent>();
@Output() readonly nzResizeEnd = new EventEmitter<NzResizeEvent>();
@Output() readonly nzResizeStart = new EventEmitter<NzResizeEvent>();
Expand All @@ -67,6 +69,9 @@ export class NzResizableDirective implements AfterViewInit, OnDestroy {
private ngZone: NgZone
) {
this.nzResizableService.handleMouseDown$.pipe(takeUntil(this.destroy$)).subscribe(event => {
if (this.nzDisabled) {
return;
}
this.resizing = true;
this.nzResizableService.startResizing(event.mouseEvent);
this.currentHandleEvent = event;
Expand Down
24 changes: 24 additions & 0 deletions components/resizable/resizable.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,30 @@ describe('resizable', () => {
expect(testComponent.height).toBeGreaterThanOrEqual(100);
}));
});

it('should disabled work', fakeAsync(() => {
testComponent.disabled = true;
fixture.detectChanges();
expect(resizableEle.classList).toContain(`nz-resizable-disabled`);
expect(testComponent.width).toBe(400);
const rect = resizableEle.getBoundingClientRect();
const handle = resizableEle.querySelector('.nz-resizable-handle-left') as HTMLElement;
mouseMoveTrigger(
handle,
{
x: rect.left,
y: rect.bottom
},
{
x: rect.left + 100,
y: rect.bottom
}
);
fixture.detectChanges();
tick(16);
fixture.detectChanges();
expect(testComponent.width).toBe(400);
}));
});

describe('customize', () => {
Expand Down
8 changes: 8 additions & 0 deletions components/resizable/style/index.less
Original file line number Diff line number Diff line change
Expand Up @@ -83,5 +83,13 @@

}
}

&-disabled {
.@{resizable-prefix-cls} {
&-handle {
pointer-events: none;
}
}
}
}