Skip to content

Commit dcf8a5d

Browse files
authored
fix(module:select): disable nzMaxMultipleCount in default mode (#9068)
1 parent e70cae3 commit dcf8a5d

4 files changed

Lines changed: 29 additions & 13 deletions

File tree

components/core/util/convert.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ export function numberAttributeWithOneFallback(value: unknown): number {
2121
return numberAttribute(value, 1);
2222
}
2323

24+
export function numberAttributeWithInfinityFallback(value: unknown): number {
25+
return numberAttribute(value, Infinity);
26+
}
27+
2428
export function toNumber(value: number | string): number;
2529
export function toNumber<D>(value: number | string, fallback: D): number | D;
2630
export function toNumber(value: number | string, fallbackValue: number = 0): number {

components/select/select-arrow.component.ts

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,16 @@
33
* found in the LICENSE file at https://github.com/NG-ZORRO/ng-zorro-antd/blob/master/LICENSE
44
*/
55

6-
import {
7-
ChangeDetectionStrategy,
8-
Component,
9-
Input,
10-
TemplateRef,
11-
ViewEncapsulation,
12-
numberAttribute
13-
} from '@angular/core';
6+
import { ChangeDetectionStrategy, Component, Input, TemplateRef, ViewEncapsulation } from '@angular/core';
147

158
import { NzOutletModule } from 'ng-zorro-antd/core/outlet';
169
import { NzSafeAny } from 'ng-zorro-antd/core/types';
10+
import { numberAttributeWithInfinityFallback } from 'ng-zorro-antd/core/util';
1711
import { NzIconModule } from 'ng-zorro-antd/icon';
1812

13+
/**
14+
* @internal
15+
*/
1916
@Component({
2017
selector: 'nz-select-arrow',
2118
encapsulation: ViewEncapsulation.None,
@@ -57,5 +54,5 @@ export class NzSelectArrowComponent {
5754
@Input() isMaxMultipleCountSet = false;
5855
@Input() suffixIcon: TemplateRef<NzSafeAny> | string | null = null;
5956
@Input() feedbackIcon: TemplateRef<NzSafeAny> | string | null = null;
60-
@Input({ transform: numberAttribute }) nzMaxMultipleCount: number = Infinity;
57+
@Input({ transform: numberAttributeWithInfinityFallback }) nzMaxMultipleCount = Infinity;
6158
}

components/select/select.component.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,12 @@ import {
5959
OnChangeType,
6060
OnTouchedType
6161
} from 'ng-zorro-antd/core/types';
62-
import { fromEventOutsideAngular, getStatusClassNames, isNotNil } from 'ng-zorro-antd/core/util';
62+
import {
63+
fromEventOutsideAngular,
64+
getStatusClassNames,
65+
isNotNil,
66+
numberAttributeWithInfinityFallback
67+
} from 'ng-zorro-antd/core/util';
6368
import { NZ_SPACE_COMPACT_ITEM_TYPE, NZ_SPACE_COMPACT_SIZE, NzSpaceCompactItemDirective } from 'ng-zorro-antd/space';
6469

6570
import { NzOptionContainerComponent } from './option-container.component';
@@ -246,7 +251,7 @@ export class NzSelectComponent implements ControlValueAccessor, OnInit, AfterCon
246251
@Input() nzMenuItemSelectedIcon: TemplateRef<NzSafeAny> | null = null;
247252
@Input() nzTokenSeparators: string[] = [];
248253
@Input() nzMaxTagPlaceholder: TemplateRef<{ $implicit: NzSafeAny[] }> | null = null;
249-
@Input() nzMaxMultipleCount = Infinity;
254+
@Input({ transform: numberAttributeWithInfinityFallback }) nzMaxMultipleCount = Infinity;
250255
@Input() nzMode: NzSelectModeType = 'default';
251256
@Input() nzFilterOption: NzFilterOptionType = defaultFilterOption;
252257
@Input() compareWith: (o1: NzSafeAny, o2: NzSafeAny) => boolean = (o1: NzSafeAny, o2: NzSafeAny) => o1 === o2;
@@ -271,8 +276,12 @@ export class NzSelectComponent implements ControlValueAccessor, OnInit, AfterCon
271276
return this._nzShowArrow === undefined ? this.nzMode === 'default' : this._nzShowArrow;
272277
}
273278

279+
get isMultiple(): boolean {
280+
return this.nzMode === 'multiple' || this.nzMode === 'tags';
281+
}
282+
274283
get isMaxMultipleCountSet(): boolean {
275-
return this.nzMaxMultipleCount !== Infinity;
284+
return this.isMultiple && this.nzMaxMultipleCount !== Infinity;
276285
}
277286

278287
get isMaxMultipleCountReached(): boolean {

components/select/select.spec.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import { NzSelectModule } from './select.module';
2323
import {
2424
NzFilterOptionType,
2525
NzSelectItemInterface,
26+
NzSelectModeType,
2627
NzSelectOptionInterface,
2728
NzSelectPlacementType
2829
} from './select.types';
@@ -1342,6 +1343,10 @@ describe('select', () => {
13421343
component.nzMaxMultipleCount = 1;
13431344
fixture.detectChanges();
13441345
expect(selectComponent.isMaxMultipleCountSet).toBeTruthy();
1346+
1347+
component.nzMode = 'default';
1348+
fixture.detectChanges();
1349+
expect(selectComponent.isMaxMultipleCountSet).toBeFalsy();
13451350
});
13461351

13471352
it('should isMaxMultipleCountReached be set correctly when click options', fakeAsync(() => {
@@ -1975,7 +1980,7 @@ export class TestSelectReactiveDefaultComponent {
19751980
imports: [FormsModule, NzSelectModule],
19761981
template: `
19771982
<nz-select
1978-
nzMode="multiple"
1983+
[nzMode]="nzMode"
19791984
[(ngModel)]="value"
19801985
[nzOptions]="listOfOption"
19811986
[nzMenuItemSelectedIcon]="nzMenuItemSelectedIcon"
@@ -2002,6 +2007,7 @@ export class TestSelectReactiveMultipleComponent {
20022007
nzRemoveIcon: TemplateRef<NzSafeAny> | null = null;
20032008
nzTokenSeparators: string[] = [];
20042009
nzMaxMultipleCount = Infinity;
2010+
nzMode: NzSelectModeType = 'multiple';
20052011
compareWith: (o1: NzSafeAny, o2: NzSafeAny) => boolean = (o1: NzSafeAny, o2: NzSafeAny) => o1 === o2;
20062012
nzAutoClearSearchValue = true;
20072013
}

0 commit comments

Comments
 (0)