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

fix(module:select): disabled allows to open panel #6008

Merged
merged 1 commit into from
Nov 6, 2020
Merged
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
32 changes: 10 additions & 22 deletions components/select/select-top-control.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,16 +57,6 @@ import { NzSelectItemInterface, NzSelectModeType, NzSelectTopControlItemType } f
</ng-container>
<ng-container *ngSwitchDefault>
<!--multiple or tags mode-->
<nz-select-search
[disabled]="disabled"
[value]="inputValue!"
[autofocus]="autofocus"
[showInput]="true"
[mirrorSync]="true"
[focusTrigger]="open"
(isComposingChange)="isComposingChange($event)"
(valueChange)="onInputValueChange($event)"
></nz-select-search>
<nz-select-item
*ngFor="let item of listOfSlicedItem; trackBy: trackValue"
[@zoomMotion]
Expand All @@ -81,13 +71,22 @@ import { NzSelectItemInterface, NzSelectModeType, NzSelectTopControlItemType } f
(@zoomMotion.done)="onAnimationEnd()"
(delete)="onDeleteItem(item.contentTemplateOutletContext)"
></nz-select-item>
<nz-select-search
[disabled]="disabled"
[value]="inputValue!"
[autofocus]="autofocus"
[showInput]="true"
[mirrorSync]="true"
[focusTrigger]="open"
(isComposingChange)="isComposingChange($event)"
(valueChange)="onInputValueChange($event)"
></nz-select-search>
</ng-container>
</ng-container>
<nz-select-placeholder *ngIf="isShowPlaceholder" [placeholder]="placeHolder"></nz-select-placeholder>
`,
host: {
'[class.ant-select-selector]': 'true',
'(click)': 'onHostClick()',
'(keydown)': 'onHostKeydown($event)'
}
})
Expand All @@ -108,24 +107,13 @@ export class NzSelectTopControlComponent implements OnChanges {
@Output() readonly inputValueChange = new EventEmitter<string>();
@Output() readonly animationEnd = new EventEmitter<void>();
@Output() readonly deleteItem = new EventEmitter<NzSelectItemInterface>();
@Output() readonly openChange = new EventEmitter<boolean>();
@ViewChild(NzSelectSearchComponent) nzSelectSearchComponent!: NzSelectSearchComponent;
listOfSlicedItem: NzSelectTopControlItemType[] = [];
isShowPlaceholder = true;
isShowSingleLabel = false;
isComposing = false;
inputValue: string | null = null;

onHostClick(): void {
if (this.open && this.showSearch) {
return;
}

if (!this.disabled) {
this.openChange.next(!this.open);
}
}

onHostKeydown(e: KeyboardEvent): void {
const inputValue = (e.target as HTMLInputElement).value;
if (e.keyCode === BACKSPACE && this.mode !== 'default' && !inputValue && this.listOfTopItem.length > 0) {
Expand Down
13 changes: 10 additions & 3 deletions components/select/select.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ export type NzSelectSizeType = 'large' | 'default' | 'small';
(animationEnd)="updateCdkConnectedOverlayPositions()"
(deleteItem)="onItemDelete($event)"
(keydown)="onKeyDown($event)"
(openChange)="setOpenState($event)"
></nz-select-top-control>
<nz-select-clear
*ngIf="nzAllowClear && !nzDisabled && listOfValue.length"
Expand All @@ -104,7 +103,6 @@ export type NzSelectSizeType = 'large' | 'default' | 'small';
[loading]="nzLoading"
[search]="nzOpen && nzShowSearch"
[suffixIcon]="nzSuffixIcon"
(click)="setOpenState(!nzOpen)"
></nz-select-arrow>
<ng-template
cdkConnectedOverlay
Expand Down Expand Up @@ -156,7 +154,8 @@ export type NzSelectSizeType = 'large' | 'default' | 'small';
'[class.ant-select-open]': 'nzOpen',
'[class.ant-select-focused]': 'nzOpen || focused',
'[class.ant-select-single]': `nzMode === 'default'`,
'[class.ant-select-multiple]': `nzMode !== 'default'`
'[class.ant-select-multiple]': `nzMode !== 'default'`,
'(click)': 'onHostClick()'
}
})
export class NzSelectComponent implements ControlValueAccessor, OnInit, AfterViewInit, OnDestroy, AfterContentInit, OnChanges {
Expand Down Expand Up @@ -281,6 +280,14 @@ export class NzSelectComponent implements ControlValueAccessor, OnInit, AfterVie
this.clearInput();
}

onHostClick(): void {
if ((this.nzOpen && this.nzShowSearch) || this.nzDisabled) {
return;
}

this.setOpenState(!this.nzOpen);
}

updateListOfContainerItem(): void {
let listOfContainerItem = this.listOfTagAndTemplateItem
.filter(item => !item.nzHide)
Expand Down