Skip to content

Commit

Permalink
fix(toolbar): support the use of toolbar in firefox and other browsers
Browse files Browse the repository at this point in the history
  • Loading branch information
zjgyb authored and Moyee committed Dec 29, 2020
1 parent ee3a994 commit 747771e
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion src/plugins/toolBar/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,30 @@ interface ToolBarConfig extends IPluginBaseConfig {
position?: Point | null;
}

function getEventPath(evt: MouseEvent) {
if (!evt) {
return [];
}

if (evt.composedPath) {
return evt.composedPath();
}

const path = [];
let el = evt.target as HTMLElement;

while (el) {
path.push(el);
if (el.tagName === 'HTML') {
path.push(document, window);
return path;
}

el = el.parentElement;
}
return path;
}

export default class ToolBar extends Base {
public getDefaultCfgs(): ToolBarConfig {
return {
Expand Down Expand Up @@ -113,7 +137,7 @@ export default class ToolBar extends Base {
const handleClick = this.get('handleClick');

toolBarDOM.addEventListener('click', (evt) => {
const current = evt.path.filter((p) => p.nodeName === 'LI');
const current = getEventPath(evt).filter((p) => p.nodeName === 'LI');
if (current.length === 0) {
return;
}
Expand Down

0 comments on commit 747771e

Please sign in to comment.