diff --git a/modules/behavior/hover.js b/modules/behavior/hover.js index 2f13f1072..36f4355f9 100644 --- a/modules/behavior/hover.js +++ b/modules/behavior/hover.js @@ -123,13 +123,16 @@ export function behaviorHover() { }; - hover.off = function() { - _selection.selectAll('.hover') + hover.off = function(selection) { + selection.selectAll('.hover') .classed('hover', false); - _selection.selectAll('.hover-suppressed') + selection.selectAll('.hover-suppressed') .classed('hover-suppressed', false); + selection + .classed('hover-disabled', false); - _selection + + selection .on('mouseover.hover', null) .on('mouseout.hover', null) .on('mousedown.hover', null); diff --git a/test/spec/behavior/hover.js b/test/spec/behavior/hover.js index 72c36cb82..35552bd82 100644 --- a/test/spec/behavior/hover.js +++ b/test/spec/behavior/hover.js @@ -16,7 +16,12 @@ describe('iD.behaviorHover', function() { it('removes the .hover class from all elements', function () { container.append('span').attr('class', 'hover'); container.call(iD.behaviorHover(context).off); - expect(container.select('span')).not.to.be.classed('hover'); + expect(container.select('span').classed('hover')).to.be.false; + }); + it('removes the .hover-disabled class from the surface element', function () { + container.attr('class', 'hover-disabled'); + container.call(iD.behaviorHover(context).off); + expect(container.classed('hover-disabled')).to.be.false; }); }); @@ -63,34 +68,37 @@ describe('iD.behaviorHover', function() { describe('alt keydown', function () { it('replaces the .hover class with .hover-suppressed', function () { container.append('span').attr('class', 'hover'); - container.call(iD.behaviorHover(context).altDisables(true)); - happen.keydown(window, {keyCode: 18}); + happen.keydown(window, {keyCode: 18}); expect(container.selectAll('.hover').nodes()).to.have.length(0); expect(container.selectAll('.hover-suppressed').nodes()).to.have.length(1); + happen.keyup(window, {keyCode: 18}); }); it('adds the .hover-disabled class to the surface', function () { container.call(iD.behaviorHover(context).altDisables(true)); + happen.keydown(window, {keyCode: 18}); expect(container.classed('hover-disabled')).to.be.true; + happen.keyup(window, {keyCode: 18}); }); }); describe('alt keyup', function () { it('replaces the .hover-suppressed class with .hover', function () { container.append('span').attr('class', 'hover-suppressed'); - container.call(iD.behaviorHover(context).altDisables(true)); - happen.keyup(window, {keyCode: 18}); + happen.keydown(window, {keyCode: 18}); + happen.keyup(window, {keyCode: 18}); expect(container.selectAll('.hover').nodes()).to.have.length(1); expect(container.selectAll('.hover-suppressed').nodes()).to.have.length(0); }); it('removes the .hover-disabled class from the surface', function () { container.call(iD.behaviorHover(context).altDisables(true)); + happen.keydown(window, {keyCode: 18}); happen.keyup(window, {keyCode: 18}); expect(container.classed('hover-disabled')).to.be.false;