11
11
/>
12
12
<input
13
13
v-if =" type === 'email'"
14
- v-model =" currentValue"
14
+ :id =" id"
15
+ v-model =" valueCopy"
16
+ type =" email"
17
+ class =" material-input"
15
18
:name =" name"
16
- :placeholder =" fillPlaceHolder "
19
+ :placeholder =" filledPlaceholder "
17
20
:readonly =" readonly"
18
21
:disabled =" disabled"
19
22
:autocomplete =" autoComplete"
20
23
:required =" required"
21
- type =" email"
22
- class =" material-input"
23
24
@focus =" handleFocus"
24
25
@blur =" handleBlur"
25
26
@input =" handleInput"
26
27
>
27
28
<input
28
29
v-if =" type === 'url'"
29
- v-model =" currentValue"
30
+ :id =" id"
31
+ v-model =" valueCopy"
32
+ type =" url"
33
+ class =" material-input"
30
34
:name =" name"
31
- :placeholder =" fillPlaceHolder "
35
+ :placeholder =" filledPlaceholder "
32
36
:readonly =" readonly"
33
37
:disabled =" disabled"
34
38
:autocomplete =" autoComplete"
35
39
:required =" required"
36
- type =" url"
37
- class =" material-input"
38
40
@focus =" handleFocus"
39
41
@blur =" handleBlur"
40
42
@input =" handleInput"
41
43
>
42
44
<input
43
45
v-if =" type === 'number'"
44
- v-model =" currentValue"
46
+ :id =" id"
47
+ v-model =" valueCopy"
48
+ type =" number"
49
+ class =" material-input"
45
50
:name =" name"
46
- :placeholder =" fillPlaceHolder"
47
- :step =" step"
51
+ :placeholder =" filledPlaceholder"
48
52
:readonly =" readonly"
49
53
:disabled =" disabled"
50
54
:autocomplete =" autoComplete"
51
55
:max =" max"
52
56
:min =" min"
57
+ :step =" step"
53
58
:minlength =" minlength"
54
59
:maxlength =" maxlength"
55
60
:required =" required"
56
- type =" number"
57
- class =" material-input"
58
61
@focus =" handleFocus"
59
62
@blur =" handleBlur"
60
63
@input =" handleInput"
61
64
>
62
65
<input
63
66
v-if =" type === 'password'"
64
- v-model =" currentValue"
67
+ :id =" id"
68
+ v-model =" valueCopy"
69
+ type =" password"
70
+ class =" material-input"
65
71
:name =" name"
66
- :placeholder =" fillPlaceHolder "
72
+ :placeholder =" filledPlaceholder "
67
73
:readonly =" readonly"
68
74
:disabled =" disabled"
69
75
:autocomplete =" autoComplete"
70
76
:max =" max"
71
77
:min =" min"
78
+ :step =" step"
72
79
:required =" required"
73
- type =" password"
74
- class =" material-input"
75
80
@focus =" handleFocus"
76
81
@blur =" handleBlur"
77
82
@input =" handleInput"
78
83
>
79
84
<input
80
85
v-if =" type === 'tel'"
81
- v-model =" currentValue"
86
+ :id =" id"
87
+ v-model =" valueCopy"
88
+ type =" tel"
89
+ class =" material-input"
82
90
:name =" name"
83
- :placeholder =" fillPlaceHolder "
91
+ :placeholder =" filledPlaceholder "
84
92
:readonly =" readonly"
85
93
:disabled =" disabled"
86
94
:autocomplete =" autoComplete"
87
95
:required =" required"
88
- type =" tel"
89
- class =" material-input"
90
96
@focus =" handleFocus"
91
97
@blur =" handleBlur"
92
98
@input =" handleInput"
93
99
>
94
100
<input
95
101
v-if =" type === 'text'"
96
- v-model =" currentValue"
102
+ :id =" id"
103
+ v-model =" valueCopy"
104
+ type =" text"
105
+ class =" material-input"
97
106
:name =" name"
98
- :placeholder =" fillPlaceHolder "
107
+ :placeholder =" filledPlaceholder "
99
108
:readonly =" readonly"
100
109
:disabled =" disabled"
101
110
:autocomplete =" autoComplete"
102
111
:minlength =" minlength"
103
112
:maxlength =" maxlength"
104
113
:required =" required"
105
- type =" text"
106
- class =" material-input"
107
114
@focus =" handleFocus"
108
115
@blur =" handleBlur"
109
116
@input =" handleInput"
@@ -124,37 +131,44 @@ import { Component, Prop, Vue, Watch } from 'vue-property-decorator'
124
131
name: ' MaterialInput'
125
132
})
126
133
export default class extends Vue {
134
+ @Prop ({ required: true }) private value! : any
135
+ @Prop ({ default: ' text' }) private type! : string
136
+ @Prop ({ default: ' ' }) private id! : string
127
137
@Prop ({ default: ' ' }) private icon! : string
128
138
@Prop ({ default: ' ' }) private name! : string
129
- @Prop ({ default: ' text' }) private type! : string
130
- @Prop ({ default : () => [] }) private value! : (string | number )[]
131
- @Prop ({ default: null }) private placeholder! : string | null
139
+ @Prop ({ default: ' ' }) private placeholder! : string
132
140
@Prop ({ default: false }) private readonly! : boolean
133
141
@Prop ({ default: false }) private disabled! : boolean
134
- @Prop ({ default: ' ' }) private min! : string
135
- @Prop ({ default: ' ' }) private max! : string
136
- @Prop ({ default: ' ' }) private step! : string
137
- @Prop ({ default: 0 }) private minlength! : number
138
- @Prop ({ default: 0 }) private maxlength! : number
139
142
@Prop ({ default: true }) private required! : boolean
140
143
@Prop ({ default: ' off' }) private autoComplete! : string
144
+ @Prop ({ default: 0 }) private min! : number | Date
145
+ @Prop ({ default: 10000 }) private max! : number | Date
146
+ @Prop ({ default: 1 }) private step! : number
147
+ @Prop ({ default: 0 }) private minlength! : number
148
+ @Prop ({ default: 20 }) private maxlength! : number
141
149
@Prop ({ default: true }) private validateEvent! : boolean
142
150
143
- private currentValue = this .value
151
+ private valueCopy = this .value
144
152
private focus = false
145
- private fillPlaceHolder: string | null = null
153
+
154
+ @Watch (' value' )
155
+ private onValueChange(value : any ) {
156
+ this .valueCopy = value
157
+ }
146
158
147
159
get computedClasses() {
148
160
return {
149
161
' material--active' : this .focus ,
150
162
' material--disabled' : this .disabled ,
151
- ' material--raised' : Boolean (this .focus || this .currentValue ) // has value
163
+ ' material--raised' : Boolean (this .focus || this .valueCopy )
152
164
}
153
165
}
154
166
155
- @Watch (' value' )
156
- private onValueChange(value : (string | number )[]) {
157
- this .currentValue = value
167
+ get filledPlaceholder() {
168
+ if (this .focus ) {
169
+ return this .placeholder
170
+ }
171
+ return ' '
158
172
}
159
173
160
174
private handleInput(event : KeyboardEvent ) {
@@ -165,24 +179,19 @@ export default class extends Vue {
165
179
this .$parent .$emit (' el.form.change' , [value ])
166
180
}
167
181
}
168
- this .$emit (' change' , value )
169
182
}
170
183
171
184
private handleFocus(event : FocusEvent ) {
172
185
this .focus = true
173
186
this .$emit (' focus' , event )
174
- if (this .placeholder && this .placeholder !== ' ' ) {
175
- this .fillPlaceHolder = this .placeholder
176
- }
177
187
}
178
188
179
189
private handleBlur(event : FocusEvent ) {
180
190
this .focus = false
181
191
this .$emit (' blur' , event )
182
- this .fillPlaceHolder = null
183
192
if (this .$parent .$options .name === ' ElFormItem' ) {
184
193
if (this .validateEvent ) {
185
- this .$parent .$emit (' el.form.blur' , [this .currentValue ])
194
+ this .$parent .$emit (' el.form.blur' , [this .valueCopy ])
186
195
}
187
196
}
188
197
}
@@ -192,16 +201,14 @@ export default class extends Vue {
192
201
<style lang="scss" scoped>
193
202
// Fonts:
194
203
$font-size-base : 16px ;
195
- $font-size-small : 18 px ;
204
+ $font-size-small : 14 px ;
196
205
$font-size-smallest : 12px ;
197
206
$font-weight-normal : normal ;
198
207
$font-weight-bold : bold ;
199
- $apixel : 1px ;
200
208
201
209
// Utils
202
- $spacer : 12 px ;
210
+ $spacer : 10 px ;
203
211
$transition : 0.2s ease all ;
204
- $index : 0px ;
205
212
$index-has-icon : 30px ;
206
213
207
214
// Theme:
@@ -232,7 +239,7 @@ $color-black: black;
232
239
233
240
// Component:
234
241
.material-input__component {
235
- margin-top : 36 px ;
242
+ margin-top : 45 px ;
236
243
position : relative ;
237
244
238
245
* {
@@ -264,11 +271,10 @@ $color-black: black;
264
271
265
272
.material-input {
266
273
font-size : $font-size-base ;
267
- padding : $spacer $spacer $spacer - $apixel * 10 $spacer / 2 ;
274
+ padding : $spacer $spacer $spacer $spacer / 2 ;
268
275
display : block ;
269
276
width : 100% ;
270
277
border : none ;
271
- line-height : 1 ;
272
278
border-radius : 0 ;
273
279
274
280
& :focus {
@@ -279,13 +285,13 @@ $color-black: black;
279
285
}
280
286
281
287
.material-label {
288
+ font-size : $font-size-small ;
282
289
font-weight : $font-weight-normal ;
283
290
position : absolute ;
284
291
pointer-events : none ;
285
- left : $index ;
292
+ left : 0 ;
286
293
top : 0 ;
287
294
transition : $transition ;
288
- font-size : $font-size-small ;
289
295
}
290
296
291
297
.material-input-bar {
@@ -327,6 +333,22 @@ $color-black: black;
327
333
}
328
334
}
329
335
}
336
+
337
+ // Errors:
338
+ .material-errors {
339
+ position : relative ;
340
+ overflow : hidden ;
341
+
342
+ .material-error {
343
+ font-size : $font-size-smallest ;
344
+ line-height : $font-size-smallest + 2px ;
345
+ overflow : hidden ;
346
+ margin-top : 0 ;
347
+ padding-top : $spacer / 2 ;
348
+ padding-right : $spacer / 2 ;
349
+ padding-left : 0 ;
350
+ }
351
+ }
330
352
}
331
353
332
354
.material-input__component {
@@ -335,7 +357,6 @@ $color-black: black;
335
357
.material-input {
336
358
background : none ;
337
359
color : $color-black ;
338
- text-indent : $index ;
339
360
border-bottom : 1px solid $color-grey-light ;
340
361
}
341
362
@@ -356,19 +377,5 @@ $color-black: black;
356
377
color : $color-blue ;
357
378
}
358
379
}
359
-
360
- // Errors:
361
- & .material--has-errors {
362
- & .material--active .material-label {
363
- color : $color-red ;
364
- }
365
-
366
- .material-input-bar {
367
- & :before ,
368
- & :after {
369
- background : transparent ;
370
- }
371
- }
372
- }
373
380
}
374
381
</style >
0 commit comments