Skip to content

Commit

Permalink
handle # selector for dropdown
Browse files Browse the repository at this point in the history
  • Loading branch information
Johann-S authored and XhmikosR committed Feb 13, 2019
1 parent a43077d commit 2ccfa57
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
2 changes: 1 addition & 1 deletion js/dropdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
selector = selector && /#[A-Za-z]/.test(selector) && selector.replace(/.*(?=#[^\s]*$)/, '') // strip for ie7
}

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

return $parent && $parent.length ? $parent : $this.parent()
}
Expand Down
31 changes: 31 additions & 0 deletions js/tests/unit/dropdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -420,4 +420,35 @@ $(function () {

assert.ok($dropdown.parent('.btn-group').hasClass('open'), 'dropdown menu is open')
})

QUnit.test('should handle # in data-target', function (assert) {
assert.expect(1)
var done = assert.async()

var html = [
'<div class="dropdown">',
' <a id="dLabel" data-target="#" href="http://example.com/" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">',
' Dropdown trigger',
' </a>',
' <ul class="dropdown-menu" aria-labelledby="dLabel">',
' <li><a href="/test">One</a></li>',
' <li><a href="/test2">Two</a></li>',
' </ul>',
'</div>'
].join('')

var $dropdown = $(html)
.appendTo('#qunit-fixture')
.find('[data-toggle="dropdown"]')
.bootstrapDropdown()

$dropdown
.parent('.dropdown')
.on('shown.bs.dropdown', function () {
assert.ok($dropdown.parent('.dropdown').hasClass('open'), '"open" class added on click')
done()
})

$dropdown.trigger('click')
})
})

0 comments on commit 2ccfa57

Please sign in to comment.