From 49e094619b171568fcdf59cf2dbf0e8b790e8e54 Mon Sep 17 00:00:00 2001 From: jakubhonisek <36561997+jakubhonisek@users.noreply.github.com> Date: Mon, 25 Jun 2018 15:29:34 +0200 Subject: [PATCH] feat(dropdown): add original click event --- docs/4.1/components/dropdowns.md | 1 + js/src/dropdown.js | 4 ++ js/tests/unit/dropdown.js | 68 ++++++++++++++++++++++++++++++++ 3 files changed, 73 insertions(+) diff --git a/docs/4.1/components/dropdowns.md b/docs/4.1/components/dropdowns.md index 7b2be36fe4..9adfa499bc 100644 --- a/docs/4.1/components/dropdowns.md +++ b/docs/4.1/components/dropdowns.md @@ -845,6 +845,7 @@ Note when `boundary` is set to any value other than `'scrollParent'`, the style ### Events All dropdown events are fired at the `.dropdown-menu`'s parent element and have a `relatedTarget` property, whose value is the toggling anchor element. +`hide.bs.dropdown` and `hidden.bs.dropdown` events have a `clickEvent` property (only when the original event type is `click`) that contains an Event Object for the click event. | Event | Description | | --- | --- | diff --git a/js/src/dropdown.js b/js/src/dropdown.js index 5494fdb64a..c7dcdec7c9 100644 --- a/js/src/dropdown.js +++ b/js/src/dropdown.js @@ -344,6 +344,10 @@ const Dropdown = (($) => { relatedTarget: toggles[i] } + if (event && event.type === 'click') { + relatedTarget.clickEvent = event + } + if (!context) { continue } diff --git a/js/tests/unit/dropdown.js b/js/tests/unit/dropdown.js index f767124d59..81d35ff3a7 100644 --- a/js/tests/unit/dropdown.js +++ b/js/tests/unit/dropdown.js @@ -499,6 +499,74 @@ $(function () { $dropdown.trigger('click') }) + QUnit.test('should fire hide and hidden event with a clickEvent', function (assert) { + assert.expect(3) + var dropdownHTML = '