From 20cfbdff79e19e77c24596cdca59c6694283e242 Mon Sep 17 00:00:00 2001 From: Rohit Sharma Date: Fri, 2 Apr 2021 00:21:55 +0530 Subject: [PATCH] Add missing things in `hide` method of dropdown (#33451) * Update `aria-expanded` attribute in `hide` method * Remove empty mouseover listeners added for iOS --- js/src/dropdown.js | 11 +++++++++-- js/tests/unit/dropdown.spec.js | 36 +++++++++++++++++++++++++++++++++- 2 files changed, 44 insertions(+), 3 deletions(-) diff --git a/js/src/dropdown.js b/js/src/dropdown.js index 605cbc64db..6b541ed150 100644 --- a/js/src/dropdown.js +++ b/js/src/dropdown.js @@ -218,12 +218,20 @@ class Dropdown extends BaseComponent { return } + // If this is a touch-enabled device we remove the extra + // empty mouseover listeners we added for iOS support + if ('ontouchstart' in document.documentElement) { + [].concat(...document.body.children) + .forEach(elem => EventHandler.off(elem, 'mouseover', null, noop())) + } + if (this._popper) { this._popper.destroy() } this._menu.classList.toggle(CLASS_NAME_SHOW) this._element.classList.toggle(CLASS_NAME_SHOW) + this._element.setAttribute('aria-expanded', 'false') Manipulator.removeDataAttribute(this._menu, 'popper') EventHandler.trigger(this._element, EVENT_HIDDEN, relatedTarget) } @@ -430,14 +438,13 @@ class Dropdown extends BaseComponent { .forEach(elem => EventHandler.off(elem, 'mouseover', null, noop())) } - toggles[i].setAttribute('aria-expanded', 'false') - if (context._popper) { context._popper.destroy() } dropdownMenu.classList.remove(CLASS_NAME_SHOW) toggles[i].classList.remove(CLASS_NAME_SHOW) + toggles[i].setAttribute('aria-expanded', 'false') Manipulator.removeDataAttribute(dropdownMenu, 'popper') EventHandler.trigger(toggles[i], EVENT_HIDDEN, relatedTarget) } diff --git a/js/tests/unit/dropdown.spec.js b/js/tests/unit/dropdown.spec.js index 03532256a3..b8969be7c7 100644 --- a/js/tests/unit/dropdown.spec.js +++ b/js/tests/unit/dropdown.spec.js @@ -743,7 +743,7 @@ describe('Dropdown', () => { it('should hide a dropdown', done => { fixtureEl.innerHTML = [ '