File tree Expand file tree Collapse file tree 1 file changed +28
-4
lines changed
Expand file tree Collapse file tree 1 file changed +28
-4
lines changed Original file line number Diff line number Diff line change 3535 }
3636
3737 .menubar : hover ,
38- .menubar : focus-within {
38+ .menubar : focus-within ,
39+ .menubar .is-open {
3940 left : 0 ;
4041 }
4142
121122 }
122123
123124 connectedCallback ( ) {
124- const bar = this . shadowRoot . querySelector ( ".menubar" )
125- const width = bar . offsetWidth
126- bar . style = `--panel-width: ${ width } px; --left-offset: calc(var(--icon-size) + 32px);`
125+ const width = this . bar . offsetWidth
126+ this . bar . style = `--panel-width: ${ width } px; --left-offset: calc(var(--icon-size) + 32px);`
127+ this . bar . addEventListener ( "touchstart" , this , { passive : false } )
128+ document . addEventListener ( "touchstart" , this , { passive : true } )
129+ }
130+
131+ handleEvent ( event ) {
132+ // click on menubar
133+ if ( event . currentTarget === this . bar ) {
134+ if ( ! this . bar . classList . contains ( "is-open" ) ) {
135+ event . preventDefault ( )
136+ this . bar . classList . add ( "is-open" )
137+ }
138+ // click outside of menubar
139+ } else if ( ! event . composedPath ( ) . includes ( this . bar ) ) {
140+ this . bar . classList . remove ( "is-open" )
141+ }
142+ }
143+
144+ disconnectedCallback ( ) {
145+ this . bar . removeEventListener ( "touchstart" , this )
146+ document . removeEventListener ( "touchstart" , this )
147+ }
148+
149+ get bar ( ) {
150+ return this . shadowRoot . querySelector ( ".menubar" )
127151 }
128152 }
129153
You can’t perform that action at this time.
0 commit comments