mirror of
https://gitee.com/antv/g6.git
synced 2024-11-30 18:58:34 +08:00
fix: Cannot read property getModel of null problem on contextmenu when the target is not an item. closes: #1815.
This commit is contained in:
parent
d620c58a0c
commit
c0bbb07824
@ -6,7 +6,8 @@
|
|||||||
- fix: combo edge with uncorrect end points;
|
- fix: combo edge with uncorrect end points;
|
||||||
- fix: combo polyline edge with wrong path;
|
- fix: combo polyline edge with wrong path;
|
||||||
- fix: getViewCenter with padding problem;
|
- fix: getViewCenter with padding problem;
|
||||||
- feat: allow user to configure the initial positions for empty combos.
|
- feat: allow user to configure the initial positions for empty combos;
|
||||||
|
- fix: Cannot read property 'getModel' of null problem on contextmenu when the target is not an item.
|
||||||
|
|
||||||
#### 3.5.10
|
#### 3.5.10
|
||||||
- fix: fitView and fitCenter with animate in the initial state;
|
- fix: fitView and fitCenter with animate in the initial state;
|
||||||
|
@ -46,7 +46,7 @@ export default class Menu extends Base {
|
|||||||
<li>菜单项2</li>
|
<li>菜单项2</li>
|
||||||
</ul>
|
</ul>
|
||||||
`
|
`
|
||||||
},
|
},
|
||||||
// 菜单隐藏事件
|
// 菜单隐藏事件
|
||||||
onHide() {
|
onHide() {
|
||||||
return true;
|
return true;
|
||||||
@ -71,7 +71,7 @@ export default class Menu extends Base {
|
|||||||
|
|
||||||
protected onMenuShow(e: IG6GraphEvent) {
|
protected onMenuShow(e: IG6GraphEvent) {
|
||||||
const self = this;
|
const self = this;
|
||||||
|
|
||||||
const container = this.get('menu')
|
const container = this.get('menu')
|
||||||
const getContent = this.get('getContent')
|
const getContent = this.get('getContent')
|
||||||
let menu = getContent(e)
|
let menu = getContent(e)
|
||||||
@ -94,26 +94,26 @@ export default class Menu extends Base {
|
|||||||
|
|
||||||
const bbox = container.getBoundingClientRect();
|
const bbox = container.getBoundingClientRect();
|
||||||
|
|
||||||
let x = e.item.getModel().x;
|
let x = e.item.getModel().x || e.x;
|
||||||
let y = e.item.getModel().y;
|
let y = e.item.getModel().y || e.y;
|
||||||
|
|
||||||
// 若菜单超出画布范围,反向
|
// 若菜单超出画布范围,反向
|
||||||
if (x + bbox.width > width) {
|
if (x + bbox.width > width) {
|
||||||
x = width - bbox.width;
|
x = width - bbox.width;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (y + bbox.height > height) {
|
if (y + bbox.height > height) {
|
||||||
y = height - bbox.height;
|
y = height - bbox.height;
|
||||||
}
|
}
|
||||||
|
|
||||||
const point = graph.getClientByPoint(x, y)
|
const point = graph.getClientByPoint(x, y)
|
||||||
e.canvasX = point.x;
|
e.canvasX = point.x;
|
||||||
e.canvasY = point.y;
|
e.canvasY = point.y;
|
||||||
|
|
||||||
modifyCSS(container, {
|
modifyCSS(container, {
|
||||||
top: `${point.y}px`,
|
top: `${point.y}px`,
|
||||||
left: `${point.x}px`,
|
left: `${point.x}px`,
|
||||||
visibility: 'visible'
|
visibility: 'visible'
|
||||||
});
|
});
|
||||||
|
|
||||||
const handler = (evt) => {
|
const handler = (evt) => {
|
||||||
@ -133,7 +133,7 @@ export default class Menu extends Base {
|
|||||||
|
|
||||||
// 隐藏菜单后需要移除事件监听
|
// 隐藏菜单后需要移除事件监听
|
||||||
document.body.removeEventListener('click', this.get('handler'));
|
document.body.removeEventListener('click', this.get('handler'));
|
||||||
|
|
||||||
const handleMenuClick = this.get('handleMenuClick')
|
const handleMenuClick = this.get('handleMenuClick')
|
||||||
if (handleMenuClick) {
|
if (handleMenuClick) {
|
||||||
container.removeEventListener('click', handleMenuClick)
|
container.removeEventListener('click', handleMenuClick)
|
||||||
@ -148,7 +148,7 @@ export default class Menu extends Base {
|
|||||||
if (handleMenuClick) {
|
if (handleMenuClick) {
|
||||||
menu.removeEventListener('click', handleMenuClick)
|
menu.removeEventListener('click', handleMenuClick)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (menu) {
|
if (menu) {
|
||||||
document.body.removeChild(menu);
|
document.body.removeChild(menu);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user