Skip to content

Commit 2ccfa57

Browse files
Johann-SXhmikosR
authored andcommitted
handle # selector for dropdown
1 parent a43077d commit 2ccfa57

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

js/dropdown.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
selector = selector && /#[A-Za-z]/.test(selector) && selector.replace(/.*(?=#[^\s]*$)/, '') // strip for ie7
3030
}
3131

32-
var $parent = selector && $(document).find(selector)
32+
var $parent = selector !== '#' ? $(document).find(selector) : null
3333

3434
return $parent && $parent.length ? $parent : $this.parent()
3535
}

js/tests/unit/dropdown.js

+31
Original file line numberDiff line numberDiff line change
@@ -420,4 +420,35 @@ $(function () {
420420

421421
assert.ok($dropdown.parent('.btn-group').hasClass('open'), 'dropdown menu is open')
422422
})
423+
424+
QUnit.test('should handle # in data-target', function (assert) {
425+
assert.expect(1)
426+
var done = assert.async()
427+
428+
var html = [
429+
'<div class="dropdown">',
430+
' <a id="dLabel" data-target="#" href="http://example.com/" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">',
431+
' Dropdown trigger',
432+
' </a>',
433+
' <ul class="dropdown-menu" aria-labelledby="dLabel">',
434+
' <li><a href="/test">One</a></li>',
435+
' <li><a href="/test2">Two</a></li>',
436+
' </ul>',
437+
'</div>'
438+
].join('')
439+
440+
var $dropdown = $(html)
441+
.appendTo('#qunit-fixture')
442+
.find('[data-toggle="dropdown"]')
443+
.bootstrapDropdown()
444+
445+
$dropdown
446+
.parent('.dropdown')
447+
.on('shown.bs.dropdown', function () {
448+
assert.ok($dropdown.parent('.dropdown').hasClass('open'), '"open" class added on click')
449+
done()
450+
})
451+
452+
$dropdown.trigger('click')
453+
})
423454
})

0 commit comments

Comments
 (0)