From ef1c7aadbc61c69e03ecc7c6e13bdccd1901cbd4 Mon Sep 17 00:00:00 2001 From: Johann-S Date: Sun, 25 Aug 2019 18:12:02 +0200 Subject: [PATCH] Backport #29298 dropdown show method should do the same as toggle --- bundlesize.config.json | 2 +- js/src/dropdown.js | 39 ++++++++++++++------------------------- js/tests/unit/dropdown.js | 37 ++++++++++++++++++++++++++++++++++++- 3 files changed, 51 insertions(+), 27 deletions(-) diff --git a/bundlesize.config.json b/bundlesize.config.json index 8c33e3abb7..6a5bfd27b9 100644 --- a/bundlesize.config.json +++ b/bundlesize.config.json @@ -26,7 +26,7 @@ }, { "path": "./dist/js/bootstrap.bundle.js", - "maxSize": "47 kB" + "maxSize": "47.50 kB" }, { "path": "./dist/js/bootstrap.bundle.min.js", diff --git a/js/src/dropdown.js b/js/src/dropdown.js index f38712e476..48125517ee 100644 --- a/js/src/dropdown.js +++ b/js/src/dropdown.js @@ -126,7 +126,6 @@ class Dropdown { return } - const parent = Dropdown._getParentFromElement(this._element) const isActive = $(this._menu).hasClass(ClassName.SHOW) Dropdown._clearMenus() @@ -135,10 +134,19 @@ class Dropdown { return } + this.show(true) + } + + show(usePopper = false) { + if (this._element.disabled || $(this._element).hasClass(ClassName.DISABLED) || $(this._menu).hasClass(ClassName.SHOW)) { + return + } + const relatedTarget = { relatedTarget: this._element } const showEvent = $.Event(Event.SHOW, relatedTarget) + const parent = Dropdown._getParentFromElement(this._element) $(parent).trigger(showEvent) @@ -147,7 +155,7 @@ class Dropdown { } // Disable totally Popper.js for Dropdown in Navbar - if (!this._inNavbar) { + if (!this._inNavbar && usePopper) { /** * Check for Popper dependency * Popper - https://popper.js.org @@ -196,29 +204,6 @@ class Dropdown { .trigger($.Event(Event.SHOWN, relatedTarget)) } - show() { - if (this._element.disabled || $(this._element).hasClass(ClassName.DISABLED) || $(this._menu).hasClass(ClassName.SHOW)) { - return - } - - const relatedTarget = { - relatedTarget: this._element - } - const showEvent = $.Event(Event.SHOW, relatedTarget) - const parent = Dropdown._getParentFromElement(this._element) - - $(parent).trigger(showEvent) - - if (showEvent.isDefaultPrevented()) { - return - } - - $(this._menu).toggleClass(ClassName.SHOW) - $(parent) - .toggleClass(ClassName.SHOW) - .trigger($.Event(Event.SHOWN, relatedTarget)) - } - hide() { if (this._element.disabled || $(this._element).hasClass(ClassName.DISABLED) || !$(this._menu).hasClass(ClassName.SHOW)) { return @@ -236,6 +221,10 @@ class Dropdown { return } + if (this._popper) { + this._popper.destroy() + } + $(this._menu).toggleClass(ClassName.SHOW) $(parent) .toggleClass(ClassName.SHOW) diff --git a/js/tests/unit/dropdown.js b/js/tests/unit/dropdown.js index 07702e2f62..bfe5aebf58 100644 --- a/js/tests/unit/dropdown.js +++ b/js/tests/unit/dropdown.js @@ -1272,7 +1272,7 @@ $(function () { }) QUnit.test('should show dropdown', function (assert) { - assert.expect(2) + assert.expect(3) var dropdownHTML = '