Skip to content

Commit 3eeb0b4

Browse files
committed
Update documentation for Events in elemental2
1 parent 20f4d6c commit 3eeb0b4

File tree

4 files changed

+17
-13
lines changed

4 files changed

+17
-13
lines changed

docs-source/book/composition/render-function.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -363,15 +363,15 @@ Here's an example with all of these modifiers used together:
363363

364364
```java
365365
vNodeData.on("keyup", (param) -> {
366-
NativeEvent event = (NativeEvent) param;
366+
KeyboardEvent event = (KeyboardEvent) param;
367367

368368
// Abort if the element emitting the event is not
369369
// the element the event is bound to
370-
if (event.getEventTarget() != event.getCurrentEventTarget()) return;
370+
if (event.target != event.currentTarget) return;
371371
// Abort if the key that went up is not the enter
372-
// key (13) and the shift key was not held down
372+
// and the shift key was not held down
373373
// at the same time
374-
if (!event.getShiftKey() || event.getKeyCode() !== 13) return;
374+
if (!event.shiftKey || !"Enter".equals(event.code)) return;
375375
// Stop event propagation
376376
event.stopPropagation();
377377
// Prevent the default keyup handler for this element

docs-source/book/essential/components.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -590,7 +590,7 @@ is just syntactic sugar for:
590590
```html
591591
<input
592592
v-bind:value="something"
593-
v-on:input="setSomethingValue((NativeEvent) $event)">
593+
v-on:input="setSomethingValue((Event) $event)">
594594
```
595595

596596
When used with a component, this simplifies to:

docs-source/book/essential/events.md

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -101,31 +101,35 @@ Sometimes we also need to access the original DOM event in an inline statement h
101101
You can pass it into a method using the special `$event` variable:
102102

103103
```html
104-
<button v-on:click='warn("Form cannot be submitted yet.", (NativeEvent) $event)'>
104+
<button v-on:click='warn("Form cannot be submitted yet.", (Event) $event)'>
105105
Submit
106106
</button>
107107
```
108108

109109
```java
110110
// ...
111-
public void warn(String message, NativeEvent event) {
111+
public void warn(String message, Event event) {
112112
if (event != null) {
113113
event.preventDefault();
114-
message += " -> Event Type: " + event.getType();
114+
message += " -> Event Type: " + event.type;
115115
}
116116

117117
Window.alert(message);
118118
}
119119
```
120120

121-
You will notice that we cast the `$event` variable to `NativeEvent` in our template.
121+
You will notice that we cast the `$event` variable to `Event` in our template.
122122
This is to indicate the type of the `$event` variable to Vue GWT.
123123

124-
This means that if your `warn` method was actually declared like this: `void warn(NativeEvent event, String message)` it would break at compile time with an explicit error.
124+
This means that if your `warn` method was actually declared like this: `void warn(Event event, String message)` it would break at compile time with an explicit error.
125125

126-
You don't have to import the `NativeEvent` class to use it in your template.
126+
You don't have to import the `Event` class to use it in your template.
127127
It's already imported by default for convenience.
128128

129+
`Event` comes from [Elemental2](https://github.com/google/elemental2).
130+
It is the base for all DOM events.
131+
You cast it to more specific events like `MouseEvent` or `KeyboardEvent` in your Component class.
132+
129133
You'll see further that `$event` can also be used when communicating between Components.
130134
In those case you might cast it to another type, like `Todo` for example.
131135

docs-source/book/essential/forms.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,8 @@ public class TodoTextComponent extends VueComponent {
7575
@JsProperty Todo todo = new Todo("Hello World!");
7676

7777
@JsMethod
78-
public void updateMessage(NativeEvent event) {
79-
this.todo.setText(JsTools.get(event.getEventTarget(), "value"));
78+
public void updateMessage(Event event) {
79+
this.todo.setText(((HTMLInputElement) event.target).value);
8080
}
8181
}
8282
```

0 commit comments

Comments
 (0)