Skip to content

Commit 1a389b0

Browse files
committed
fix(MdField): improve error states and input reset
1 parent 25f5ab1 commit 1a389b0

File tree

4 files changed

+31
-6
lines changed

4 files changed

+31
-6
lines changed

src/components/MdField/MdField.vue

+20
Original file line numberDiff line numberDiff line change
@@ -450,6 +450,26 @@
450450
}
451451
452452
&.md-invalid {
453+
@keyframes md-invalid-shake {
454+
10%, 90% {
455+
transform: translate3d(-1px, 0, 0);
456+
}
457+
458+
30%, 70% {
459+
transform: translate3d(-4px, 0, 0);
460+
}
461+
462+
40%, 60% {
463+
transform: translate3d(4px, 0, 0);
464+
}
465+
}
466+
467+
&.md-has-value label:not(:focus) {
468+
animation: md-invalid-shake .4s $md-transition-default-timing both;
469+
backface-visibility: hidden;
470+
perspective: 1000px;
471+
}
472+
453473
&.md-has-textarea:not(.md-autogrow) {
454474
&:before {
455475
border-width: 2px;

src/components/MdField/MdFieldMixin.js

+7-4
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,9 @@ export default {
3131
}
3232
},
3333
watch: {
34-
value (val) {
35-
this.content = val
34+
value (value) {
35+
this.content = value
36+
this.setFieldValue()
3637
},
3738
clear (clear) {
3839
if (clear) {
@@ -57,7 +58,6 @@ export default {
5758
this.$el.value = ''
5859
this.content = ''
5960
this.setFieldValue()
60-
this.$emit('input', '')
6161
},
6262
setLabelFor () {
6363
const label = this.$el.parentNode.querySelector('label')
@@ -93,7 +93,10 @@ export default {
9393
this.MdField.focused = false
9494
},
9595
onInput () {
96-
this.setFieldValue()
96+
const newValue = this.$el ? this.$el.value : this.content
97+
98+
this.$emit('input', newValue)
99+
this.MdField.value = newValue
97100
}
98101
},
99102
created () {

src/components/MdField/MdInput/MdInput.vue

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
v-model="content"
77
@focus="onFocus"
88
@blur="onBlur"
9-
@input="onInput">
9+
@input="onInput"
10+
@change="onInput">
1011
</template>
1112

1213
<script>

src/components/MdField/MdTextarea/MdTextarea.vue

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
v-model="content"
88
@focus="onFocus"
99
@blur="onBlur"
10-
@input="onInput">
10+
@input="onInput"
11+
@change="onInput">
1112
</textarea>
1213
</template>
1314

0 commit comments

Comments
 (0)