Skip to content

Commit

Permalink
fix(context-pad): clear hover timeout on close
Browse files Browse the repository at this point in the history
  • Loading branch information
philippfromme committed Nov 7, 2023
1 parent cae4980 commit 1d3820b
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 2 deletions.
2 changes: 2 additions & 0 deletions lib/features/context-pad/ContextPad.js
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,8 @@ ContextPad.prototype.close = function() {
return;
}

clearTimeout(this._timeout);

this._overlays.remove(this._overlayId);

this._overlayId = null;
Expand Down
13 changes: 11 additions & 2 deletions test/spec/features/context-pad/ContextPadProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,17 @@ import imageC from './resources/c.png';
import { every } from 'min-dash';


export default function ContextPadProvider(contextPad) {
export default function ContextPadProvider(contextPad, elementRegistry) {
this._contextPad = contextPad;
this._elementRegistry = elementRegistry;

contextPad.registerProvider(this);
}

ContextPadProvider.$inject = [ 'contextPad' ];
ContextPadProvider.$inject = [ 'contextPad', 'elementRegistry' ];

ContextPadProvider.prototype.getContextPadEntries = function(element) {
var self = this;

if (element.type === 'A') {
return {
Expand Down Expand Up @@ -47,6 +51,11 @@ ContextPadProvider.prototype.getContextPadEntries = function(element) {
'action.hover': {
className: 'hover',
action: {
click: function(e) {
self._contextPad.open(self._elementRegistry.get('s2'));

return 'action.click';
},
hover: function(e) {
e.__handled = true;

Expand Down
41 changes: 41 additions & 0 deletions test/spec/features/context-pad/ContextPadSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -838,6 +838,47 @@ describe('features/context-pad', function() {
}));


it('should not handle hover event', inject(function(canvas, contextPad) {

// given
var shape = canvas.addShape({
id: 's1',
width: 100, height: 100,
x: 10, y: 10,
type: 'hover'
});

canvas.addShape({
id: 's2',
width: 100, height: 100,
x: 10, y: 10,
type: 'hover'
});

contextPad.open(shape);

var pad = contextPad.getPad(shape),
html = pad.html,
target = domQuery('[data-action="action.hover"]', html);

var event = globalEvent(target, { x: 0, y: 0 });

// when
contextPad.trigger('mouseover', event);

expect(event.__handled).not.to.exist;

clock.tick(250);

contextPad.trigger('click', globalEvent(target, { x: 0, y: 0 }));

clock.tick(500);

// then
expect(event.__handled).not.to.exist;
}));


it('should prevent unhandled events', inject(function(canvas, contextPad) {

// given
Expand Down

0 comments on commit 1d3820b

Please sign in to comment.