|
26 | 26 | </div>
|
27 | 27 |
|
28 | 28 | <div>
|
29 |
| - <Button on:click$capture={addEventCapture} on:click={addEventBubble}> |
| 29 | + Try clicking and using the Enter key to activate this next button. (The click |
| 30 | + event's target is an element below the button while the key event's target is |
| 31 | + the button.) |
| 32 | +</div> |
| 33 | + |
| 34 | +<div> |
| 35 | + <Button on:click$capture={addEventPhase} on:click={addEventPhase}> |
30 | 36 | <Label>Capture and Bubble Phase Listeners</Label>
|
31 | 37 | </Button>
|
32 | 38 | </div>
|
|
40 | 46 | </div>
|
41 | 47 |
|
42 | 48 | <div>
|
43 |
| - <Button |
| 49 | + <A |
44 | 50 | href="http://example.com"
|
45 | 51 | on:click$preventDefault={() =>
|
46 | 52 | console.log("You tried to go, but didn't make it.")}
|
47 | 53 | >
|
48 |
| - <Label>A Link Button, with Default Prevented</Label> |
49 |
| - </Button> |
| 54 | + A Link, with Default Prevented |
| 55 | + </A> |
50 | 56 | </div>
|
51 | 57 |
|
52 | 58 | <script>
|
53 | 59 | import Button, { Label } from '@smui/button';
|
| 60 | + import A from '@smui/common/A.svelte'; |
54 | 61 |
|
55 | 62 | let eventOutput;
|
56 | 63 | let eventPhaseOutput;
|
|
65 | 72 | });
|
66 | 73 | }
|
67 | 74 |
|
68 |
| - function addEventCapture(event) { |
69 |
| - eventPhases.push([event, 'capture']); |
70 |
| - eventPhases = eventPhases; |
71 |
| - requestAnimationFrame(() => { |
72 |
| - eventPhaseOutput.scrollTop = eventPhaseOutput.scrollHeight; |
73 |
| - }); |
74 |
| - } |
75 |
| -
|
76 |
| - function addEventBubble(event) { |
77 |
| - eventPhases.push([event, 'bubble']); |
| 75 | + function addEventPhase(event) { |
| 76 | + const phases = ['none', 'capturing', 'at-target', 'bubbling']; |
| 77 | + eventPhases.push([event, phases[event.eventPhase]]); |
78 | 78 | eventPhases = eventPhases;
|
79 | 79 | requestAnimationFrame(() => {
|
80 | 80 | eventPhaseOutput.scrollTop = eventPhaseOutput.scrollHeight;
|
|
0 commit comments