Skip to content

Commit 9b7e5f5

Browse files
committed
feat(event): Collapse the sidebar when click outside element in the small screen
1 parent 432bcfb commit 9b7e5f5

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

src/core/event/sidebar.js

+11-6
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,22 @@ const title = dom.$.title
77
* Toggle button
88
*/
99
export function btn (el) {
10-
const toggle = () => dom.body.classList.toggle('close')
10+
const toggle = _ => dom.body.classList.toggle('close')
1111

1212
el = dom.getNode(el)
13-
dom.on(el, 'click', toggle)
13+
dom.on(el, 'click', e => {
14+
e.stopPropagation()
15+
toggle()
16+
})
1417

1518
const sidebar = dom.getNode('.sidebar')
1619

17-
dom.on(sidebar, 'click', () => {
18-
isMobile && toggle()
19-
setTimeout(() => getAndActive(sidebar, true, true), 0)
20-
})
20+
isMobile && dom.on(dom.body, 'click', _ =>
21+
dom.body.classList.contains('close') && toggle()
22+
)
23+
dom.on(sidebar, 'click', _ =>
24+
setTimeout((_ => getAndActive(sidebar, true, true), 0))
25+
)
2126
}
2227

2328
export function sticky () {

0 commit comments

Comments
 (0)