@@ -66,15 +66,18 @@ export default {
6666 show (val ) {
6767 this .open = val
6868 },
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+ }
7674 }
7775 },
76+ // mounted () {
77+ // if (this.open === true) {
78+ // this.createBackdrop()
79+ // }
80+ // },
7881 beforeDestroy () {
7982 this .removeBackdrop ()
8083 },
@@ -110,16 +113,29 @@ export default {
110113 isOnMobile () {
111114 return Boolean (getComputedStyle (this .$el ).getPropertyValue (' --is-mobile' ))
112115 },
116+ sidebarCloseListener (e ) {
117+ if (
118+ document .getElementById (this ._uid + ' backdrop' ) &&
119+ ! this .$el .contains (e .target )
120+ ) {
121+ this .closeSidebar ()
122+ }
123+ },
113124 createBackdrop () {
114125 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+ }
115131 backdrop .className = ' c-sidebar-backdrop c-show'
116132 backdrop .id = this ._uid + ' backdrop'
117133 document .body .appendChild (backdrop)
118- backdrop .addEventListener (' click' , this .closeSidebar )
119134 },
120135 removeBackdrop () {
121136 const backdrop = document .getElementById (this ._uid + ' backdrop' )
122137 if (backdrop) {
138+ document .removeEventListener (' click' , this .sidebarCloseListener )
123139 backdrop .removeEventListener (' click' , this .closeSidebar )
124140 document .body .removeChild (backdrop)
125141 }
0 commit comments