-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
support custom events on <:Window> - fixes #1268
- Loading branch information
1 parent
8717ff8
commit 6ef808c
Showing
4 changed files
with
74 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
export default { | ||
html: `<p>escaped: false</p>`, | ||
|
||
test(assert, component, target, window) { | ||
const event = new window.KeyboardEvent('keydown', { | ||
which: 27 | ||
}); | ||
|
||
window.dispatchEvent(event); | ||
|
||
assert.htmlEqual(target.innerHTML, ` | ||
<p>escaped: true</p> | ||
`); | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<:Window on:esc="set({ escaped: true })" /> | ||
|
||
<p>escaped: {{escaped}}</p> | ||
|
||
<script> | ||
export default { | ||
data() { | ||
return { escaped: false }; | ||
}, | ||
|
||
events: { | ||
esc(node, callback) { | ||
function onKeyDown(event) { | ||
if (event.which === 27) callback(event); | ||
} | ||
node.addEventListener('keydown', onKeyDown); | ||
return { | ||
destroy() { | ||
node.removeEventListener('keydown', onKeyDown); | ||
} | ||
}; | ||
} | ||
} | ||
}; | ||
</script> |