Skip to content

Commit

Permalink
fix: 修复pointer event导致的误触,兼容浏览器不支持pointer event的情况
Browse files Browse the repository at this point in the history
  • Loading branch information
sunsonliu committed Dec 25, 2023
1 parent dce6053 commit 08965e5
Showing 1 changed file with 27 additions and 7 deletions.
34 changes: 27 additions & 7 deletions src/toolbars/Toolbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,13 +134,33 @@ export default class Toolbar {

this.menus.level1MenusName.forEach((name) => {
const btn = this.menus.hooks[name].createBtn();
btn.addEventListener(
'pointerup',
(event) => {
this.onClick(event, name);
},
false,
);
if ('onpointerup' in window) {
// 只有先down再up的才触发click逻辑,避免误触(尤其是float menu的场景)
btn.addEventListener(
'pointerdown',
() => {
this.isPointerDown = true;
},
false,
);
btn.addEventListener(
'pointerup',
(event) => {
this.isPointerDown && this.onClick(event, name);
this.isPointerDown = false;
},
false,
);
} else {
// vscode 插件里不支持 pointer event
btn.addEventListener(
'click',
(event) => {
this.onClick(event, name);
},
false,
);
}
if (this.isHasSubMenu(name)) {
btn.classList.add('cherry-toolbar-dropdown');
}
Expand Down

0 comments on commit 08965e5

Please sign in to comment.