Skip to content

Commit a16b7df

Browse files
fix(jqLite): deregister special mouseenter / mouseleave events correctly
Closes angular#12795 Closes angular#12799
1 parent 9b6f6e6 commit a16b7df

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

src/jqLite.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -850,13 +850,13 @@ forEach({
850850
var types = type.indexOf(' ') >= 0 ? type.split(' ') : [type];
851851
var i = types.length;
852852

853-
var addHandler = function(type, specialHandlerWrapper) {
853+
var addHandler = function(type, specialHandlerWrapper, noEventListener) {
854854
var eventFns = events[type];
855855

856856
if (!eventFns) {
857857
eventFns = events[type] = [];
858858
eventFns.specialHandlerWrapper = specialHandlerWrapper;
859-
if (type !== '$destroy') {
859+
if (type !== '$destroy' && !noEventListener) {
860860
addEventListenerFn(element, type, handle);
861861
}
862862
}
@@ -868,6 +868,7 @@ forEach({
868868
type = types[i];
869869
if (MOUSE_EVENT_MAP[type]) {
870870
addHandler(MOUSE_EVENT_MAP[type], specialMouseHandlerWrapper);
871+
addHandler(type, undefined, true);
871872
} else {
872873
addHandler(type);
873874
}

test/jqLiteSpec.js

+14
Original file line numberDiff line numberDiff line change
@@ -1469,6 +1469,20 @@ describe('jqLite', function() {
14691469
expect(onMouseleave).toHaveBeenCalledOnce();
14701470
});
14711471

1472+
it('should call a `mouseenter/leave` listener when manually triggering the event', function() {
1473+
var aElem = jqLite(a);
1474+
var onMouseenter = jasmine.createSpy('mouseenter');
1475+
var onMouseleave = jasmine.createSpy('mouseleave');
1476+
1477+
aElem.on('mouseenter', onMouseenter);
1478+
aElem.on('mouseleave', onMouseleave);
1479+
1480+
aElem.triggerHandler('mouseenter');
1481+
expect(onMouseenter).toHaveBeenCalledOnce();
1482+
1483+
aElem.triggerHandler('mouseleave');
1484+
expect(onMouseleave).toHaveBeenCalledOnce();
1485+
});
14721486

14731487

14741488
it('should deregister specific listener within the listener and call subsequent listeners', function() {

0 commit comments

Comments
 (0)