From 4d16787997719e8a9238695852b2f110e6288643 Mon Sep 17 00:00:00 2001 From: Josh Johnson Date: Wed, 2 Aug 2017 09:42:12 +0100 Subject: [PATCH] IE11 test --- assets/scripts/src/choices.js | 6 +++++- tests/spec/choices_spec.js | 31 +++++++++++++++++++++++++++++-- 2 files changed, 34 insertions(+), 3 deletions(-) diff --git a/assets/scripts/src/choices.js b/assets/scripts/src/choices.js index 73b4ff9..f8deb41 100644 --- a/assets/scripts/src/choices.js +++ b/assets/scripts/src/choices.js @@ -1824,6 +1824,7 @@ class Choices { _onMouseDown(e) { const target = e.target; + // If we have our mouse down on the scrollbar and are on IE11... if (target === this.choiceList && this.isIe11) { this.isScrollingOnIe = true; } @@ -2062,8 +2063,11 @@ class Choices { blurActions[this.passedElement.type](); } else { - this.input.focus(); + // On IE11, clicking the scollbar blurs our input and thus + // closes the dropdown. To stop this, we refocus our input + // if we know we are on IE *and* are scrolling. this.isScrollingOnIe = false; + this.input.focus(); } } diff --git a/tests/spec/choices_spec.js b/tests/spec/choices_spec.js index b48f60b..3dd5c31 100644 --- a/tests/spec/choices_spec.js +++ b/tests/spec/choices_spec.js @@ -383,8 +383,8 @@ describe('Choices', () => { it('should close the dropdown on double click', function() { this.choices = new Choices(this.input); - const container = this.choices.containerOuter, - openState = this.choices.config.classNames.openState; + const container = this.choices.containerOuter; + const openState = this.choices.config.classNames.openState; this.choices._onClick({ target: container, @@ -401,6 +401,33 @@ describe('Choices', () => { expect(document.activeElement === this.choices.input && container.classList.contains(openState)).toBe(false); }); + it('should set scrolling flag and not hide dropdown when scrolling on IE', function() { + this.choices = new Choices(this.input); + this.choices.isIe11 = true; + + spyOn(this.choices, 'hideDropdown'); + + const container = this.choices.containerOuter; + const choiceList = this.choices.choiceList; + + // Click to open dropdown + this.choices._onClick({ + target: container, + ctrlKey: false, + preventDefault: () => {} + }); + + // Hold mouse on scrollbar + this.choices._onMouseDown({ + target: choiceList, + ctrlKey: false, + preventDefault: () => {} + }); + + expect(this.choices.isScrollingOnIe).toBe(true); + expect(this.choices.hideDropdown).not.toHaveBeenCalled(); + }); + it('should trigger showDropdown on dropdown opening', function() { this.choices = new Choices(this.input); const container = this.choices.containerOuter;