Skip to content

Commit 803782a

Browse files
brandyscarneyadamdbradley
authored andcommitted
feat(input): add max, min, step as inputs and pass to native
closes #10189
1 parent 4ca9f2c commit 803782a

File tree

4 files changed

+84
-2
lines changed

4 files changed

+84
-2
lines changed

src/components/input/input.ts

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,9 @@ export class TextInput extends Ion implements IonicFormInput {
9999
_readonly: boolean = false;
100100
_isTouch: boolean;
101101
_keyboardHeight: number;
102+
_min: any;
103+
_max: any;
104+
_step: any;
102105
_native: NativeInput;
103106
_nav: NavControllerBase;
104107
_scrollStart: any;
@@ -257,6 +260,60 @@ export class TextInput extends Ion implements IonicFormInput {
257260
this._clearOnEdit = isTrueProperty(val);
258261
}
259262

263+
/**
264+
* @input {any} The minimum value, which must not be greater than its maximum (max attribute) value.
265+
*/
266+
@Input()
267+
get min() {
268+
return this._min;
269+
}
270+
set min(val: any) {
271+
this.setMin(this._min = val);
272+
}
273+
274+
/**
275+
* @private
276+
*/
277+
setMin(val: any) {
278+
this._native && this._native.setMin(val);
279+
}
280+
281+
/**
282+
* @input {any} The maximum value, which must not be less than its minimum (min attribute) value.
283+
*/
284+
@Input()
285+
get max() {
286+
return this._max;
287+
}
288+
set max(val: any) {
289+
this.setMax(this._max = val);
290+
}
291+
292+
/**
293+
* @private
294+
*/
295+
setMax(val: any) {
296+
this._native && this._native.setMax(val);
297+
}
298+
299+
/**
300+
* @input {any} Works with the min and max attributes to limit the increments at which a value can be set.
301+
*/
302+
@Input()
303+
get step() {
304+
return this._step;
305+
}
306+
set step(val: any) {
307+
this.setStep(this._step = val);
308+
}
309+
310+
/**
311+
* @private
312+
*/
313+
setStep(val: any) {
314+
this._native && this._native.setStep(val);
315+
}
316+
260317
/**
261318
* @private
262319
*/
@@ -305,6 +362,9 @@ export class TextInput extends Ion implements IonicFormInput {
305362
setNativeInput(nativeInput: NativeInput) {
306363
this._native = nativeInput;
307364
nativeInput.setValue(this._value);
365+
nativeInput.setMin(this._min);
366+
nativeInput.setMax(this._max);
367+
nativeInput.setStep(this._step);
308368
nativeInput.isDisabled(this.disabled);
309369

310370
if (this._item && this._item.labelId !== null) {

src/components/input/native-input.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,18 @@ export class NativeInput {
164164
return this.element().value;
165165
}
166166

167+
setMin(val: any) {
168+
this._elementRef.nativeElement['min'] = val;
169+
}
170+
171+
setMax(val: any) {
172+
this._elementRef.nativeElement['max'] = val;
173+
}
174+
175+
setStep(val: any) {
176+
this._elementRef.nativeElement['step'] = val;
177+
}
178+
167179
setElementClass(cssClass: string, shouldAdd: boolean) {
168180
this._renderer.setElementClass(this._elementRef.nativeElement, cssClass, shouldAdd);
169181
}

src/components/input/test/floating-labels/app.module.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,20 @@ import { IonicApp, IonicModule } from '../../../../../ionic-angular';
77
})
88
export class E2EPage {
99
myParam = '';
10+
minValue = 8;
11+
maxValue = 12;
12+
stepValue = 2;
1013

1114
myValues = {
1215
value1: 'Dynamic Input',
1316
value2: 'Dynamic Textarea'
1417
};
18+
19+
toggleValues() {
20+
this.minValue === 8 ? this.minValue = 4 : this.minValue = 8;
21+
this.maxValue === 12 ? this.maxValue = 20 : this.maxValue = 12;
22+
this.stepValue === 2 ? this.stepValue = 4 : this.stepValue = 2;
23+
}
1524
}
1625

1726
@Component({

src/components/input/test/floating-labels/main.html

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,9 @@
3030
</ion-item>
3131

3232
<ion-item>
33-
<ion-label floating>Enter Number: {{ numberInput.value }} </ion-label>
34-
<ion-input #numberInput type="number"></ion-input>
33+
<ion-label floating>value: {{ numberInput.value }} min: {{ minValue }} max: {{ maxValue }} step: {{ stepValue }} </ion-label>
34+
<ion-input #numberInput [min]="minValue" [max]="maxValue" [step]="stepValue" type="number"></ion-input>
35+
<button item-right outline ion-button (click)="toggleValues()">Toggle</button>
3536
</ion-item>
3637

3738
<ion-item>

0 commit comments

Comments
 (0)