File tree Expand file tree Collapse file tree 2 files changed +32
-2
lines changed
docs/src/pages/components
src/components/mdInputContainer Expand file tree Collapse file tree 2 files changed +32
-2
lines changed Original file line number Diff line number Diff line change 71
71
<md-table-cell>Sets the type. Default <code>text</code></md-table-cell>
72
72
</md-table-row>
73
73
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
+
74
80
<md-table-row>
75
81
<md-table-cell>disabled</md-table-cell>
76
82
<md-table-cell><code>Boolean</code></md-table-cell>
115
121
<md-table-cell>A required model object to bind the value.</md-table-cell>
116
122
</md-table-row>
117
123
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
+
118
130
<md-table-row>
119
131
<md-table-cell>disabled</md-table-cell>
120
132
<md-table-cell><code>Boolean</code></md-table-cell>
Original file line number Diff line number Diff line change 1
1
export default {
2
2
props: {
3
3
value: [String, Number],
4
+ debounce: {
5
+ type: Number,
6
+ default: 3E2
7
+ },
4
8
disabled: Boolean,
5
9
required: Boolean,
6
10
maxlength: [Number, String],
11
+ name: String,
7
12
placeholder: String
8
13
},
14
+ data() {
15
+ return {
16
+ timeout: 0
17
+ };
18
+ },
9
19
watch: {
10
20
value(value) {
11
21
this.setParentValue(value);
@@ -29,6 +39,15 @@ export default {
29
39
this.parentContainer.enableCounter = this.maxlength > 0;
30
40
this.parentContainer.counterLength = this.maxlength;
31
41
},
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
+ },
32
51
setParentValue(value) {
33
52
this.parentContainer.setValue(value || this.$el.value);
34
53
},
@@ -58,8 +77,7 @@ export default {
58
77
},
59
78
onInput() {
60
79
this.updateValues();
61
- this.$emit('change', this.$el.value);
62
- this.$emit('input', this.$el.value);
80
+ this.lazyEventEmitter();
63
81
}
64
82
}
65
83
};
You can’t perform that action at this time.
0 commit comments