@@ -66,15 +66,18 @@ export default {
66
66
show (val ) {
67
67
this .open = val
68
68
},
69
- open (val ) {
70
- val === true ? this .createBackdrop () : this .removeBackdrop ()
71
- }
72
- },
73
- mounted () {
74
- if (this .open === true ) {
75
- this .createBackdrop ()
69
+ open: {
70
+ immediate: true ,
71
+ handler (val ) {
72
+ val === true ? this .createBackdrop () : this .removeBackdrop ()
73
+ }
76
74
}
77
75
},
76
+ // mounted () {
77
+ // if (this.open === true) {
78
+ // this.createBackdrop()
79
+ // }
80
+ // },
78
81
beforeDestroy () {
79
82
this .removeBackdrop ()
80
83
},
@@ -110,16 +113,29 @@ export default {
110
113
isOnMobile () {
111
114
return Boolean (getComputedStyle (this .$el ).getPropertyValue (' --is-mobile' ))
112
115
},
116
+ sidebarCloseListener (e ) {
117
+ if (
118
+ document .getElementById (this ._uid + ' backdrop' ) &&
119
+ ! this .$el .contains (e .target )
120
+ ) {
121
+ this .closeSidebar ()
122
+ }
123
+ },
113
124
createBackdrop () {
114
125
const backdrop = document .createElement (' div' )
126
+ if (this .overlaid ) {
127
+ document .addEventListener (' click' , this .sidebarCloseListener , true )
128
+ } else {
129
+ backdrop .addEventListener (' click' , this .closeSidebar )
130
+ }
115
131
backdrop .className = ' c-sidebar-backdrop c-show'
116
132
backdrop .id = this ._uid + ' backdrop'
117
133
document .body .appendChild (backdrop)
118
- backdrop .addEventListener (' click' , this .closeSidebar )
119
134
},
120
135
removeBackdrop () {
121
136
const backdrop = document .getElementById (this ._uid + ' backdrop' )
122
137
if (backdrop) {
138
+ document .removeEventListener (' click' , this .sidebarCloseListener )
123
139
backdrop .removeEventListener (' click' , this .closeSidebar )
124
140
document .body .removeChild (backdrop)
125
141
}
0 commit comments