Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/twbs/bootstrap.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/js
diff options
context:
space:
mode:
authorjakubhonisek <36561997+jakubhonisek@users.noreply.github.com>2018-06-25 16:29:34 +0300
committerJohann-S <johann.servoire@gmail.com>2018-06-25 16:29:34 +0300
commit49e094619b171568fcdf59cf2dbf0e8b790e8e54 (patch)
tree0f71764cf0b30b3bafa99fe34ec31b93b4f6887e /js
parentbca4ceacc79b78e5ddb32715065aec245a636892 (diff)
feat(dropdown): add original click event
Diffstat (limited to 'js')
-rw-r--r--js/src/dropdown.js4
-rw-r--r--js/tests/unit/dropdown.js68
2 files changed, 72 insertions, 0 deletions
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 = '<div class="tabs">' +
+ '<div class="dropdown">' +
+ '<a href="#" class="dropdown-toggle" data-toggle="dropdown">Dropdown</a>' +
+ '<div class="dropdown-menu">' +
+ '<a class="dropdown-item" href="#">Secondary link</a>' +
+ '<a class="dropdown-item" href="#">Something else here</a>' +
+ '<div class="divider"/>' +
+ '<a class="dropdown-item" href="#">Another link</a>' +
+ '</div>' +
+ '</div>' +
+ '</div>'
+ var $dropdown = $(dropdownHTML)
+ .appendTo('#qunit-fixture')
+ .find('[data-toggle="dropdown"]')
+ .bootstrapDropdown()
+
+ $dropdown.parent('.dropdown')
+ .on('hide.bs.dropdown', function (e) {
+ assert.ok(e.clickEvent)
+ })
+ .on('hidden.bs.dropdown', function (e) {
+ assert.ok(e.clickEvent)
+ })
+ .on('shown.bs.dropdown', function () {
+ assert.ok(true, 'shown was fired')
+ $(document.body).trigger('click')
+ })
+
+ $dropdown.trigger('click')
+ })
+
+ QUnit.test('should fire hide and hidden event without a clickEvent if event type is not click', function (assert) {
+ assert.expect(3)
+ var dropdownHTML = '<div class="tabs">' +
+ '<div class="dropdown">' +
+ '<a href="#" class="dropdown-toggle" data-toggle="dropdown">Dropdown</a>' +
+ '<div class="dropdown-menu">' +
+ '<a class="dropdown-item" href="#">Secondary link</a>' +
+ '<a class="dropdown-item" href="#">Something else here</a>' +
+ '<div class="divider"/>' +
+ '<a class="dropdown-item" href="#">Another link</a>' +
+ '</div>' +
+ '</div>' +
+ '</div>'
+ var $dropdown = $(dropdownHTML)
+ .appendTo('#qunit-fixture')
+ .find('[data-toggle="dropdown"]')
+ .bootstrapDropdown()
+
+ $dropdown.parent('.dropdown')
+ .on('hide.bs.dropdown', function (e) {
+ assert.notOk(e.clickEvent)
+ })
+ .on('hidden.bs.dropdown', function (e) {
+ assert.notOk(e.clickEvent)
+ })
+ .on('shown.bs.dropdown', function () {
+ assert.ok(true, 'shown was fired')
+ $dropdown.trigger($.Event('keydown', {
+ which: 27
+ }))
+ })
+
+ $dropdown.trigger('click')
+ })
+
QUnit.test('should ignore keyboard events within <input>s and <textarea>s', function (assert) {
assert.expect(3)
var done = assert.async()