Skip to content

Commit aebaf1a

Browse files
author
Marty Wallace
committed
Maximum length can be specified as a prop.
1 parent c054d25 commit aebaf1a

File tree

6 files changed

+23
-6
lines changed

6 files changed

+23
-6
lines changed

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,15 @@ If the `action` does not match any of these inbuilt actions, an event will be di
2626

2727
> Note: You can simply use `{action}` which will create a button with no text content. This is useful for things like `space` which you may just want to render as a wide empty button.
2828
29+
## Props.
30+
31+
The possible component properties are:
32+
33+
* `chars` - The character list (explained above).
34+
* `maxlength` - The maximum length of `value`.
35+
36+
> Note: Because `maxlength` is a `Number` you must provide it with the vye dynamic syntax e.g. `<keyboard :maxlength="10">` not `<keyboard maxlength="10">` (the latter will be interpreted as a `String`).
37+
2938
## Interacting:
3039

3140
In regards to styling and interacting with the component, there are several routes:

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "vue-keyboard",
3-
"version": "1.2.0",
3+
"version": "1.3.0",
44
"homepage": "https://github.com/MartyWallace/vue-keyboard",
55
"main": "dist/vue-keyboard.js",
66
"license": "MIT",

demo/basic.html

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<title>Keyboard Demo</title>
66
</head>
77
<body>
8-
<keyboard chars="qwertyuiop{backspace:backspace}|asdfghjkl|zxcvbnm|{space:space}{custom:custom}" :value.sync="input"></keyboard>
8+
<keyboard chars="qwertyuiop{backspace:backspace}|asdfghjkl|zxcvbnm|{space:space}{custom:custom}" :maxlength="5" :value.sync="input"></keyboard>
99
<p>${ input }</p>
1010

1111
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/1.0.26/vue.min.js"></script>
@@ -25,8 +25,7 @@
2525
},
2626
events: {
2727
mutate: function(keyboard) {
28-
// Limit to 16 chars.
29-
keyboard.value = keyboard.value.slice(0, 16);
28+
//
3029
},
3130
custom: function(keyboard) {
3231
console.log('Custom button pressed. The current value is ' + keyboard.value);

dist/vue-keyboard.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "vue-keyboard",
3-
"version": "1.2.0",
3+
"version": "1.3.0",
44
"devDependencies": {
55
"gulp": "^3.9.1",
66
"gulp-uglify": "1.5.*",

src/vue-keyboard.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@
1717
value: {
1818
type: String,
1919
default: ''
20+
},
21+
maxlength: {
22+
type: Number,
23+
default: 0
2024
}
2125
},
2226

@@ -70,6 +74,11 @@
7074

7175
mutate(value) {
7276
this.value = value;
77+
78+
if (this.maxlength > 0) {
79+
this.value = this.value.slice(0, this.maxlength);
80+
}
81+
7382
this.$dispatch('mutate', this);
7483
},
7584

0 commit comments

Comments
 (0)