Skip to content

Commit

Permalink
fix(MdField): improve error states and input reset
Browse files Browse the repository at this point in the history
  • Loading branch information
marcosmoura committed Oct 13, 2017
1 parent 25f5ab1 commit 1a389b0
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 6 deletions.
20 changes: 20 additions & 0 deletions src/components/MdField/MdField.vue
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,26 @@
}
&.md-invalid {
@keyframes md-invalid-shake {
10%, 90% {
transform: translate3d(-1px, 0, 0);
}
30%, 70% {
transform: translate3d(-4px, 0, 0);
}
40%, 60% {
transform: translate3d(4px, 0, 0);
}
}
&.md-has-value label:not(:focus) {
animation: md-invalid-shake .4s $md-transition-default-timing both;
backface-visibility: hidden;
perspective: 1000px;
}
&.md-has-textarea:not(.md-autogrow) {
&:before {
border-width: 2px;
Expand Down
11 changes: 7 additions & 4 deletions src/components/MdField/MdFieldMixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@ export default {
}
},
watch: {
value (val) {
this.content = val
value (value) {
this.content = value
this.setFieldValue()
},
clear (clear) {
if (clear) {
Expand All @@ -57,7 +58,6 @@ export default {
this.$el.value = ''
this.content = ''
this.setFieldValue()
this.$emit('input', '')
},
setLabelFor () {
const label = this.$el.parentNode.querySelector('label')
Expand Down Expand Up @@ -93,7 +93,10 @@ export default {
this.MdField.focused = false
},
onInput () {
this.setFieldValue()
const newValue = this.$el ? this.$el.value : this.content

this.$emit('input', newValue)
this.MdField.value = newValue
}
},
created () {
Expand Down
3 changes: 2 additions & 1 deletion src/components/MdField/MdInput/MdInput.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
v-model="content"
@focus="onFocus"
@blur="onBlur"
@input="onInput">
@input="onInput"
@change="onInput">
</template>

<script>
Expand Down
3 changes: 2 additions & 1 deletion src/components/MdField/MdTextarea/MdTextarea.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
v-model="content"
@focus="onFocus"
@blur="onBlur"
@input="onInput">
@input="onInput"
@change="onInput">
</textarea>
</template>

Expand Down

0 comments on commit 1a389b0

Please sign in to comment.