Skip to content

Commit fe99d19

Browse files
committed
feat(textarea): add textarea and interfaces for both inputs
1 parent 487948e commit fe99d19

File tree

6 files changed

+569
-209
lines changed

6 files changed

+569
-209
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
// Shared Interfaces
2+
3+
import { EventEmitter } from '@stencil/core';
4+
5+
export interface InputBaseComponent {
6+
ionStyle: EventEmitter;
7+
ionBlur: EventEmitter;
8+
ionFocus: EventEmitter;
9+
10+
clearOnEdit: boolean;
11+
didBlurAfterEdit: boolean;
12+
styleTmr: number;
13+
14+
// Shared Attributes
15+
autocapitalize: string;
16+
autocomplete: string;
17+
autofocus: boolean;
18+
disabled: boolean;
19+
minlength: number;
20+
maxlength: number;
21+
name: string;
22+
placeholder: string;
23+
readonly: boolean;
24+
required: boolean;
25+
spellcheck: boolean;
26+
value: string;
27+
28+
// Shared Methods
29+
inputBlurred: (ev: any) => void;
30+
inputChanged: (ev: any) => void;
31+
inputFocused: (ev: any) => void;
32+
inputKeydown: (ev: any) => void;
33+
}
34+
35+
export interface InputComponent extends InputBaseComponent {
36+
clearInput: boolean;
37+
38+
// Input Attributes
39+
accept: string;
40+
autocorrect: string;
41+
inputmode: string;
42+
min: string;
43+
max: string;
44+
multiple: boolean;
45+
pattern: string;
46+
results: number;
47+
step: string;
48+
size: number;
49+
type: string;
50+
}
51+
52+
export interface TextareaComponent extends InputBaseComponent {
53+
54+
// Textarea Attributes
55+
cols: number;
56+
rows: number;
57+
wrap: string;
58+
}

packages/core/src/components/input/input.tsx

+95-36
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { Component, Element, Event, EventEmitter, Prop, PropDidChange } from '@s
22

33
import { createThemedClasses } from '../../utils/theme';
44

5+
import { InputComponent } from './input-base';
56

