@@ -65,16 +65,40 @@ export default {
6565 watch: {
6666 show (val ) {
6767 this .open = val
68+ },
69+ open (val , oldVal ) {
70+ const backdrop = document .getElementsByClassName (' c-sidebar-backdrop' )[0 ]
71+ if (val === true ) {
72+ backdrop .className = ' c-sidebar-backdrop c-show'
73+ } else if (oldVal === true ) {
74+ backdrop .className = ' c-sidebar-backdrop d-none'
75+ }
76+ }
77+ },
78+ mounted () {
79+ const backdrop = document .createElement (' div' )
80+ if (this .open === true ) {
81+ backdrop .className = ' c-sidebar-backdrop c-show'
82+ } else {
83+ backdrop .className = ' c-sidebar-backdrop d-none'
6884 }
85+ document .body .appendChild (backdrop)
86+ backdrop .addEventListener (' click' , this .closeSidebar )
87+ },
88+ beforeDestroy () {
89+ const backdrop = document .getElementsByClassName (' c-sidebar-backdrop' )[0 ]
90+ backdrop .removeEventListener (' click' , this .closeSidebar )
91+ document .body .removeChild (backdrop)
6992 },
7093 computed: {
7194 sidebarClasses () {
95+ const haveResponsiveClass = this .breakpoint && this .open === ' responsive'
7296 return [
7397 ' c-sidebar' ,
7498 ` c-sidebar-${ this .colorScheme } ` ,
7599 {
76100 ' c-sidebar-show' : this .open === true ,
77- [` c-sidebar-${ this .breakpoint } -show` ]: this . open === ' responsive ' ,
101+ [` c-sidebar-${ this .breakpoint } -show` ]: haveResponsiveClass ,
78102 ' c-sidebar-fixed' : this .fixed ,
79103 ' c-sidebar-right' : this .aside ,
80104 ' c-sidebar-minimized' : this .minimize && ! this .unfoldable ,
@@ -93,10 +117,13 @@ export default {
93117 this .hideOnMobileClick &&
94118 this .isOnMobile ()
95119 ) {
96- this .open = ' responsive'
97- this .$emit (' update:show' , ' responsive' )
120+ this .closeSidebar ()
98121 }
99122 },
123+ closeSidebar () {
124+ this .open = ' responsive'
125+ this .$emit (' update:show' , ' responsive' )
126+ },
100127 isOnMobile () {
101128 return Boolean (getComputedStyle (this .$el ).getPropertyValue (' --is-mobile' ))
102129 }
0 commit comments