Skip to content

Commit 4bcb687

Browse files
Pablo Henriquemarcosmoura
authored andcommitted
Issue#544 (vuematerial#674)
* chips autocomplete * criando autocomplete * base solida * fixing issue vuematerial#544 * removing old files * reduced debounce time
1 parent 1371d6c commit 4bcb687

File tree

2 files changed

+32
-2
lines changed

2 files changed

+32
-2
lines changed

docs/src/pages/components/Input.vue

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,12 @@
7171
<md-table-cell>Sets the type. Default <code>text</code></md-table-cell>
7272
</md-table-row>
7373

74+
<md-table-row>
75+
<md-table-cell>debounce</md-table-cell>
76+
<md-table-cell><code>Number</code></md-table-cell>
77+
<md-table-cell>Debounce the <code>change</code> and <code>input</code> events emission. Default <code>300</code>ms</md-table-cell>
78+
</md-table-row>
79+
7480
<md-table-row>
7581
<md-table-cell>disabled</md-table-cell>
7682
<md-table-cell><code>Boolean</code></md-table-cell>
@@ -115,6 +121,12 @@
115121
<md-table-cell>A required model object to bind the value.</md-table-cell>
116122
</md-table-row>
117123

124+
<md-table-row>
125+
<md-table-cell>debounce</md-table-cell>
126+
<md-table-cell><code>Number</code></md-table-cell>
127+
<md-table-cell>Debounce the <code>change</code> and <code>input</code> events emission. Default <code>300</code>ms</md-table-cell>
128+
</md-table-row>
129+
118130
<md-table-row>
119131
<md-table-cell>disabled</md-table-cell>
120132
<md-table-cell><code>Boolean</code></md-table-cell>

src/components/mdInputContainer/common.js

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,21 @@
11
export default {
22
props: {
33
value: [String, Number],
4+
debounce: {
5+
type: Number,
6+
default: 3E2
7+
},
48
disabled: Boolean,
59
required: Boolean,
610
maxlength: [Number, String],
11+
name: String,
712
placeholder: String
813
},
14+
data() {
15+
return {
16+
timeout: 0
17+
};
18+
},
919
watch: {
1020
value(value) {
1121
this.setParentValue(value);
@@ -29,6 +39,15 @@ export default {
2939
this.parentContainer.enableCounter = this.maxlength > 0;
3040
this.parentContainer.counterLength = this.maxlength;
3141
},
42+
lazyEventEmitter() {
43+
if (this.timeout) {
44+
window.clearTimeout(this.timeout);
45+
}
46+
this.timeout = window.setTimeout(() => {
47+
this.$emit('change', this.$el.value);
48+
this.$emit('input', this.$el.value);
49+
}, this.debounce);
50+
},
3251
setParentValue(value) {
3352
this.parentContainer.setValue(value || this.$el.value);
3453
},
@@ -58,8 +77,7 @@ export default {
5877
},
5978
onInput() {
6079
this.updateValues();
61-
this.$emit('change', this.$el.value);
62-
this.$emit('input', this.$el.value);
80+
this.lazyEventEmitter();
6381
}
6482
}
6583
};

0 commit comments

Comments
 (0)