-
Notifications
You must be signed in to change notification settings - Fork 795
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(runtime): support "capture" style events (#4968)
* fix(runtime): handle capture style events * add some more comments for context * tests are good to have * forgot a test for removing event listeners * PR feedback
- Loading branch information
1 parent
f113b05
commit 2c8cfac
Showing
6 changed files
with
117 additions
and
5 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
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,21 @@ | ||
import { Component, h, State } from '@stencil/core'; | ||
|
||
@Component({ | ||
tag: 'event-listener-capture', | ||
}) | ||
export class EventListenerCapture { | ||
@State() counter = 0; | ||
|
||
render() { | ||
return ( | ||
<div> | ||
<p>Click the text below to trigger a capture style event</p> | ||
<div> | ||
<p id="incrementer" onClickCapture={() => this.counter++}> | ||
Clicked: <span id="counter">{this.counter}</span> time(s) | ||
</p> | ||
</div> | ||
</div> | ||
); | ||
} | ||
} |
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,6 @@ | ||
<!doctype html> | ||
<meta charset="utf8" /> | ||
<script src="./build/testapp.esm.js" type="module"></script> | ||
<script src="./build/testapp.js" nomodule></script> | ||
|
||
<event-listener-capture></event-listener-capture> |
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,31 @@ | ||
import { setupDomTests, waitForChanges } from '../util'; | ||
|
||
describe('event-listener-capture', function () { | ||
const { setupDom, tearDownDom } = setupDomTests(document); | ||
|
||
let app: HTMLElement | undefined; | ||
let host: HTMLElement | undefined; | ||
|
||
beforeEach(async () => { | ||
app = await setupDom('/event-listener-capture/index.html'); | ||
host = app.querySelector('event-listener-capture'); | ||
}); | ||
|
||
afterEach(tearDownDom); | ||
|
||
it('should render', () => { | ||
expect(host).toBeDefined(); | ||
}); | ||
|
||
it('should increment counter on click', async () => { | ||
const counter = host.querySelector('#counter'); | ||
expect(counter.textContent).toBe('0'); | ||
|
||
const p = host.querySelector('#incrementer') as HTMLParagraphElement; | ||
expect(p).toBeDefined(); | ||
p.click(); | ||
await waitForChanges(); | ||
|
||
expect(counter.textContent).toBe('1'); | ||
}); | ||
}); |