Skip to content

Commit 83e3f35

Browse files
authored
Merge branch 'master' into fix-keypress-event-to-keydown
2 parents 29ab934 + c750ddb commit 83e3f35

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ https://github.com/icebob/vue-touch-keyboard/archive/master.zip
5656
layout: "normal",
5757
input: null,
5858
options: {
59-
useKbEvents: false
59+
useKbEvents: false,
60+
preventClickEvent: false
6061
}
6162
},
6263
@@ -97,6 +98,7 @@ Property | Default | Accepted values | Description
9798
Option | Default | Accepted values | Description
9899
----------- | -------- | --------------- | -----------
99100
`useKbEvents` | `false` | `boolean` | If true, the component will generate a `keydown` event and trigger it. If it returns with `false`, it won't insert the new character.
101+
`preventClickEvent` | `false` | `boolean` | If true, the component will `preventDefault` the click event.
100102

101103
## Built-in layouts
102104
* `normal` - Normal full layout. Similar as real keyboard layouts

src/keyboard.vue

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// input(type="text", v-model="keyboardText", v-if="!input")
44
.keyboard
55
.line(v-for="(line, index) in keySet", :key="index")
6-
span(v-for="(key, index) in line", :key="index", :class="getClassesOfKey(key)", v-text="getCaptionOfKey(key)", @click="clickKey(key)", @mousedown="mousedown", :style="getKeyStyle(key)")
6+
span(v-for="(key, index) in line", :key="index", :class="getClassesOfKey(key)", v-text="getCaptionOfKey(key)", @click="e => clickKey(e, key)", @mousedown="mousedown", :style="getKeyStyle(key)")
77

88

99
</template>
@@ -176,15 +176,17 @@
176176
return text;
177177
},
178178
179-
mousedown() {
179+
mousedown(e) {
180180
if (!this.input) return;
181+
if (this.options.preventClickEvent) e.preventDefault();
181182
182183
this.inputScrollLeft = this.input.scrollLeft;
183184
//console.log("mousedown: ", this.input.scrollLeft, this.input.scrollWidth, this.input.clientWidth);
184185
},
185186
186-
clickKey(key) {
187+
clickKey(e, key) {
187188
if (!this.input) return;
189+
if (this.options.preventClickEvent) e.preventDefault();
188190
189191
let caret = this.getCaret();
190192
let text = this.input.value;

0 commit comments

Comments
 (0)