67
@Component({
78
tag: 'ion-input',
@@ -14,11 +15,12 @@ import { createThemedClasses } from '../../utils/theme';
1415
theme: 'input'
1516
}
1617
})
17-
export class Input {
18-
mode: any;
19-
color: any;
20-
styleTmr: any;
18+
export class Input implements InputComponent {
19+
mode: string;
20+
color: string;
21+
2122
didBlurAfterEdit: boolean;
23+
styleTmr: number;
2224

2325
@Element() el: HTMLElement;
2426

@@ -37,6 +39,16 @@ export class Input {
3739
*/
3840
@Event() ionFocus: EventEmitter;
3941

42+
/**
43+
* @input {string} If the value of the type attribute is `"file"`, then this attribute will indicate the types of files that the server accepts, otherwise it will be ignored. The value must be a comma-separated list of unique content type specifiers.
44+
*/
45+
@Prop() accept: string;
46+
47+
/**
48+
* @input {string} Indicates whether and how the text value should be automatically capitalized as it is entered/edited by the user. Defaults to `"none"`.
49+
*/
50+
@Prop() autocapitalize: string = 'none';
51+
4052
/**
4153
* @input {string} Indicates whether the value of the control can be automatically completed by the browser. Defaults to `"off"`.
4254
*/
@@ -50,7 +62,7 @@ export class Input {
5062
/**
5163
* @input {string} This Boolean attribute lets you specify that a form control should have input focus when the page loads. Defaults to `false`.
5264
*/
53-
@Prop() autofocus: boolean;
65+
@Prop() autofocus: boolean = false;
5466

5567
/**
5668
* @input {boolean} If true and the type is `checkbox` or `radio`, the control is selected by default. Defaults to `false`.
@@ -72,9 +84,9 @@ export class Input {
7284
@Prop() clearInput: boolean = false;
7385

7486
/**
75-
* @input {boolean} If true, the value will be cleared after focus upon edit. Defaults to `true` when `type` is `"password"`, `false` for all other types. Defaults to `false`.
87+
* @input {boolean} If true, the value will be cleared after focus upon edit. Defaults to `true` when `type` is `"password"`, `false` for all other types.
7688
*/
77-
@Prop({state: true}) clearOnEdit: boolean;
89+
@Prop({ state: true }) clearOnEdit: boolean;
7890

7991
/**
8092
* @input {boolean} If true, the user cannot interact with this element. Defaults to `false`.
@@ -90,15 +102,45 @@ export class Input {
90102
}
91103

92104
/**
93-
* @input {any} The minimum value, which must not be greater than its maximum (max attribute) value.
105+
* @input {string} A hint to the browser for which keyboard to display. This attribute applies when the value of the type attribute is `"text"`, `"password"`, `"email"`, or `"url"`. Possible values are: `"verbatim"`, `"latin"`, `"latin-name"`, `"latin-prose"`, `"full-width-latin"`, `"kana"`, `"katakana"`, `"numeric"`, `"tel"`, `"email"`, `"url"`.
94106
*/
95-
@Prop() min: string;
107+
@Prop() inputmode: string;
96108

97109
/**
98-
* @input {any} The maximum value, which must not be less than its minimum (min attribute) value.
110+
* @input {string} The maximum value, which must not be less than its minimum (min attribute) value.
99111
*/
100112
@Prop() max: string;
101113

114+
/**
115+
* @input {number} If the value of the type attribute is `text`, `email`, `search`, `password`, `tel`, or `url`, this attribute specifies the maximum number of characters that the user can enter.
116+
*/
117+
@Prop() maxlength: number;
118+
119+
/**
120+
* @input {string} The minimum value, which must not be greater than its maximum (max attribute) value.
121+
*/
122+
@Prop() min: string;
123+
124+
/**
125+
* @input {number} If the value of the type attribute is `text`, `email`, `search`, `password`, `tel`, or `url`, this attribute specifies the minimum number of characters that the user can enter.
126+
*/
127+
@Prop() minlength: number;
128+
129+
/**
130+
* @input {boolean} If true, the user can enter more than one value. This attribute applies when the type attribute is set to `"email"` or `"file"`, otherwise it is ignored.
131+
*/
132+
@Prop() multiple: boolean;
133+
134+
/**
135+
* @input {string} The name of the control, which is submitted with the form data.
136+
*/
137+
@Prop() name: string;
138+
139+
/**
140+
* @input {string} A regular expression that the value is checked against. The pattern must match the entire value, not just some subset. Use the title attribute to describe the pattern to help the user. This attribute applies when the value of the type attribute is `"text"`, `"search"`, `"tel"`, `"url"`, `"email"`, or `"password"`, otherwise it is ignored.
141+
*/
142+
@Prop() pattern: string;
143+
102144
/**
103145
* @input {string} Instructional text that shows before the input has a value.
104146
*/
@@ -109,16 +151,31 @@ export class Input {
109151
*/
110152
@Prop() readonly: boolean = false;
111153

154+
/**
155+
* @input {boolean} If true, the user must fill in a value before submitting a form.
156+
*/
157+
@Prop() required: boolean = false;
158+
159+
/**
160+
* @input {number} This is a nonstandard attribute supported by Safari that only applies when the type is `"search"`. Its value should be a nonnegative decimal integer.
161+
*/
162+
@Prop() results: number;
163+
112164
/**
113165
* @input {string} If true, the element will have its spelling and grammar checked. Defaults to `false`.
114166
*/
115167
@Prop() spellcheck: boolean = false;
116168

117169
/**
118-
* @input {any} Works with the min and max attributes to limit the increments at which a value can be set.
170+
* @input {string} Works with the min and max attributes to limit the increments at which a value can be set. Possible values are: `"any"` or a positive floating point number.
119171
*/
120172
@Prop() step: string;
121173

174+
/**
175+
* @input {number} The initial size of the control. This value is in pixels unless the value of the type attribute is `"text"` or `"password"`, in which case it is an integer number of characters. This attribute applies only when the `type` attribute is set to `"text"`, `"search"`, `"tel"`, `"url"`, `"email"`, or `"password"`, otherwise it is ignored.
176+
*/
177+
@Prop() size: number;
178+
122179
/**
123180
* @input {string} The type of control to display. The default type is text. Possible values are: `"text"`, `"password"`, `"email"`, `"number"`, `"search"`, `"tel"`, or `"url"`.
124181
*/
@@ -129,7 +186,6 @@ export class Input {
129186
*/
130187
@Prop({ state: true }) value: string;
131188

132-
133189
ionViewDidLoad() {
134190
this.emitStyle();
135191

@@ -155,13 +211,6 @@ export class Input {
155211
});
156212
}
157213

158-
/**
159-
* @hidden
160-
*/
161-
hasValue(): boolean {
162-
return (this.value !== null && this.value !== undefined && this.value !== '');
163-
}
164-
165214

166215
/**
167216
* @hidden
@@ -194,15 +243,6 @@ export class Input {
194243
}
195244

196245

197-
/**
198-
* @hidden
199-
*/
200-
hasFocus(): boolean {
201-
// check if an input has focus or not
202-
return this.el && (this.el.querySelector(':focus') === this.el.querySelector('input'));
203-
}
204-
205-
206246
/**
207247
* @hidden
208248
*/
@@ -241,7 +281,6 @@ export class Input {
241281
this.didBlurAfterEdit = false;
242282
}
243283

244-
245284
/**
246285
* @hidden
247286
*/
@@ -250,32 +289,52 @@ export class Input {
250289
this.value = '';
251290
}
252291

292+
/**
293+
* @hidden
294+
*/
295+
hasFocus(): boolean {
296+
// check if an input has focus or not
297+
return this.el && (this.el.querySelector(':focus') === this.el.querySelector('input'));
298+
}
299+
300+
301+
/**
302+
* @hidden
303+
*/
304+
hasValue(): boolean {
305+
return (this.value !== null && this.value !== undefined && this.value !== '');
306+
}
307+
253308

254309
render() {
255310
const themedClasses = createThemedClasses(this.mode, this.color, 'text-input');
256311
// TODO aria-labelledby={this.item.labelId}
257312

258-
// OLD RENDER
259-
// '<input [(ngModel)]="_value" [type]="type" (blur)="inputBlurred($event)" (focus)="inputFocused($event)" [placeholder]="placeholder" [disabled]="disabled" [readonly]="readonly" class="text-input" [ngClass]="\'text-input-\' + _mode" *ngIf="_type!==\'textarea\'" #input>' +
260-
// '<textarea [(ngModel)]="_value" (blur)="inputBlurred($event)" (focus)="inputFocused($event)" [placeholder]="placeholder" [disabled]="disabled" [readonly]="readonly" class="text-input" [ngClass]="\'text-input-\' + _mode" *ngIf="_type===\'textarea\'" #textarea></textarea>' +
261-
// '<input [type]="type" aria-hidden="true" next-input *ngIf="_useAssist">' +
262-
// '<ion-button clear [hidden]="!clearInput" type="button" class="text-input-clear-icon" (click)="clearTextInput()" (mousedown)="clearTextInput()"></ion-button>' +
263-
// '<div (touchstart)="pointerStart($event)" (touchend)="pointerEnd($event)" (mousedown)="pointerStart($event)" (mouseup)="pointerEnd($event)" class="input-cover" tappable *ngIf="_useAssist"></div>',
264-
265313
return (
266314
<input
267315
aria-disabled={this.disabled ? 'true' : false}
316+
accept={this.accept}
317+
autoCapitalize={this.autocapitalize}
268318
autoComplete={this.autocomplete}
269319
autoCorrect={this.autocorrect}
270320
autoFocus={this.autofocus}
271321
checked={this.checked}
272322
disabled={this.disabled}
323+
inputMode={this.inputmode}
273324
min={this.min}
274325
max={this.max}
326+
minLength={this.minlength}
327+
maxLength={this.maxlength}
328+
multiple={this.multiple}
329+
name={this.name}
330+
pattern={this.pattern}
275331
placeholder={this.placeholder}
332+
results={this.results}
276333
readOnly={this.readonly}
334+
required={this.required}
277335
spellCheck={this.spellcheck}
278336
step={this.step}
337+
size={this.size}
279338
type={this.type}
280339
value={this.value}
281340
class={themedClasses}

0 commit comments

Comments
 (0)