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:tag): support fully control by user #3100

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
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
16 changes: 16 additions & 0 deletions components/tag/demo/full-control-checkable.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
order: 4
title:
zh-CN: 完整控制可选择
en-US: FullControlCheckable
---

## zh-CN

`Tag` 的状态完全由用户接管,不再自动根据点击事件改变数据。

## en-US

The status of `Tag` is completely up to the user and no longer automatically changes the data based on the click event.


12 changes: 12 additions & 0 deletions components/tag/demo/full-control-checkable.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { Component } from '@angular/core';

@Component({
selector: 'nz-demo-tag-full-control-checkable',
template: `
<nz-tag nzMode="checkable" [nzChecked]="checked" [nzControl]="true">Tag</nz-tag>
<nz-switch [(ngModel)]="checked"></nz-switch>
`
})
export class NzDemoTagFullControlCheckableComponent {
checked = false;
}
1 change: 1 addition & 0 deletions components/tag/doc/index.en-US.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ Tag for categorizing or markup.
| `[nzMode]` | Mode of tag | `'closeable'|'default'|'checkable'` | `'default'` |
| `[nzChecked]` | Checked status of Tag, double binding, only works when `nzMode="checkable"` | `boolean` | `false` |
| `[nzColor]` | Color of the Tag | `string` | - |
| `[nzControl]` | determine whether fully control state by user | `boolean` | `false` |
| `(nzAfterClose)` | Callback executed when close animation is completed, only works when `nzMode="closable"` | `EventEmitter<void>` | - |
| `(nzOnClose)` | Callback executed when tag is closed, only works when `nzMode="closable"`| `EventEmitter<MouseEvent>` | - |
| `(nzCheckedChange)` | Checked status change call back, only works when `nzMode="checkable"` | `EventEmitter<boolean>` | - |
1 change: 1 addition & 0 deletions components/tag/doc/index.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ title: Tag
| `[nzMode]` | 设定标签工作的模式 | `'closeable'|'default'|'checkable'` | `'default'` |
| `[nzChecked]` | 设置标签的选中状态,可双向绑定,在 `nzMode="checkable"` 时可用 | `boolean` | `false` |
| `[nzColor]` | 标签色 | `string` | - |
| `[nzControl]` | 是否完全由用户控制状态 | `boolean` | `false` |
| `(nzAfterClose)` | 关闭动画完成后的回调,在 `nzMode="closable"` 时可用 | `EventEmitter<void>` | - |
| `(nzOnClose)` | 关闭时的回调,在 `nzMode="closable"` 时可用 | `EventEmitter<MouseEvent>` | - |
| `(nzCheckedChange)` | 设置标签的选中状态的回调,在 `nzMode="checkable"` 时可用 | `EventEmitter<void>` | - |
3 changes: 2 additions & 1 deletion components/tag/nz-tag.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export class NzTagComponent implements OnInit, OnChanges {
presetColor = false;
@Input() nzMode: 'default' | 'closeable' | 'checkable' = 'default';
@Input() nzColor: string;
@Input() @InputBoolean() nzControl: boolean = false;
@Input() @InputBoolean() nzChecked: boolean = false;
@Input() @InputBoolean() nzNoAnimation: boolean = false;
@Output() readonly nzAfterClose = new EventEmitter<void>();
Expand Down Expand Up @@ -62,7 +63,7 @@ export class NzTagComponent implements OnInit, OnChanges {
}

updateCheckedStatus(): void {
if (this.nzMode === 'checkable') {
if (this.nzMode === 'checkable' && !this.nzControl) {
this.nzChecked = !this.nzChecked;
this.nzCheckedChange.emit(this.nzChecked);
this.updateClassMap();
Expand Down
17 changes: 16 additions & 1 deletion components/tag/nz-tag.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,19 @@ describe('tag', () => {
expect(testComponent.checkedChange).toHaveBeenCalledTimes(1);
expect(tag.nativeElement.classList).toContain('ant-tag-checkable');
expect(tag.nativeElement.classList).toContain('ant-tag-checkable-checked');
testComponent.control = true;
testComponent.checked = true;
fixture.detectChanges();
expect(testComponent.checked).toBe(true);
expect(testComponent.checkedChange).toHaveBeenCalledTimes(1);
expect(tag.nativeElement.classList).toContain('ant-tag-checkable');
expect(tag.nativeElement.classList).toContain('ant-tag-checkable-checked');
testComponent.checked = false;
fixture.detectChanges();
expect(testComponent.checked).toBe(false);
expect(testComponent.checkedChange).toHaveBeenCalledTimes(1);
expect(tag.nativeElement.classList).toContain('ant-tag-checkable');
expect(tag.nativeElement.classList).not.toContain('ant-tag-checkable-checked');
});
it('should closeable work', fakeAsync(() => {
fixture.detectChanges();
Expand Down Expand Up @@ -114,6 +127,7 @@ describe('tag', () => {
[nzMode]="mode"
[(nzChecked)]="checked"
[nzColor]="color"
[nzControl]="control"
(nzCheckedChange)="checkedChange($event)"
(nzAfterClose)="afterClose()"
(nzOnClose)="onClose()"
Expand All @@ -126,6 +140,7 @@ export class NzTestTagBasicComponent {
mode = 'default';
color: string | undefined;
checked = false;
control = false;
onClose = jasmine.createSpy('on close');
afterClose = jasmine.createSpy('after close');
checkedChange = jasmine.createSpy('after close');
Expand All @@ -140,4 +155,4 @@ export class NzTestTagPreventComponent {
onClose(e: MouseEvent): void {
e.preventDefault();
}
}
}