Skip to content

Commit

Permalink
fix(properties-panel): stop propagation of DEL key events
Browse files Browse the repository at this point in the history
  • Loading branch information
philippfromme committed May 28, 2018
1 parent adee204 commit 71dc3a4
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 1 deletion.
10 changes: 10 additions & 0 deletions lib/PropertiesPanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -549,6 +549,16 @@ PropertiesPanel.prototype._bindListeners = function(container) {
domDelegate.bind(container, 'input, textarea, [contenteditable]', 'input', debounce(handleChange, DEBOUNCE_DELAY));
domDelegate.bind(container, 'input, textarea, select, [contenteditable]', 'change', handleChange);

// handle key events
domDelegate.bind(container, 'select', 'keydown', function(e) {

// DEL
if (e.keyCode === 46) {
e.stopPropagation();
e.preventDefault();
}
});

domDelegate.bind(container, '[data-action]', 'click', function onClick(event) {

// triggers on all inputs
Expand Down
15 changes: 15 additions & 0 deletions test/TestHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,20 @@ var triggerInput = function(element, value) {
element.focus();
};

var triggerKeyEvent = function(element, event, code) {
var e = document.createEvent('Events');

if (e.initEvent) {
e.initEvent(event, true, true);
}

e.keyCode = code;
e.which = code;

element.dispatchEvent(e);
};


/**
* Select a form field with the specified index in the DOM
*
Expand Down Expand Up @@ -178,6 +192,7 @@ var selectedByIndex = function(element) {
module.exports.triggerEvent = triggerEvent;
module.exports.triggerValue = triggerValue;
module.exports.triggerInput = triggerInput;
module.exports.triggerKeyEvent = triggerKeyEvent;
module.exports.triggerFormFieldSelection = triggerFormFieldSelection;
module.exports.selectedByOption = selectedByOption;
module.exports.selectedByIndex = selectedByIndex;
Expand Down
38 changes: 38 additions & 0 deletions test/spec/PropertiesPanelSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -430,4 +430,42 @@ describe('properties-panel', function() {
});


describe('listeners', function() {

function getSelect(container) {
return domQuery('select[name=select]', container);
}

var select, spy;

beforeEach(inject(function(propertiesPanel, elementRegistry, selection) {
propertiesPanel.attachTo(container);

var task2 = elementRegistry.get('Task_2');
selection.select(task2);

select = getSelect(propertiesPanel._container);

spy = sinon.spy();

document.addEventListener('keydown', spy);
}));

afterEach(function() {
document.removeEventListener('keydown', spy);
});


it('should stop propagation of DEL key events', function() {

// when
TestHelper.triggerKeyEvent(select, 'keydown', 46);

// then
expect(spy).to.not.have.been.called;
});

});


});
3 changes: 3 additions & 0 deletions test/spec/properties/PropertiesProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,9 @@ function createGroups(element, bpmnFactory) {
a: !values.a && new Error('a must be checked')
};
}
}, {
id: 'select',
html: '<select name="select"><option>foo</option><option>bar</option></select>'
}
]
}
Expand Down
6 changes: 5 additions & 1 deletion test/spec/test.bpmn
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<bpmn2:definitions xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:bpmn2="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" xmlns:custom="http://custom" id="_pHDz0KojEeOJhIBv1RySdg" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="1.2.2" xsi:schemaLocation="http://www.omg.org/spec/BPMN/20100524/MODEL BPMN20.xsd">
<bpmn2:definitions xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:bpmn2="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:custom="http://custom" id="_pHDz0KojEeOJhIBv1RySdg" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="1.14.0" xsi:schemaLocation="http://www.omg.org/spec/BPMN/20100524/MODEL BPMN20.xsd">
<bpmn2:process id="Process_1" isExecutable="false">
<bpmn2:startEvent id="StartEvent_1" name="Label" custom:foo="BAR">
<bpmn2:documentation>FOO FOO BAR BAR</bpmn2:documentation>
</bpmn2:startEvent>
<bpmn2:task id="Task_1" custom:foo="BAR" />
<bpmn2:sendTask id="Task_2" />
</bpmn2:process>
<bpmndi:BPMNDiagram id="BPMNDiagram_1">
<bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="Process_1">
Expand All @@ -17,6 +18,9 @@
<bpmndi:BPMNShape id="_BPMNShape_Task_3" bpmnElement="Task_1">
<dc:Bounds x="260" y="146" width="100" height="80" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="SendTask_0tdg6fy_di" bpmnElement="Task_2">
<dc:Bounds x="260" y="283" width="100" height="80" />
</bpmndi:BPMNShape>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</bpmn2:definitions>

0 comments on commit 71dc3a4

Please sign in to comment.