File tree 1 file changed +19
-4
lines changed
site/content/examples/15-composition/04-modal 1 file changed +19
-4
lines changed Original file line number Diff line number Diff line change 2
2
import { createEventDispatcher } from ' svelte' ;
3
3
4
4
const dispatch = createEventDispatcher ();
5
+
6
+ const handleClose = () => dispatch (' close' )
7
+
8
+ function handleKeydown (event ) {
9
+ if (event .key == ' Escape' ) {
10
+ handleClose ()
11
+ } else if (event .key == ' Tab' ) {
12
+ event .preventDefault ()
13
+ }
14
+ }
15
+
16
+ let closeButton
17
+ onMount (() => {
18
+ closeButton .focus ()
19
+ })
20
+
5
21
</script >
6
22
7
23
<style >
16
32
17
33
.modal {
18
34
position : absolute ;
19
- left : 50% ;
20
- top : 50% ;
35
+ left : 50% ; top : 50% ;
21
36
width : calc (100vw - 4em );
22
37
max-width : 32em ;
23
38
max-height : calc (100vh - 4em );
33
48
}
34
49
</style >
35
50
36
- <div class ='modal-background' on :click =' {() => dispatch ( " close " ) }' ></div >
51
+ <div class ='modal-background' on :click =' {handleClose }' ></div >
37
52
38
53
<div class =' modal' >
39
54
<slot name =' header' ></slot >
40
55
<hr >
41
56
<slot ></slot >
42
57
<hr >
43
58
44
- <button on :click =' {() => dispatch (" close" )}' >close modal</button >
59
+ <button on :click =' {() => dispatch (" close" )}' bind:this ={ closeButton } >close modal</button >
45
60
</div >
You can’t perform that action at this time.
0 commit comments