-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
text-field.ts
204 lines (171 loc) · 4.18 KB
/
text-field.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
/* eslint-disable ember/no-mixins */
/* eslint-disable ember/no-classic-classes */
/**
@module @ember/component
*/
import hasDOM from './_has-dom';
import { computed } from '@ember/object';
import Component from '@ember/component';
import { TextSupport } from '../mixins/text-support';
const inputTypes = hasDOM ? Object.create(null) : null;
function canSetTypeOfInput(type: string): boolean {
// if running in outside of a browser always return
// the original type
if (!hasDOM) {
return Boolean(type);
}
if (type in inputTypes) {
return inputTypes[type];
}
let inputTypeTestElement = document.createElement('input');
try {
inputTypeTestElement.type = type;
} catch (e) {
// ignored
}
return (inputTypes[type] = inputTypeTestElement.type === type);
}
/**
The internal class used to create text inputs when the `Input` component is used with `type` of `text`.
See [Ember.Templates.components.Input](/ember/release/classes/Ember.Templates.components/methods/Input?anchor=Input) for usage details.
## Layout and LayoutName properties
Because HTML `input` elements are self closing `layout` and `layoutName`
properties will not be applied.
@class TextField
@extends Component
@uses Ember.TextSupport
@public
*/
const TextField = Component.extend(TextSupport, {
/**
By default, this component will add the `ember-text-field` class to the component's element.
@property classNames
@type Array | String
@default ['ember-text-field']
@public
*/
classNames: ['ember-text-field'],
tagName: 'input',
/**
By default this component will forward a number of arguments to attributes on the the
component's element:
* accept
* autocomplete
* autosave
* dir
* formaction
* formenctype
* formmethod
* formnovalidate
* formtarget
* height
* inputmode
* lang
* list
* type
* max
* min
* multiple
* name
* pattern
* size
* step
* value
* width
When invoked with `{{input type="text"}}`, you can only customize these attributes. When invoked
with `<Input @type="text" />`, you can just use HTML attributes directly.
@property attributeBindings
@type Array | String
@default ['accept', 'autocomplete', 'autosave', 'dir', 'formaction', 'formenctype', 'formmethod', 'formnovalidate', 'formtarget', 'height', 'inputmode', 'lang', 'list', 'type', 'max', 'min', 'multiple', 'name', 'pattern', 'size', 'step', 'value', 'width']
@public
*/
attributeBindings: [
'accept',
'autocomplete',
'autosave',
'dir',
'formaction',
'formenctype',
'formmethod',
'formnovalidate',
'formtarget',
'height',
'inputmode',
'lang',
'list',
'type', // needs to be before min and max. See #15675
'max',
'min',
'multiple',
'name',
'pattern',
'size',
'step',
'value',
'width',
],
/**
As the user inputs text, this property is updated to reflect the `value` property of the HTML
element.
@property value
@type String
@default ""
@public
*/
value: '',
/**
The `type` attribute of the input element.
@property type
@type String
@default "text"
@public
*/
type: computed({
get(): string {
return 'text';
},
set(_key: string, value: string) {
let type = 'text';
if (canSetTypeOfInput(value)) {
type = value;
}
return type;
},
}),
/**
The `size` of the text field in characters.
@property size
@type String
@default null
@public
*/
size: null,
/**
The `pattern` attribute of input element.
@property pattern
@type String
@default null
@public
*/
pattern: null,
/**
The `min` attribute of input element used with `type="number"` or `type="range"`.
@property min
@type String
@default null
@since 1.4.0
@public
*/
min: null,
/**
The `max` attribute of input element used with `type="number"` or `type="range"`.
@property max
@type String
@default null
@since 1.4.0
@public
*/
max: null,
});
TextField.toString = () => '@ember/component/text-field';
export default TextField;