Skip to content

Commit 0f3aed5

Browse files
authored
feat(module:input): hide stepper for type number (#8003)
* feat(module:input): hide stepper for type number * refactor(module:input): stepperless set to true by default * refactor(module:input): move css to patch file
1 parent 71b4f1e commit 0f3aed5

7 files changed

Lines changed: 31 additions & 11 deletions

File tree

‎components/affix/affix.spec.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { BidiModule, Dir } from '@angular/cdk/bidi';
22
import { Component, DebugElement, ViewChild } from '@angular/core';
3-
import { ComponentFixture, discardPeriodicTasks, fakeAsync, TestBed, tick, waitForAsync } from '@angular/core/testing';
3+
import { ComponentFixture, TestBed, discardPeriodicTasks, fakeAsync, tick, waitForAsync } from '@angular/core/testing';
44
import { By } from '@angular/platform-browser';
55

66
import { NzScrollService } from 'ng-zorro-antd/core/services';

‎components/input/demo/basic.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { Component } from '@angular/core';
33
@Component({
44
selector: 'nz-demo-input-basic',
55
template: `
6-
<input nz-input placeholder="Basic usage" [(ngModel)]="value" />
6+
<input nz-input placeholder="Basic usage" [(ngModel)]="value" type="number" />
77
<br />
88
<br />
99
<input nz-input placeholder="Basic usage" [(ngModel)]="value" [disabled]="true" />

‎components/input/doc/index.en-US.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ All props of input supported by [w3c standards](https://www.w3schools.com/tags/t
2929
| `[nzAutosize]` | Only used for `textarea`, height autosize feature, can be set to `boolean` or an object `{ minRows: 2, maxRows: 6 }` | `boolean \| { minRows: number, maxRows: number }` | `false` |
3030
| `[nzBorderless]` | Whether hide border | `boolean` | `false` |
3131
| `[nzStatus]` | Set validation status | `'error' \| 'warning'` | - |
32+
| `[nzStepperless]` | Whether hide stepper when input type is number | `'boolean' \| 'true'` | - |
3233

3334
### nz-input-group
3435

‎components/input/input.directive.ts‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import { distinctUntilChanged, filter, takeUntil } from 'rxjs/operators';
2424

2525
import { NzFormItemFeedbackIconComponent, NzFormNoStatusService, NzFormStatusService } from 'ng-zorro-antd/core/form';
2626
import { BooleanInput, NgClassInterface, NzSizeLDSType, NzStatus, NzValidateStatus } from 'ng-zorro-antd/core/types';
27-
import { getStatusClassNames, InputBoolean } from 'ng-zorro-antd/core/util';
27+
import { InputBoolean, getStatusClassNames } from 'ng-zorro-antd/core/util';
2828

2929
@Directive({
3030
selector: 'input[nz-input],textarea[nz-input]',
@@ -36,14 +36,16 @@ import { getStatusClassNames, InputBoolean } from 'ng-zorro-antd/core/util';
3636
'[class.ant-input-lg]': `nzSize === 'large'`,
3737
'[class.ant-input-sm]': `nzSize === 'small'`,
3838
'[attr.disabled]': 'disabled || null',
39-
'[class.ant-input-rtl]': `dir=== 'rtl'`
39+
'[class.ant-input-rtl]': `dir=== 'rtl'`,
40+
'[class.ant-input-stepperless]': `nzStepperless`
4041
}
4142
})
4243
export class NzInputDirective implements OnChanges, OnInit, OnDestroy {
4344
static ngAcceptInputType_disabled: BooleanInput;
4445
static ngAcceptInputType_nzBorderless: BooleanInput;
4546
@Input() @InputBoolean() nzBorderless = false;
4647
@Input() nzSize: NzSizeLDSType = 'default';
48+
@Input() @InputBoolean() nzStepperless: boolean = true;
4749
@Input() nzStatus: NzStatus = '';
4850
@Input()
4951
get disabled(): boolean {

‎components/input/input.spec.ts‎

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { BidiModule, Direction } from '@angular/cdk/bidi';
22
import { Component, DebugElement } from '@angular/core';
3-
import { ComponentFixture, fakeAsync, flush, TestBed, waitForAsync } from '@angular/core/testing';
4-
import { UntypedFormBuilder, UntypedFormGroup, FormsModule, ReactiveFormsModule } from '@angular/forms';
3+
import { ComponentFixture, TestBed, fakeAsync, flush, waitForAsync } from '@angular/core/testing';
4+
import { FormsModule, ReactiveFormsModule, UntypedFormBuilder, UntypedFormGroup } from '@angular/forms';
55
import { By } from '@angular/platform-browser';
66

77
import { NzStatus } from 'ng-zorro-antd/core/types';
@@ -62,6 +62,13 @@ describe('input', () => {
6262
expect(inputElement.nativeElement.classList).toContain('ant-input');
6363
expect(inputElement.nativeElement.classList).toContain('ant-input-lg');
6464
});
65+
it('should nzStepperLess work', () => {
66+
fixture.detectChanges();
67+
expect(inputElement.nativeElement.classList).toContain('ant-input-stepperless');
68+
testComponent.stepperless = false;
69+
fixture.detectChanges();
70+
expect(inputElement.nativeElement.classList).not.toContain('ant-input-stepperless');
71+
});
6572
});
6673

6774
describe('input with textarea element', () => {
@@ -204,11 +211,12 @@ export class NzTestInputWithDirComponent {
204211
}
205212

206213
@Component({
207-
template: ` <input nz-input [nzSize]="size" [disabled]="disabled" /> `
214+
template: ` <input nz-input [nzSize]="size" [disabled]="disabled" [nzStepperless]="stepperless" /> `
208215
})
209216
export class NzTestInputWithInputComponent {
210217
size = 'default';
211218
disabled = false;
219+
stepperless = true;
212220
}
213221

214222
@Component({

‎components/input/style/mixin.less‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@
2323
border-color: @hoverBorderColor;
2424
}
2525
& when not (@theme = variable) {
26-
box-shadow: @input-outline-offset @outline-blur-size @outline-width
27-
fade(@borderColor, @outline-fade);
26+
box-shadow: @input-outline-offset @outline-blur-size @outline-width fade(@borderColor, @outline-fade);
2827
}
2928
& when (@theme = variable) {
3029
border-color: @hoverBorderColor;
@@ -200,8 +199,7 @@
200199
.@{ant-prefix}-select {
201200
margin: -(@input-padding-vertical-base + 1px) (-@input-padding-horizontal-base);
202201

203-
&.@{ant-prefix}-select-single:not(.@{ant-prefix}-select-customize-input)
204-
.@{ant-prefix}-select-selector {
202+
&.@{ant-prefix}-select-single:not(.@{ant-prefix}-select-customize-input) .@{ant-prefix}-select-selector {
205203
background-color: inherit;
206204
border: @border-width-base @border-style-base transparent;
207205
box-shadow: none;

‎components/input/style/patch.less‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,3 +62,14 @@ nz-form-item-feedback-icon.@{ant-prefix}-input {
6262
position: relative;
6363
}
6464

65+
.input() {
66+
&-stepperless[type='number'] {
67+
-moz-appearance: textfield;
68+
&::-webkit-inner-spin-button,
69+
::-webkit-outer-spin-button {
70+
-webkit-appearance: none;
71+
margin: 0;
72+
}
73+
}
74+
}
75+

0 commit comments

Comments
 (0)