diff --git a/src/components/mdChips/mdChips.vue b/src/components/mdChips/mdChips.vue index 9175dae..2b8c75d 100644 --- a/src/components/mdChips/mdChips.vue +++ b/src/components/mdChips/mdChips.vue @@ -18,8 +18,8 @@ :name="mdInputName" :disabled="disabled" @keydown.native.delete="deleteLastChip" - @keydown.native.enter="selectChip" - @keydown.native.186="selectChip" + @keydown.native.prevent.enter="addChip" + @keydown.native.prevent.186="addChip" tabindex="0" ref="input"> @@ -77,7 +77,7 @@ this.$refs.input.$el.focus(); }); }, - selectChip() { + addChip() { if (this.currentChip && this.selectedChips.length < this.mdMax) { const value = this.currentChip.trim(); diff --git a/src/components/mdInputContainer/common.js b/src/components/mdInputContainer/common.js index 272d819..4cf4800 100644 --- a/src/components/mdInputContainer/common.js +++ b/src/components/mdInputContainer/common.js @@ -7,9 +7,9 @@ export default { placeholder: String }, watch: { - value() { - this.setParentValue(this.$el.value); - this.onInput(); + value(value) { + this.setParentValue(value); + this.updateValues(value); }, disabled() { this.setParentDisabled(); @@ -41,18 +41,25 @@ export default { setParentPlaceholder() { this.parentContainer.hasPlaceholder = !!this.placeholder; }, + updateValues(value) { + const newValue = value || this.$el.value || this.value; + + this.setParentValue(newValue); + this.parentContainer.inputLength = newValue ? newValue.length : 0; + }, onFocus() { - this.parentContainer.isFocused = true; + if (this.parentContainer) { + this.parentContainer.isFocused = true; + } }, onBlur() { this.parentContainer.isFocused = false; this.setParentValue(); }, onInput() { - this.setParentValue(this.value); - this.parentContainer.inputLength = this.value ? this.value.length : 0; - this.$emit('change', this.value); - this.$emit('input', this.value); + this.updateValues(); + this.$emit('change', this.$el.value); + this.$emit('input', this.$el.value); } } }; diff --git a/src/components/mdInputContainer/mdInput.vue b/src/components/mdInputContainer/mdInput.vue index d6beddd..5405cfd 100644 --- a/src/components/mdInputContainer/mdInput.vue +++ b/src/components/mdInputContainer/mdInput.vue @@ -40,7 +40,7 @@ this.setParentRequired(); this.setParentPlaceholder(); this.handleMaxLength(); - this.onInput(); + this.updateValues(); }); } }; diff --git a/src/components/mdInputContainer/mdTextarea.vue b/src/components/mdInputContainer/mdTextarea.vue index c959be0..de5edc1 100644 --- a/src/components/mdInputContainer/mdTextarea.vue +++ b/src/components/mdInputContainer/mdTextarea.vue @@ -39,7 +39,7 @@ this.setParentRequired(); this.setParentPlaceholder(); this.handleMaxLength(); - this.onInput(); + this.updateValues(); if (!this.$el.getAttribute('rows')) { this.$el.setAttribute('rows', '1');