Skip to content

Commit 1c5357e

Browse files
committed
added change event on update value and fix the docs playground
1 parent b4268cc commit 1c5357e

File tree

5 files changed

+57
-11
lines changed

5 files changed

+57
-11
lines changed

.prettierrc.js

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
module.exports = {
2+
trailingComma: 'es5',
3+
proseWrap: 'always',
4+
tabWidth: 2,
5+
printWidth: 100,
6+
semi: true,
7+
singleQuote: true,
8+
};

.vscode/settings.json

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"editor.formatOnSave": true,
3+
"editor.fontWeight": "normal"
4+
}

docs/.vuepress/components/BaseNumber.vue

+11-6
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,14 @@ export default {
4343
type: String,
4444
default: () => options.decimal,
4545
},
46+
min: {
47+
type: [Number,Boolean],
48+
default: () => options.min,
49+
},
50+
max: {
51+
type: [Number,Boolean],
52+
default: () => options.max,
53+
},
4654
separator: {
4755
type: String,
4856
default: () => options.separator,
@@ -59,7 +67,7 @@ export default {
5967
directives: {
6068
number: directive,
6169
},
62-
emits: ["update:modelValue"],
70+
emits: ["update:model-value"],
6371
data() {
6472
return {
6573
maskedValue: this.modelValue,
@@ -72,7 +80,7 @@ export default {
7280
this.unmaskedValue = target.unmaskedValue;
7381
},
7482
change() {
75-
this.$emit("update:modelValue", this.emittedValue);
83+
this.$emit("update:model-value", this.emittedValue);
7684
},
7785
},
7886
computed: {
@@ -98,10 +106,7 @@ export default {
98106
config: {
99107
immediate: true,
100108
handler(val) {
101-
this.$emit(
102-
"update:modelValue",
103-
this.emittedValue || this.unmaskedValue || this.maskedValue
104-
);
109+
this.$emit("update:model-value", this.emittedValue || this.modelValue);
105110
},
106111
},
107112
},

docs/.vuepress/components/PlayGround.vue

+21-4
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44
<div class="grid">
55
<div class="font-medium mb-2">Component</div>
66
<BaseNumber
7-
:modelValue="price"
8-
@update:model-value="(val) => (price = val)"
7+
v-model="price"
98
v-bind="config"
109
/>
1110
<div class="mt-2">
@@ -15,6 +14,7 @@
1514
<div class="grid">
1615
<div class="font-medium mb-2">Directive</div>
1716
<BaseInput
17+
v-if="updated"
1818
:modelValue="priceDirective"
1919
@update:model-value="(val) => (priceDirective = val)"
2020
v-number="config"
@@ -70,11 +70,11 @@
7070
</div>
7171
<div class="mb-5 min-w-0 grid">
7272
<div class="mb-2 font-medium">Minimum value</div>
73-
<BaseInput type="text" v-model="config.min" />
73+
<BaseInput type="text" v-model.number="config.min" />
7474
</div>
7575
<div class="mb-5 min-w-0 grid">
7676
<div class="mb-2 font-medium">Maximum value</div>
77-
<BaseInput type="text" v-model="config.max" />
77+
<BaseInput type="text" v-model.number="config.max" />
7878
</div>
7979
</div>
8080
<div class="mb-8">
@@ -86,9 +86,12 @@
8686
</template>
8787

8888
<script>
89+
let emitTimer;
90+
8991
export default {
9092
data() {
9193
return {
94+
updated: true,
9295
exportDialogVisible: false,
9396
price: 154.52,
9497
priceDirective: 154.52,
@@ -104,5 +107,19 @@ export default {
104107
},
105108
};
106109
},
110+
watch: {
111+
config: {
112+
deep: true,
113+
handler (val) {
114+
clearTimeout(emitTimer);
115+
emitTimer = setTimeout(() => {
116+
this.updated = false
117+
this.$nextTick(() => {
118+
this.updated = true;
119+
});
120+
}, 1000);
121+
}
122+
}
123+
}
107124
};
108125
</script>

src/core.js

+13-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,18 @@ export function FacadeInputEvent() {
1414
})
1515
}
1616

17+
/**
18+
* Creates a CustomEvent('change') with detail = { facade: true }
19+
* used as a way to identify our own change event
20+
*/
21+
export function FacadeChangeEvent() {
22+
return new CustomEvent('change', {
23+
bubbles: true,
24+
cancelable: true,
25+
detail: { facade: true }
26+
})
27+
}
28+
1729
/**
1830
* ensure that the element we're attaching to is an input element
1931
* if not try to find an input element in this elements childrens
@@ -84,7 +96,7 @@ export function updateValue(el, vnode, { emit = true, force = false, clean = fal
8496

8597
// this part needs to be outside the above IF statement for vuetify in firefox
8698
// drawback is that we endup with two's input events in firefox
87-
return emit && el.dispatchEvent(FacadeInputEvent())
99+
return emit && el.dispatchEvent(FacadeInputEvent()) && el.dispatchEvent(FacadeChangeEvent())
88100
}
89101
}
90102

0 commit comments

Comments
 (0)