docsifyjs / docsifyjs/docsify

Event binding of body.ready on mobile devices causes abnormal switching of the sidebar

Đang mở
#1,697 0 bình luận 1 reaction 0 người được giao Xem trên GitHub
needs investigation
Ngôn ngữ chính
JavaScript
Star
31.5k
Fork
5.8k
Merge trung bình
9 ngày 8 giờ
Pull request đã merge (30 ngày)
2

Mô tả

## Bug Report

On mobile devices, docsify will add a click event to the body element.
When the event is not removed, clicking any area in the left sidebar will trigger its switching function.
After removing the event, the function is normal.

Its position is between 1932 -> 1938:

```
function btn(el) {
var toggle = function (_) {return body.classList.toggle('close'); };

el = getNode(el);
if (el === null || el === undefined) {
return;
}

on(el,'click', function (e) {
e.stopPropagation();
toggle();
});
// this position
isMobile &&
on(
body,
'click',
function (_) {return body.classList.contains('close') && toggle();}
);
}
```

Just like in the picture, this is when I did not remove the event:

![bug1](https://user-images.githubusercontent.com/81478335/147542347-20944890-e4ac-4c97-a110-d8910b0a67ae.gif)

When I removed the event, everything returned to normal:

![bug2](https://user-images.githubusercontent.com/81478335/147542519-0053e3e3-3d21-4068-a1e6-0936cf687780.gif)

I don't understand the meaning of this event, because after I disable it, I feel that everything is normal.

#### Steps to reproduce

On mobile devices, click button.sidebar-toggle. Click again on any area in the sidebar.

#### What is current behaviour

It will automatically close the sidebar.

#### What is the expected behaviour

Only when the button.sidebar-toggle button is clicked, can the sidebar toggle function be triggered.

#### Other relevant information

- [ ] Bug does still occur when all/other plugins are disabled?

- Your OS: ubuntu 20.04.3 LTS
- Node.js version: 10.24.1
- npm/yarn version: 6.4.12
- Browser version: any browser
- Docsify version: 4.4.3
- Docsify plugins:
```
gitalk
search
emoji
docsify-copy-code
countable
pangu
sidebar
progress
gifcontrol
pagination
```

#### Please create a reproducible sandbox

[![Edit 307qqv236](https://codesandbox.io/static/img/play-codesandbox.svg)](https://codesandbox.io/s/307qqv236)

#### Mention the docsify version in which this bug was not present (if any)

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.