You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The `chars` property accepts a pipe `|` delimited string of characters to use as the keyboard buttons. You can include special function characters with the `{text:action}` syntax, where `text` is the text that will be rendered in the button and `action` is the action within the keyboard component to be called when that button is pressed. The actions are:
19
+
The `chars` property accepts a pipe `|` delimited string of characters to use as the keyboard buttons. You can include special function characters with the `{text:action}` syntax, where `text` is the text that will be rendered in the button and `action` is the action within the keyboard component to be called when that button is pressed. The inbuilt actions are:
14
20
15
21
*`backspace` - Remove one character from the end of the current value.
16
22
*`space` - Insert one whitespace character.
17
23
*`clear` - Clear the entire input value.
18
24
19
-
> If the `action` does not match any of these inbuilt actions, an event will be dispatched by the keyboard component instead, using the action name. The keyboard component will be provided to the listener as the first argument.
25
+
If the `action` does not match any of these inbuilt actions, an event will be dispatched by the keyboard component instead, using the action name as the event name. The keyboard component will be provided to the listener as the first argument.
26
+
27
+
> 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.
28
+
29
+
## Interacting:
30
+
31
+
In regards to styling and interacting with the component, there are several routes:
32
+
33
+
* Buttons rendered with the `{text:action}` syntax will include a class name `action-x` where `x` is the name of the action e.g. `action-clear`.
34
+
* General buttons will include a class name `char-x` where `x` is the text content e.g. `char-a`, `char-b`.
35
+
* A `mutate` event is dispatched by the component whenever the `value` changes. The keyboard component will be provided to the listener as the first argument.
36
+
* You can use `:value.sync="x"` to sync the keyboard value with a value in the parent Vue instance.
37
+
38
+
## Example:
39
+
40
+
Here is an example application containing a `keyboard` component:
41
+
42
+
JavaScript:
43
+
44
+
```
45
+
var app = new Vue({
46
+
el: 'body',
47
+
data: {
48
+
input: ''
49
+
},
50
+
events: {
51
+
mutate: function(keyboard) {
52
+
// Limit to 16 chars.
53
+
keyboard.value = keyboard.value.slice(0, 16);
54
+
},
55
+
custom: function(keyboard) {
56
+
console.log('Custom button pressed. The current value is ' + keyboard.value);
Buttons rendered with this syntax will include a class name `action-<x>` where `<x>` is the name of the action e.g. `action-clear`.
68
+
This keeps the `input` value in the main application in sync with the value of the keyboard, limits that value to 16 characters and triggers the 'custom' function in the main application when the "custom" button in the keyboard is clicked.
0 commit comments