Skip to content

Commit

Permalink
feat(module:autocomplete): support bind any types to the nzModule of …
Browse files Browse the repository at this point in the history
…trigger element (NG-ZORRO#1397)

close NG-ZORRO#1298
  • Loading branch information
hsuanxyz authored and vthinkxie committed May 24, 2018
1 parent 46bd235 commit fc9d50d
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 6 deletions.
4 changes: 2 additions & 2 deletions components/auto-complete/demo/certain-category.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { ChangeDetectionStrategy, Component, OnInit, ViewEncapsulation } from '@
<a class="more-link" href="https://www.google.com/search?q=ng+zorro" target="_blank">更多</a>
</span>
</ng-template>
<nz-auto-option *ngFor="let option of group.children" [nzValue]="option.title">
<nz-auto-option *ngFor="let option of group.children" [nzLabel]="option.title" [nzValue]="option">
{{option.title}}
<span class="certain-search-item-count">{{option.count}} 人 关注</span>
</nz-auto-option>
Expand All @@ -43,7 +43,7 @@ export class NzDemoAutoCompleteCertainCategoryComponent implements OnInit {
inputValue: string;
optionGroups: any[];

onChange(value: string): void {
onChange(value: any): void {
console.log(value);
}

Expand Down
7 changes: 7 additions & 0 deletions components/auto-complete/doc/index.en-US.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,10 @@ When there is a need for autocomplete functionality.
| nzDefaultActiveFirstOption | Whether active first option by default | `boolean` | `true` |
| nzWidth | Custom width, unit px | `number` | trigger element width |

### nz-auto-option

| Property | Description | Type | Default |
| --- | --- | --- | --- |
| nzValue | bind ngModel of the trigger element | `any` | - |
| nzLabel | display value of the trigger element | `string` | - |
| nzDisabled | disabled option | `boolean` | `false` |
7 changes: 7 additions & 0 deletions components/auto-complete/doc/index.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,10 @@ subtitle: 自动完成
| nzDefaultActiveFirstOption | 是否默认高亮第一个选项。 | `boolean` | `true` |
| nzWidth | 自定义宽度单位 px | `number` | 触发元素宽度 |

### nz-auto-option

| 属性 | 说明 | 类型 | 默认值 |
| --- | --- | --- | --- |
| nzValue | 绑定到触发元素 ngModel 的值 | `any` | - |
| nzLabel | 填入触发元素显示的值 | `string` | - |
| nzDisabled | 禁用选项 | `boolean` | `false` |
3 changes: 2 additions & 1 deletion components/auto-complete/nz-autocomplete-option.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ export class NzAutocompleteOptionComponent {
active = false;
selected = false;

@Input() nzValue: {};
/* tslint:disable-next-line:no-any */
@Input() nzValue: any;
@Input() nzLabel: string;

@Input()
Expand Down
4 changes: 2 additions & 2 deletions components/auto-complete/nz-autocomplete-trigger.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -265,8 +265,8 @@ export class NzAutocompleteTriggerDirective implements ControlValueAccessor, OnD
}

private setValueAndClose(option: NzAutocompleteOptionComponent): void {
const value = option.getLabel();
this.setTriggerValue(value);
const value = option.nzValue;
this.setTriggerValue(option.getLabel());
this._onChange(value);
this._element.nativeElement.focus();
this.closePanel();
Expand Down
2 changes: 1 addition & 1 deletion components/auto-complete/nz-autocomplete.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ export class NzAutocompleteComponent implements AfterViewInit {
@ViewChildren(NzAutocompleteOptionComponent) fromDataSourceOptions: QueryList<NzAutocompleteOptionComponent>;

/** 自定义宽度单位 px */
@Input() nzWidth: number | void;
@Input() nzWidth: number;

/** 是否默认高亮第一个选项,默认 `true` */
@Input()
Expand Down

0 comments on commit fc9d50d

Please sign in to comment.